Class: SimpleStructuredLogger::Writer

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/simple_structured_logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWriter

Returns a new instance of Writer.



44
45
46
47
# File 'lib/simple_structured_logger.rb', line 44

def initialize
  @l = ::Logger.new(STDOUT)
  @default_tags = {}
end

Instance Attribute Details

#default_tagsObject (readonly)

Returns the value of attribute default_tags.



42
43
44
# File 'lib/simple_structured_logger.rb', line 42

def default_tags
  @default_tags
end

Instance Method Details

#debug(msg, opts = {}) ⇒ Object



67
68
69
# File 'lib/simple_structured_logger.rb', line 67

def debug(msg, opts={})
  @l.debug("#{msg}: #{stringify_tags(opts)}")
end

#error(msg, opts = {}) ⇒ Object



59
60
61
# File 'lib/simple_structured_logger.rb', line 59

def error(msg, opts={})
  @l.error("#{msg}: #{stringify_tags(opts)}")
end

#info(msg, opts = {}) ⇒ Object



63
64
65
# File 'lib/simple_structured_logger.rb', line 63

def info(msg, opts={})
  @l.info("#{msg}: #{stringify_tags(opts)}")
end

#reset_context!Object



49
50
51
# File 'lib/simple_structured_logger.rb', line 49

def reset_context!
  @default_tags = {}
end

#set_context(context) ⇒ Object



53
54
55
56
57
# File 'lib/simple_structured_logger.rb', line 53

def set_context(context)
  reset_context!

  @default_tags.merge!(context)
end

#warn(msg, opts = {}) ⇒ Object



71
72
73
# File 'lib/simple_structured_logger.rb', line 71

def warn(msg, opts={})
  @l.warn("#{msg}: #{stringify_tags(opts)}")
end