You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix logs still appearing even when LogLevel is set to none bug (#3318)
## Why make this change?
- Closes issue #3262
The logger for the Startup class is not initialized properly, since this
logger is special due to the nature of the Startup class it needs to be
continuously updated as DAB initializes. This causes two problems:
- Some logs appear even when LogLevel is set to some value that would
impede those logs to appear.
- Some logs don't appear at all, even when LogLevel is set to a value
that should allow them to be logged.
- Closes issue #3256 & #3255
The CLI logger still outputs some logs even when the LogLevel is set to
`none`. It is expected that if the LogLevel set is `none` or some other
level that shouldn't output the `information` level, the logs will not
appear.
## What is this change?
Important Note: These changes currently only allow us to change the
LogLevel from the CLI with the `default` namespace in the config file.
An task was created to solve this issue:
#3451
In order to solve issue #3262:
- We removed the LogBuffer from the services inside of `Startup.cs`,
this is necessary since we wanted each class to have its own LogBuffer
so that we are able to tell from which logger the logs are being
outputted.
- Then, we also correctly initialized the `Startup` logger by changing
the method that it was using to initialize the logger, it now uses
`CreateLoggerFactoryForHostedAndNonHostedScenario` which checks if there
are any LogLevel namespaces from the config file that can be applicable
for the specific logger. It is important to note that there are multiple
places where the logs are flushed in order to cover for the cases in
which an exception is found and causes DAB to end abruptly, and when we
there is an IsLateConfigured scenario.
- We also changed the logger for the LogBuffer in all the missing places
where it creates logs before the logger is able to properly initialize
to add those logs to the LogBuffer and only flush them after the loggers
are initialized.
In order to solve issue #3256 & #3255:
- We changed the CLI so that we add all the logs go to a single global
LogBuffer that is created inside the `StartOptions.cs` until it is able
to deserialize the RuntimeConfig and find which level to set the
`LogLevel` in order to flush all the logs.
- This is something that we only want to happen when we use the `dab
start` command, which is why we only make this change in the
`StartOptions.cs` file, on the function `TryStartEngineWithOptions`
inside of `ConfigGenerator.cs`, and a few functions from `Utils.cs` and
`ConfigMerger.cs` that are used inside the `TryStartEngine` function.
## How was this tested?
- [ ] Integration Tests
- [x] Unit Tests
## Sample Request(s)
- dab start --LogLevel none
- dab start --LogLevel error
---------
Co-authored-by: Aniruddh Munde <anmunde@microsoft.com>
Assert.IsTrue(ConfigMerger.TryMergeConfigsIfAvailable(fileSystem,loader,newStringLogger(),outstring?mergedConfig),"Failed to merge config files");
260
+
Assert.IsTrue(ConfigMerger.TryMergeConfigsIfAvailable(fileSystem,loader,newStringLogger(),logBuffer,outstring?mergedConfig),"Failed to merge config files");
Copy file name to clipboardExpand all lines: src/Cli/Commands/StartOptions.cs
+11-1Lines changed: 11 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,8 @@ public class StartOptions : Options
19
19
{
20
20
privateconststringLOGLEVEL_HELPTEXT="Specifies logging level as provided value. For possible values, see: https://go.microsoft.com/fwlink/?linkid=2263106";
_logger.LogError("Invalid connection-string provided in the config.");
2713
+
options.CliBuffer.BufferLog(LogLevel.Error,"Invalid connection-string provided in the config.");
2714
2714
returnfalse;
2715
2715
}
2716
2716
@@ -2729,9 +2729,8 @@ public static bool TryStartEngineWithOptions(StartOptions options, FileSystemRun
2729
2729
{
2730
2730
if(options.LogLevelis<LogLevel.Trace or >LogLevel.None)
2731
2731
{
2732
-
_logger.LogError(
2733
-
"LogLevel's valid range is 0 to 6, your value: {logLevel}, see: https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.loglevel",
2734
-
options.LogLevel);
2732
+
options.CliBuffer.BufferLog(LogLevel.Error,
2733
+
$"LogLevel's valid range is 0 to 6, your value: {options.LogLevel}, see: https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.loglevel");
2735
2734
returnfalse;
2736
2735
}
2737
2736
@@ -2740,8 +2739,28 @@ public static bool TryStartEngineWithOptions(StartOptions options, FileSystemRun
2740
2739
// This allows MCP logging/setLevel to work when no CLI override is present.
0 commit comments