| | | 1 | | using Microsoft.Extensions.DependencyInjection; |
| | | 2 | | using Microsoft.Extensions.Logging; |
| | | 3 | | |
| | | 4 | | namespace Orchestrator; |
| | | 5 | | |
| | | 6 | | public static class LoggingConfiguration |
| | | 7 | | { |
| | 1 | 8 | | private static readonly HashSet<string> QuietExperimentRunCommands = new(StringComparer.OrdinalIgnoreCase) |
| | 1 | 9 | | { |
| | 1 | 10 | | "run-slice", |
| | 1 | 11 | | "run-repeated-match", |
| | 1 | 12 | | "run-repeated-match-slice", |
| | 1 | 13 | | "run-community-to-date" |
| | 1 | 14 | | }; |
| | | 15 | | |
| | | 16 | | public static LogLevel GetMinimumLevelForCommandLine(IEnumerable<string> args) |
| | | 17 | | { |
| | 1 | 18 | | ArgumentNullException.ThrowIfNull(args); |
| | | 19 | | |
| | 1 | 20 | | return args.Any(QuietExperimentRunCommands.Contains) |
| | 1 | 21 | | ? LogLevel.Warning |
| | 1 | 22 | | : LogLevel.Information; |
| | | 23 | | } |
| | | 24 | | |
| | | 25 | | public static ILogger<T> CreateLogger<T>(LogLevel minimumLevel = LogLevel.Information) |
| | | 26 | | { |
| | 1 | 27 | | var serviceCollection = new ServiceCollection(); |
| | 1 | 28 | | serviceCollection.AddLogging(builder => |
| | 1 | 29 | | builder.AddSimpleConsole(options => |
| | 1 | 30 | | { |
| | 1 | 31 | | options.SingleLine = true; |
| | 1 | 32 | | options.IncludeScopes = false; |
| | 1 | 33 | | options.TimestampFormat = null; |
| | 1 | 34 | | options.ColorBehavior = Microsoft.Extensions.Logging.Console.LoggerColorBehavior.Enabled; |
| | 1 | 35 | | }) |
| | 1 | 36 | | .SetMinimumLevel(minimumLevel)); |
| | | 37 | | |
| | 1 | 38 | | var serviceProvider = serviceCollection.BuildServiceProvider(); |
| | 1 | 39 | | return serviceProvider.GetRequiredService<ILogger<T>>(); |
| | | 40 | | } |
| | | 41 | | } |