Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
Allow setting log level
Browse files Browse the repository at this point in the history
  • Loading branch information
floriandejonckheere committed Mar 7, 2024
1 parent 9da2058 commit 80b5852
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/mosaik/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
module MOSAIK
class Logger < SimpleDelegator
def initialize
super(::Logger.new($stdout, formatter:))
super(::Logger.new($stdout, level:, formatter:))
end

def level
ENV.fetch("LOG_LEVEL", "info")
end

private

def formatter
proc do |severity, _time, _progname, msg|
abort("#{File.basename($PROGRAM_NAME)}: #{msg}".white.on_red) if severity == "FATAL"
abort("#{File.basename($PROGRAM_NAME)}: #{msg}".white.on_red) if severity == ::Logger::FATAL

msg = "#{msg}\n"
msg = msg.yellow if severity == "DEBUG"
msg = msg.red if severity == "ERROR"
msg = msg.yellow if severity == ::Logger::DEBUG
msg = msg.red if severity == ::Logger::ERROR

msg
end
Expand Down

0 comments on commit 80b5852

Please sign in to comment.