Class: BlockLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/block_logger.rb

Constant Summary collapse

VERSION =
'0.1.1'
DEFAULT_LOG_LEVEL =
:info
DEFAULT_LOG_PATTERN =
"%.1l, [%d] %5l -- %c: %m\n".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



37
38
39
# File 'lib/block_logger.rb', line 37

def name
  @name
end

Class Method Details

.levelObject



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

.tracesObject



24
25
26
# File 'lib/block_logger.rb', line 24

def traces
  @traces ||= {}
end

Instance Method Details

#debug(msg, **kwargs) ⇒ Object



66
67
68
# File 'lib/block_logger.rb', line 66

def debug(msg, **kwargs)
  @logger.debug "#{msg}#{serialize_kwargs(kwargs)}"
end

#error(msg, **kwargs) ⇒ Object



54
55
56
# File 'lib/block_logger.rb', line 54

def error(msg, **kwargs)
  @logger.error "#{msg}#{serialize_kwargs(kwargs)}"
end

#fatal(msg, **kwargs) ⇒ Object



50
51
52
# File 'lib/block_logger.rb', line 50

def fatal(msg, **kwargs)
  @logger.fatal "#{msg}#{serialize_kwargs(kwargs)}"
end

#info(msg, **kwargs) ⇒ Object



62
63
64
# File 'lib/block_logger.rb', line 62

def info(msg, **kwargs)
  @logger.info "#{msg}#{serialize_kwargs(kwargs)}"
end

#serialize_kwargs(kwargs) ⇒ Object



70
71
72
# File 'lib/block_logger.rb', line 70

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



58
59
60
# File 'lib/block_logger.rb', line 58

def warn(msg, **kwargs)
  @logger.warn "#{msg}#{serialize_kwargs(kwargs)}"
end