Class: Lennarb::Logger
- Inherits:
-
Object
- Object
- Lennarb::Logger
- Defined in:
- lib/lennarb/logger.rb
Constant Summary collapse
- LEVELS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ debug: ::Logger::DEBUG, info: ::Logger::INFO, warn: ::Logger::WARN, error: ::Logger::ERROR, fatal: ::Logger::FATAL }.freeze
- DEFAULT_FORMATTER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
proc do || line = [[:tag], [:message]].compact.join(" ") "#{line}\n" end
Instance Method Summary collapse
-
#initialize(logger = ::Logger.new($stdout, level: ::Logger::INFO), formatter: DEFAULT_FORMATTER, tag: nil, tag_color: nil, message_color: nil, colorize: false) ⇒ Logger
constructor
Initialize a new logger.
-
#tagged(*tags) {|logger| ... } ⇒ Logger
Create a new logger with additional tags.
Constructor Details
#initialize(logger = ::Logger.new($stdout, level: ::Logger::INFO), formatter: DEFAULT_FORMATTER, tag: nil, tag_color: nil, message_color: nil, colorize: false) ⇒ Logger
Initialize a new logger
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lennarb/logger.rb', line 26 def initialize( logger = ::Logger.new($stdout, level: ::Logger::INFO), formatter: DEFAULT_FORMATTER, tag: nil, tag_color: nil, message_color: nil, colorize: false ) @logger = logger.dup @logger.formatter = proc { |*args| format_log(*args) } @tag = Array(tag) @formatter = formatter @tag_color = tag_color @message_color = @colorize = colorize || $stdout.tty? end |
Instance Method Details
#tagged(*tags) {|logger| ... } ⇒ Logger
Create a new logger with additional tags
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/lennarb/logger.rb', line 55 def tagged(*) new_logger = Logger.new( @logger, formatter: @formatter, tag: @tag.dup.concat(), tag_color: @tag_color, message_color: @message_color, colorize: @colorize ) yield new_logger if block_given? new_logger end |