Refactored log setup onto separate project
This commit is contained in:
parent
ef8f5c357f
commit
67c37a49e1
@ -52,6 +52,10 @@ shards:
|
|||||||
git: https://github.com/kemalcr/kemal-basic-auth.git
|
git: https://github.com/kemalcr/kemal-basic-auth.git
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
|
||||||
|
oplog:
|
||||||
|
git: https://github.com/ralsina/oplog.git
|
||||||
|
version: 0.1.0+git.commit.70e3a7bbc2f1f4d75cf4e142244b263ee2844ba1
|
||||||
|
|
||||||
radix:
|
radix:
|
||||||
git: https://github.com/luislavena/radix.git
|
git: https://github.com/luislavena/radix.git
|
||||||
version: 0.4.1
|
version: 0.4.1
|
||||||
|
@ -34,6 +34,8 @@ dependencies:
|
|||||||
github: kemalcr/kemal
|
github: kemalcr/kemal
|
||||||
kemal-basic-auth:
|
kemal-basic-auth:
|
||||||
github: kemalcr/kemal-basic-auth
|
github: kemalcr/kemal-basic-auth
|
||||||
|
oplog:
|
||||||
|
github: ralsina/oplog
|
||||||
rucksack:
|
rucksack:
|
||||||
github: busyloop/rucksack
|
github: busyloop/rucksack
|
||||||
|
|
||||||
|
50
src/log.cr
50
src/log.cr
@ -1,50 +0,0 @@
|
|||||||
module Logging
|
|
||||||
extend self
|
|
||||||
|
|
||||||
class LogBackend < Log::IOBackend
|
|
||||||
@stdout = Log::IOBackend.new(io: STDOUT, formatter: LogFormat)
|
|
||||||
@stderr = Log::IOBackend.new(io: STDERR, formatter: LogFormat)
|
|
||||||
|
|
||||||
def write(entry : Log::Entry)
|
|
||||||
if entry.severity >= Log::Severity::Error
|
|
||||||
@stderr.write entry
|
|
||||||
else
|
|
||||||
@stdout.write entry
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
struct LogFormat < Log::StaticFormatter
|
|
||||||
@@colors = {
|
|
||||||
"FATAL" => :red,
|
|
||||||
"ERROR" => :red,
|
|
||||||
"WARN" => :yellow,
|
|
||||||
"NOTICE" => :yellow,
|
|
||||||
"INFO" => :green,
|
|
||||||
"DEBUG" => :blue,
|
|
||||||
"TRACE" => :light_blue,
|
|
||||||
}
|
|
||||||
|
|
||||||
def run
|
|
||||||
string "#{@entry.message}".colorize(@@colors[@entry.severity.label])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.setup(verbosity)
|
|
||||||
Colorize.on_tty_only!
|
|
||||||
verbosity = [0, verbosity].max
|
|
||||||
verbosity = [6, verbosity].min
|
|
||||||
severity = [
|
|
||||||
Log::Severity::Fatal,
|
|
||||||
Log::Severity::Error,
|
|
||||||
Log::Severity::Warn,
|
|
||||||
Log::Severity::Notice,
|
|
||||||
Log::Severity::Info,
|
|
||||||
Log::Severity::Debug,
|
|
||||||
Log::Severity::Trace,
|
|
||||||
][verbosity]
|
|
||||||
Log.setup(
|
|
||||||
severity,
|
|
||||||
LogBackend.new)
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,8 +1,8 @@
|
|||||||
require "./config.cr"
|
require "./config.cr"
|
||||||
require "./faaso.cr"
|
require "./faaso.cr"
|
||||||
require "./log.cr"
|
|
||||||
require "colorize"
|
require "colorize"
|
||||||
require "docopt"
|
require "docopt"
|
||||||
|
require "oplog"
|
||||||
require "rucksack"
|
require "rucksack"
|
||||||
|
|
||||||
macro version
|
macro version
|
||||||
@ -35,7 +35,7 @@ Options:
|
|||||||
DOC
|
DOC
|
||||||
|
|
||||||
ans = Docopt.docopt(doc, ARGV)
|
ans = Docopt.docopt(doc, ARGV)
|
||||||
Logging.setup(ans["-v"].to_s.to_i)
|
Oplog.setup(ans["-v"].to_s.to_i)
|
||||||
Log.debug { ans }
|
Log.debug { ans }
|
||||||
|
|
||||||
status : Int32 = 0
|
status : Int32 = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user