-
Notifications
You must be signed in to change notification settings - Fork 330
Fix logs still appearing even when LogLevel is set to none bug
#3318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8d26aec
9d21e65
3bb69d5
d0cb93a
d87ef7b
100914f
2e6d2bf
741d2d4
260a9c0
c460cab
c487a5d
29818d9
e1ee165
5832465
0e64146
ddd6508
85d8381
0ca53e7
7101d4a
4c981c9
4a331eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2555,7 +2555,7 @@ | |
| /// </summary> | ||
| public static bool TryStartEngineWithOptions(StartOptions options, FileSystemRuntimeConfigLoader loader, IFileSystem fileSystem) | ||
| { | ||
| if (!TryGetConfigForRuntimeEngine(options.Config, loader, fileSystem, out string runtimeConfigFile)) | ||
| if (!TryGetConfigForRuntimeEngine(options.Config, loader, fileSystem, out string runtimeConfigFile, options.CliBuffer)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
@@ -2564,17 +2564,17 @@ | |
| // Replaces all the environment variables while deserializing when starting DAB. | ||
| if (!loader.TryLoadKnownConfig(out RuntimeConfig? deserializedRuntimeConfig, replaceEnvVar: true)) | ||
| { | ||
| _logger.LogError("Failed to parse the config file: {runtimeConfigFile}.", runtimeConfigFile); | ||
| options.CliBuffer.BufferLog(LogLevel.Error, $"Failed to parse the config file: {runtimeConfigFile}."); | ||
| return false; | ||
| } | ||
| else | ||
| { | ||
| _logger.LogInformation("Loaded config file: {runtimeConfigFile}", runtimeConfigFile); | ||
| options.CliBuffer.BufferLog(LogLevel.Information, $"Loaded config file: {runtimeConfigFile}"); | ||
| } | ||
|
|
||
| if (string.IsNullOrWhiteSpace(deserializedRuntimeConfig.DataSource.ConnectionString)) | ||
| { | ||
| _logger.LogError("Invalid connection-string provided in the config."); | ||
| options.CliBuffer.BufferLog(LogLevel.Error, "Invalid connection-string provided in the config."); | ||
| return false; | ||
| } | ||
|
|
||
|
|
@@ -2589,23 +2589,36 @@ | |
| { | ||
| if (options.LogLevel is < LogLevel.Trace or > LogLevel.None) | ||
| { | ||
| _logger.LogError( | ||
| "LogLevel's valid range is 0 to 6, your value: {logLevel}, see: https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.loglevel", | ||
| options.LogLevel); | ||
| options.CliBuffer.BufferLog(LogLevel.Error, | ||
| $"LogLevel's valid range is 0 to 6, your value: {options.LogLevel}, see: https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.loglevel"); | ||
| return false; | ||
| } | ||
|
|
||
| minimumLogLevel = (LogLevel)options.LogLevel; | ||
| _logger.LogInformation("Setting minimum LogLevel: {minimumLogLevel}.", minimumLogLevel); | ||
| options.CliBuffer.BufferLog(LogLevel.Information, $"Setting minimum LogLevel: {minimumLogLevel}."); | ||
| } | ||
| else | ||
| { | ||
| minimumLogLevel = deserializedRuntimeConfig.GetConfiguredLogLevel(); | ||
| HostMode hostModeType = deserializedRuntimeConfig.IsDevelopmentMode() ? HostMode.Development : HostMode.Production; | ||
|
|
||
| _logger.LogInformation($"Setting default minimum LogLevel: {minimumLogLevel} for {hostModeType} mode.", minimumLogLevel, hostModeType); | ||
| options.CliBuffer.BufferLog(LogLevel.Information, $"Setting default minimum LogLevel: {minimumLogLevel} for {hostModeType} mode."); | ||
| } | ||
|
|
||
| Utils.LoggerFactoryForCli = Utils.GetLoggerFactoryForCli(minimumLogLevel); | ||
|
|
||
| // Update logger for StartOptions | ||
| ILogger<Program> programLogger = Utils.LoggerFactoryForCli.CreateLogger<Program>(); | ||
| options.CliBuffer.FlushToLogger(programLogger); | ||
|
|
||
| // Update logger for Utils | ||
| ILogger<Utils> utilsLogger = Utils.LoggerFactoryForCli.CreateLogger<Utils>(); | ||
| Utils.SetCliUtilsLogger(utilsLogger); | ||
|
|
||
| // Update logger for ConfigGenerator | ||
| ILogger<ConfigGenerator> configGeneratorLogger = Utils.LoggerFactoryForCli.CreateLogger<ConfigGenerator>(); | ||
| SetLoggerForCliConfigGenerator(configGeneratorLogger); | ||
|
|
||
| args.Add("--LogLevel"); | ||
| args.Add(minimumLogLevel.ToString()); | ||
|
|
||
|
|
@@ -2696,16 +2709,32 @@ | |
| string? configToBeUsed, | ||
| FileSystemRuntimeConfigLoader loader, | ||
| IFileSystem fileSystem, | ||
| out string runtimeConfigFile) | ||
| out string runtimeConfigFile, | ||
| LogBuffer? logBuffer = null) | ||
| { | ||
| if (string.IsNullOrEmpty(configToBeUsed) && ConfigMerger.TryMergeConfigsIfAvailable(fileSystem, loader, _logger, out configToBeUsed)) | ||
| if (string.IsNullOrEmpty(configToBeUsed) && ConfigMerger.TryMergeConfigsIfAvailable(fileSystem, loader, _logger, logBuffer, out configToBeUsed)) | ||
| { | ||
| _logger.LogInformation("Using merged config file based on environment: {configToBeUsed}.", configToBeUsed); | ||
| if (logBuffer is null) | ||
| { | ||
| _logger.LogInformation("Using merged config file based on environment,: {configToBeUsed}.", {configToBeUsed}); | ||
|
Check failure on line 2719 in src/Cli/ConfigGenerator.cs
|
||
| } | ||
| else | ||
| { | ||
| logBuffer.BufferLog(LogLevel.Information, $"Merged config file based on environment is available: {configToBeUsed}."); | ||
| } | ||
| } | ||
|
|
||
| if (!TryGetConfigFileBasedOnCliPrecedence(loader, configToBeUsed, out runtimeConfigFile)) | ||
| if (!TryGetConfigFileBasedOnCliPrecedence(loader, configToBeUsed, out runtimeConfigFile, logBuffer)) | ||
| { | ||
| _logger.LogError("Config not provided and default config file doesn't exist."); | ||
| if (logBuffer is null) | ||
| { | ||
| _logger.LogError("Config not provided and default config file doesn't exist."); | ||
| } | ||
| else | ||
| { | ||
| logBuffer.BufferLog(LogLevel.Error, "Config not provided and default config file doesn't exist."); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
|
|
@@ -3622,5 +3651,26 @@ | |
|
|
||
| return true; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Helper method that sends the log to the buffer if the buffer has being set up. | ||
RubenCerna2079 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// Else, it will send the log to the logger. | ||
| /// </summary> | ||
| /// <param name="logger">Logger instance to which the logs will be sent if the buffer is not set up.</param> | ||
| /// <param name="cliBuffer">Optional log buffer to which the logs will be sent if set up.</param> | ||
| /// <param name="logLevel">LogLevel of the log.</param> | ||
| /// <param name="message">Message that will be printed in the log.</param> | ||
RubenCerna2079 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// <param name="ex">Exception associated with the log.</param> | ||
| public static void SendLogToBufferOrLogger(LogBuffer? cliBuffer, LogLevel logLevel, string message, Exception? ex = null) | ||
| { | ||
| if (cliBuffer is not null) | ||
| { | ||
| cliBuffer.BufferLog(logLevel, message, ex); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this helper method? The caller is anyway passing both the logger and the logbuffer to this function. Its not like the caller is unaware, if the CliBuffer is null or not, if its a static member that you initialize then it is always going to be valid. You can simply call the BufferLog in the caller itself.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are some places where we use it where it is not always necessary as the loggers have already been initialized properly, so we pass the LogBuffer as a null so that it directly logs the message. I will also add this to the description to make it easier to understand.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In those other callers, where the logger directly logs - you can simply use logger.Log. There you dont need the buffer. This wrapper is unnecessary, we can simply either flush to buffer or do logger.log in the respective callers. |
||
| } | ||
| else | ||
| { | ||
| _logger.Log(logLevel, ex, message); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.