Logger: Make colorize_logs true by default

This commit is contained in:
Fijxu 2024-09-20 00:32:27 -03:00
parent f8ec312328
commit d77afdcf00
No known key found for this signature in database
GPG Key ID: 32C1DDF333EDA6A4
3 changed files with 7 additions and 6 deletions

View File

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

View File

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

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