diff options
| author | Fijxu <fijxu@nadeko.net> | 2024-10-08 18:36:50 -0300 |
|---|---|---|
| committer | Fijxu <fijxu@nadeko.net> | 2024-10-08 18:36:50 -0300 |
| commit | d2edd4b63fe690c248ff8709b39098fcdad0e109 (patch) | |
| tree | 4085d0017402337e5a223a69f9e2d15898ad9893 | |
| parent | 17b525f2a66f6e832ccdc74522feebe68f73d9de (diff) | |
| download | invidious-d2edd4b63fe690c248ff8709b39098fcdad0e109.tar.gz invidious-d2edd4b63fe690c248ff8709b39098fcdad0e109.tar.bz2 invidious-d2edd4b63fe690c248ff8709b39098fcdad0e109.zip | |
fixup! Logger: Add color support for different log levels
| -rw-r--r-- | config/config.example.yml | 2 | ||||
| -rw-r--r-- | src/invidious/helpers/logger.cr | 6 |
2 files changed, 5 insertions, 3 deletions
diff --git a/config/config.example.yml b/config/config.example.yml index d79622ad..f746d1f7 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -224,7 +224,7 @@ https_only: false ## ## Enables colors in logs. Useful for debugging purposes -## This is overridden if "-k" or "--colorize" +## This is overridden if "-k" or "--colorize" ## are passed on the command line. ## Colors are also disabled if the environment variable ## NO_COLOR is present and has any value diff --git a/src/invidious/helpers/logger.cr b/src/invidious/helpers/logger.cr index 3c425ff4..03349595 100644 --- a/src/invidious/helpers/logger.cr +++ b/src/invidious/helpers/logger.cr @@ -12,7 +12,9 @@ enum LogLevel end class Invidious::LogHandler < Kemal::BaseLogHandler - def initialize(@io : IO = STDOUT, @level = LogLevel::Debug, @use_color : Bool = true) + def initialize(@io : IO = STDOUT, @level = LogLevel::Debug, use_color : Bool = true) + Colorize.enabled = use_color + Colorize.on_tty_only! end def call(context : HTTP::Server::Context) @@ -56,7 +58,7 @@ class Invidious::LogHandler < Kemal::BaseLogHandler {% for level in %w(trace debug info warn error fatal) %} def {{level.id}}(message : String) if LogLevel::{{level.id.capitalize}} >= @level - puts("#{Time.utc} [{{level.id}}] #{message}".colorize(color(LogLevel::{{level.id.capitalize}})).toggle(@use_color)) + puts("#{Time.utc} [{{level.id}}] #{message}".colorize(color(LogLevel::{{level.id.capitalize}}))) end end {% end %} |
