Class: BlockLogger
- Inherits:
-
Object
- Object
- BlockLogger
- Defined in:
- lib/block_logger.rb
Constant Summary collapse
- VERSION =
'0.1.2'- DEFAULT_LOG_LEVEL =
:info- DEFAULT_LOG_PATTERN =
"%.1l, [%d] %5l -- %c: %m\n".freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .level ⇒ Object
- .level=(level) ⇒ Object
- .set_trace(name, v = true) ⇒ Object
- .trace?(name) ⇒ Boolean
- .traces ⇒ Object
Instance Method Summary collapse
- #debug(msg, **kwargs) ⇒ Object
- #error(msg, **kwargs) ⇒ Object
- #fatal(msg, **kwargs) ⇒ Object
- #info(msg, **kwargs) ⇒ Object
-
#initialize(name, logger = nil) ⇒ BlockLogger
constructor
A new instance of BlockLogger.
- #level ⇒ Object
- #level=(l) ⇒ Object
- #serialize_kwargs(kwargs) ⇒ Object
- #trace(msg, **kwargs) ⇒ Object
- #warn(msg, **kwargs) ⇒ Object
Constructor Details
#initialize(name, logger = nil) ⇒ BlockLogger
39 40 41 42 |
# File 'lib/block_logger.rb', line 39 def initialize(name, logger=nil) @name = name @logger = logger || Logging.logger[name] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
37 38 39 |
# File 'lib/block_logger.rb', line 37 def name @name end |
Class Method Details
.level ⇒ Object
28 29 30 |
# File 'lib/block_logger.rb', line 28 def level Logging.logger.root.level end |
.level=(level) ⇒ Object
32 33 34 |
# File 'lib/block_logger.rb', line 32 def level=(level) Logging.logger.root.level = level end |
.set_trace(name, v = true) ⇒ Object
20 21 22 |
# File 'lib/block_logger.rb', line 20 def set_trace(name, v=true) traces[name] = v end |
.trace?(name) ⇒ Boolean
16 17 18 |
# File 'lib/block_logger.rb', line 16 def trace?(name) !!traces[name] end |
.traces ⇒ Object
24 25 26 |
# File 'lib/block_logger.rb', line 24 def traces @traces ||= {} end |
Instance Method Details
#debug(msg, **kwargs) ⇒ Object
74 75 76 |
# File 'lib/block_logger.rb', line 74 def debug(msg, **kwargs) @logger.debug "#{msg}#{serialize_kwargs(kwargs)}" end |
#error(msg, **kwargs) ⇒ Object
62 63 64 |
# File 'lib/block_logger.rb', line 62 def error(msg, **kwargs) @logger.error "#{msg}#{serialize_kwargs(kwargs)}" end |
#fatal(msg, **kwargs) ⇒ Object
58 59 60 |
# File 'lib/block_logger.rb', line 58 def fatal(msg, **kwargs) @logger.fatal "#{msg}#{serialize_kwargs(kwargs)}" end |
#info(msg, **kwargs) ⇒ Object
70 71 72 |
# File 'lib/block_logger.rb', line 70 def info(msg, **kwargs) @logger.info "#{msg}#{serialize_kwargs(kwargs)}" end |
#level ⇒ Object
50 51 52 |
# File 'lib/block_logger.rb', line 50 def level @logger.level end |
#level=(l) ⇒ Object
54 55 56 |
# File 'lib/block_logger.rb', line 54 def level=(l) @logger.level = l end |
#serialize_kwargs(kwargs) ⇒ Object
78 79 80 |
# File 'lib/block_logger.rb', line 78 def serialize_kwargs(kwargs) " #{kwargs.map {|k,v| "#{k}=#{v}" }.join(' ')}" end |
#trace(msg, **kwargs) ⇒ Object
44 45 46 47 48 |
# File 'lib/block_logger.rb', line 44 def trace(msg, **kwargs) if self.class.trace?(name) @logger.info "TRACE #{msg}#{serialize_kwargs(kwargs)}" end end |
#warn(msg, **kwargs) ⇒ Object
66 67 68 |
# File 'lib/block_logger.rb', line 66 def warn(msg, **kwargs) @logger.warn "#{msg}#{serialize_kwargs(kwargs)}" end |