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
  @logger = ::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

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

Instance Method Details

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



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

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

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



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

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

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



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

def info(msg, opts={})
  @logger.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
58
59
60
61
# File 'lib/simple_structured_logger.rb', line 53

def set_context(context)
  reset_context!

  if self.respond_to?(:expand_context)
    context = self.expand_context(context)
  end

  @default_tags.merge!(context)
end

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



75
76
77
# File 'lib/simple_structured_logger.rb', line 75

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