From d77afdcf00f55a4455fb84dd90c4e5773167b759 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Fri, 20 Sep 2024 00:32:27 -0300 Subject: [PATCH] Logger: Make colorize_logs true by default --- config/config.example.yml | 6 ++++-- src/invidious/config.cr | 2 +- src/invidious/helpers/logger.cr | 5 ++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/config/config.example.yml b/config/config.example.yml index 37b932ea..fefc28be 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -226,11 +226,13 @@ https_only: false ## Enables colors in logs. Useful for debugging purposes ## 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 ## ## Accepted values: true, false -## Default: false +## Default: true ## -#colorize_logs: false +#colorize_logs: true # ----------------------------- # Features diff --git a/src/invidious/config.cr b/src/invidious/config.cr index d8543d35..054f8db7 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -69,7 +69,7 @@ class Config # Default log level, valid YAML values are ints and strings, see src/invidious/helpers/logger.cr property log_level : LogLevel = LogLevel::Info # Enables colors in logs. Useful for debugging purposes - property colorize_logs : Bool = false + property colorize_logs : Bool = true # Database configuration with separate parameters (username, hostname, etc) property db : DBConfig? = nil diff --git a/src/invidious/helpers/logger.cr b/src/invidious/helpers/logger.cr index 36a3a7f9..3c425ff4 100644 --- a/src/invidious/helpers/logger.cr +++ b/src/invidious/helpers/logger.cr @@ -12,7 +12,7 @@ enum LogLevel end class Invidious::LogHandler < Kemal::BaseLogHandler - def initialize(@io : IO = STDOUT, @level = LogLevel::Debug, @color : Bool = true) + def initialize(@io : IO = STDOUT, @level = LogLevel::Debug, @use_color : Bool = true) end def call(context : HTTP::Server::Context) @@ -56,8 +56,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(@color)) - + puts("#{Time.utc} [{{level.id}}] #{message}".colorize(color(LogLevel::{{level.id.capitalize}})).toggle(@use_color)) end end {% end %}