Skip to content

Fix Setting Azure.DataApiBuilder to none bug#3318

Open
RubenCerna2079 wants to merge 12 commits intomainfrom
dev/rubencerna/fix-loglevel-bugs
Open

Fix Setting Azure.DataApiBuilder to none bug#3318
RubenCerna2079 wants to merge 12 commits intomainfrom
dev/rubencerna/fix-loglevel-bugs

Conversation

@RubenCerna2079
Copy link
Copy Markdown
Contributor

@RubenCerna2079 RubenCerna2079 commented Mar 25, 2026

Why make this change?

What is this change?

  • Startup.cs: Correctly initialized the logger for startup by creating its own LogLevelInitializer and added the logs that are generated before the startup logger is initialized correctly to a log buffer, so they can be flushed out once the logger is completely initialized.
  • Service/Program.cs: Fixed grammar mistake in isLogLevelOverriddenByCli
  • DynamicLogLevelProvider.cs: Added summary comments
  • LogBuffer.cs: Changed name from StartupLogBuffer.cs as it is now also used in the CLI. Also added the Exceptions parameter in order to allow for more types of logs to be saved in the buffer.
  • FileSystemRuntimeConfigLoader.cs: Moved LogBuffer so that it always starts on its own, and the parameter doesn't need to be passed to it.
  • StartOptions.cs: Add its own LogBuffer and add logs to buffer.
  • ConfigGenerator.cs: Set LogBuffer and add all the logs that are generated into the buffer and flush them once the LogLevel is set.
  • CustomLoggerProvider.cs: Allow the minimum LogLevel to be changed.
  • ConfigMerger.cs: Add logs to buffer.

How was this tested?

  • Integration Tests
  • Unit Tests

Sample Request(s)

  • dab start --LogLevel none
  • dab start --LogLevel error

@RubenCerna2079 RubenCerna2079 linked an issue Mar 25, 2026 that may be closed by this pull request
@RubenCerna2079
Copy link
Copy Markdown
Contributor Author

/azp run

@RubenCerna2079 RubenCerna2079 marked this pull request as ready for review March 26, 2026 23:36
Copilot AI review requested due to automatic review settings March 26, 2026 23:36
@RubenCerna2079
Copy link
Copy Markdown
Contributor Author

/azp run

@RubenCerna2079
Copy link
Copy Markdown
Contributor Author

/azp run

@RubenCerna2079 RubenCerna2079 added this to the March 2026 milestone Mar 26, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses incorrect/early logging behavior in both the Service startup path and the CLI by introducing a shared buffering approach until the effective minimum log level is known, and by making the CLI logger provider honor a configurable minimum log level (including None).

Changes:

  • Introduces a general LogBuffer (renamed from StartupLogBuffer) and wires it into Service startup and CLI flows to capture early logs and flush them after log level resolution.
  • Updates Service startup to re-initialize the Startup logger with a dedicated LogLevelInitializer, and expands log filter registration.
  • Updates CLI logging infrastructure to allow the minimum log level to be configured and routes multiple CLI logs through the buffer-or-logger helper.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/Service/Telemetry/DynamicLogLevelProvider.cs Adds optional logger filter support and new XML doc blocks.
src/Service/Startup.cs Buffers early Startup logs and reworks telemetry/logger initialization sequencing.
src/Service/Program.cs Fixes spelling in isLogLevelOverriddenByCli naming.
src/Config/LogBuffer.cs Renames/expands log buffer to include optional exceptions.
src/Config/FileSystemRuntimeConfigLoader.cs Makes loader own its log buffer (no longer injected) and buffers until logger is set.
src/Cli/Utils.cs Routes some config-selection logs through the buffer-or-logger helper; allows CLI logger factory to accept a minimum level.
src/Cli/CustomLoggerProvider.cs Adds configurable minimum log level and enforces it (including disabling output for None).
src/Cli/ConfigMerger.cs Routes merge logs through the buffer-or-logger helper.
src/Cli/ConfigGenerator.cs Adds CLI buffer support, flushes buffered logs after log level is resolved, and adds helper for buffer-or-logger.
src/Cli/Commands/StartOptions.cs Introduces a CLI buffer and attempts to route start logs through buffering.
Comments suppressed due to low confidence (1)

src/Config/LogBuffer.cs:16

  • LogBuffer only stores a fully-rendered string message, which forces callers to use string interpolation and loses structured logging (message templates + args). That can break log analytics queries/telemetry correlation that rely on named properties. Consider storing the message template plus arguments (and optionally EventId) and using the ILogger.Log(logLevel, exception, template, args) overload when flushing.

lock (_flushLock)
{
while (_logBuffer.TryDequeue(out (LogLevel LogLevel, string Message) entry))
while (_logBuffer.TryDequeue(out (LogLevel LogLevel, string Message, Exception? Exception) entry))
Copy link
Copy Markdown
Contributor

@aaronburtle aaronburtle Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function allows for null targetLogger, but doesn't seem to check if the targetLogger is null before dequeue. Doesn't that mean if the targetLogger is null, we just lose all the errors in the buffer? Should we skip flushing until targetLogger is not null, or maybe find another work around?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it that way on purpose, but I will change it so that it throws a warning or an error that there is no logger and the logs cannot be flushed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the target logger is null and we are going to flush the buffer, should we instead print those logs to console? is there a case where we prefer those logs to be lost entirely?


//Flush all logs that were buffered before setting the LogLevel.
// Important: All logs set before this point should use _logBuffer.
_logBuffer.FlushToLogger(_logger);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is an exception raised before we flush the logger here, then the buffer never flushes and any errors are skipped from being logged. similarly if TryGetConfig returns false I dont think we flush the logger for the late configured path.

I think we should use a try/finally block here to ensure that we always flush the logger.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, after this is fixed (or if you make it into a followup issue), there will be another issue which is we still have some usage of the console to account for this, for example, errors during deserialization. We will need to adjust console usage to rely on the logger buffer once we know it will flush properly even during a halted startup.


public static void SetBufferForCliConfigGenerator(LogBuffer cliBuffer)
{
_cliBuffer = cliBuffer;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This static method sets a static logbuffer globally, but StartOptions created a new log buffer each time it is invoked. This is probably going to work fine for now, but it creates a landmine where if we ever have parallel test execution or we invoke multiple StartOption instances for some reason we will have a race condition and logs from one test could flush to another, creating strange behavior.

@@ -48,13 +49,13 @@ public StartOptions(bool verbose, LogLevel? logLevel, bool isHttpsRedirectionDis

public int Handler(ILogger logger, FileSystemRuntimeConfigLoader loader, IFileSystem fileSystem)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like all the logging is now handled with SendLogToBufferOrLogger now, is the logger param here still used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Todo

4 participants