Logger: Make colorize_logs true by default

This commit is contained in:
Fijxu 2024-09-20 00:32:27 -03:00
parent 500b1f6c38
commit bbad70dd5e
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
3 changed files with 7 additions and 6 deletions

View file

@ -237,11 +237,13 @@ http_proxy:
## 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

View file

@ -79,7 +79,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

View file

@ -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 %}