Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Logger: moved to separate file, updated & added spec
- Loading branch information
1 parent
cb99e67
commit 8630099
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# encoding: utf-8 | ||
module Skiima | ||
class Logger | ||
extend Forwardable | ||
|
||
delegate debug: :logger | ||
delegate info: :logger | ||
delegate warn: :logger | ||
delegate error: :logger | ||
delegate fatal: :logger | ||
|
||
attr_accessor :logger, :logging_out, :logging_level | ||
|
||
def initialize(opts = {}) | ||
@logging_out = get_logger_out(opts[:logging_out]) | ||
@logging_level = get_logger_level(opts[:logging_level]) | ||
create_logger | ||
end | ||
|
||
private | ||
|
||
def get_logger_out(str) | ||
case str | ||
when /STDOUT/i then ::STDOUT | ||
when /STDERR/i then ::STDERR | ||
else File.join(root_path, str) | ||
end | ||
end | ||
|
||
def get_logger_level(str) | ||
case str | ||
when '4', /fatal/i then ::Logger::FATAL | ||
when '3', /error/i then ::Logger::ERROR | ||
when '2', /warn/i then ::Logger::WARN | ||
when '1', /info/i then ::Logger::INFO | ||
when '0', /debug/i then ::Logger::DEBUG | ||
else ::Logger::ERROR | ||
end | ||
end | ||
|
||
def create_logger | ||
@logger = ::Logger.new(logging_out) | ||
@logger.level = logging_level | ||
end | ||
|
||
end | ||
|
||
module LoggerHelpers | ||
def log_message(logger, msg) | ||
logger.debug msg | ||
end | ||
end | ||
end | ||
|
Empty file.