This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(GH-118) Update to different handling of logging
resolves #118
- Loading branch information
1 parent
897fbaa
commit 856c5d7
Showing
12 changed files
with
81 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Diagnostics; | ||
using Codecov.Program; | ||
using Serilog; | ||
using Serilog.Events; | ||
using Serilog.Sinks.SystemConsole.Themes; | ||
|
||
namespace Codecov.Logging | ||
{ | ||
internal static class LogConfiguration | ||
{ | ||
private const string ConsoleFullTemplate = "[{Level:u3}] " + ConsoleInfoTemplate; | ||
private const string ConsoleInfoTemplate = "{Message:l}{NewLine}{Exception}"; | ||
private static readonly ConsoleTheme _consoleTheme = AnsiConsoleTheme.Code; | ||
private static readonly ConsoleTheme _noColorTheme = ConsoleTheme.None; | ||
|
||
public static void ConfigureLogging(CommandLineOptions options) | ||
{ | ||
var config = new LoggerConfiguration() | ||
.MinimumLevel.Verbose(); | ||
|
||
CreateDebugLogger(config); | ||
CreateConsoleInformationLogger(config, ConsoleInfoTemplate, options); | ||
CreateConsoleFullLogger(config, ConsoleFullTemplate, options); | ||
|
||
Log.Logger = config.CreateLogger(); | ||
} | ||
|
||
private static void CreateConsoleFullLogger(LoggerConfiguration config, string consoleTemplate, CommandLineOptions options) | ||
{ | ||
var color = options.NoColor ? _noColorTheme : _consoleTheme; | ||
|
||
config.WriteTo.Logger((config) => config | ||
.Filter.ByExcluding((logEvent) => !options.Verbose && logEvent.Level == LogEventLevel.Verbose) | ||
.Filter.ByExcluding((logEvent) => logEvent.Level == LogEventLevel.Information) | ||
.WriteTo.Console( | ||
outputTemplate: consoleTemplate, | ||
standardErrorFromLevel: LogEventLevel.Warning, | ||
theme: color)); | ||
} | ||
|
||
private static void CreateConsoleInformationLogger(LoggerConfiguration config, string consoleTemplate, CommandLineOptions options) | ||
{ | ||
var color = options.NoColor ? _noColorTheme : _consoleTheme; | ||
|
||
config.WriteTo.Logger((config) => config | ||
.Filter.ByIncludingOnly((logEvent) => logEvent.Level == LogEventLevel.Information) | ||
.WriteTo.Console( | ||
outputTemplate: consoleTemplate, | ||
theme: color)); | ||
} | ||
|
||
[Conditional("DEBUG")] | ||
private static void CreateDebugLogger(LoggerConfiguration config) | ||
{ | ||
config.WriteTo.Debug(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters