46 lines
997 B
Crystal
46 lines
997 B
Crystal
require "log"
|
|
require "colorize"
|
|
|
|
module Funfriend::Logging
|
|
extend self
|
|
|
|
struct FunfriendFormat < Log::StaticFormatter
|
|
private def severity_color(severity : Log::Severity) : Colorize::Object
|
|
case severity
|
|
when .trace?
|
|
Colorize.with.dark_gray
|
|
when .debug?
|
|
Colorize.with.dark_gray
|
|
when .info?
|
|
Colorize.with.cyan
|
|
when .notice?
|
|
Colorize.with.cyan
|
|
when .warn?
|
|
Colorize.with.yellow
|
|
when .error?
|
|
Colorize.with.red
|
|
when .fatal?
|
|
Colorize.with.light_red
|
|
else
|
|
Colorize.with.white
|
|
end
|
|
end
|
|
|
|
def run
|
|
severity_color(@entry.severity).surround(@io) do
|
|
@entry.severity.label.rjust(@io, 6)
|
|
end
|
|
string " "
|
|
Colorize.with.white.surround(@io) do
|
|
source
|
|
end
|
|
string " "
|
|
message
|
|
end
|
|
end
|
|
|
|
def init
|
|
Log.setup(backend: Log::IOBackend.new(formatter: FunfriendFormat, dispatcher: Log::DispatchMode::Sync))
|
|
end
|
|
end
|