Class: SimpleStructuredLogger::Writer
- Inherits:
-
Object
- Object
- SimpleStructuredLogger::Writer
- Includes:
- Singleton
- Defined in:
- lib/simple_structured_logger.rb
Instance Attribute Summary collapse
-
#default_tags ⇒ Object
Returns the value of attribute default_tags.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #debug(msg, opts = {}) ⇒ Object
- #error(msg, opts = {}) ⇒ Object
- #info(msg, opts = {}) ⇒ Object
-
#initialize ⇒ Writer
constructor
A new instance of Writer.
- #reset_context! ⇒ Object
- #set_context(context) ⇒ Object
- #set_log_level_from_environment ⇒ Object
- #warn(msg, opts = {}) ⇒ Object
Constructor Details
#initialize ⇒ Writer
Returns a new instance of Writer.
54 55 56 57 58 59 |
# File 'lib/simple_structured_logger.rb', line 54 def initialize @logger = ::Logger.new(STDOUT) @default_tags = {} set_log_level_from_environment end |
Instance Attribute Details
#default_tags ⇒ Object
Returns the value of attribute default_tags.
52 53 54 |
# File 'lib/simple_structured_logger.rb', line 52 def @default_tags end |
#logger ⇒ Object
Returns the value of attribute logger.
52 53 54 |
# File 'lib/simple_structured_logger.rb', line 52 def logger @logger end |
Instance Method Details
#debug(msg, opts = {}) ⇒ Object
91 92 93 |
# File 'lib/simple_structured_logger.rb', line 91 def debug(msg, opts={}) @logger.debug("#{msg}: #{(opts)}") end |
#error(msg, opts = {}) ⇒ Object
83 84 85 |
# File 'lib/simple_structured_logger.rb', line 83 def error(msg, opts={}) @logger.error("#{msg}: #{(opts)}") end |
#info(msg, opts = {}) ⇒ Object
87 88 89 |
# File 'lib/simple_structured_logger.rb', line 87 def info(msg, opts={}) @logger.info("#{msg}: #{(opts)}") end |
#reset_context! ⇒ Object
69 70 71 |
# File 'lib/simple_structured_logger.rb', line 69 def reset_context! @default_tags = {} end |
#set_context(context) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/simple_structured_logger.rb', line 73 def set_context(context) reset_context! if SimpleStructuredLogger::Configuration. context = SimpleStructuredLogger::Configuration..call(context) end @default_tags.merge!(context) end |
#set_log_level_from_environment ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/simple_structured_logger.rb', line 61 def set_log_level_from_environment env_log_level = ENV['LOG_LEVEL'] if !env_log_level.nil? && Logger::Severity.const_defined?(env_log_level.upcase) @logger.level = Logger::Severity.const_get(env_log_level.upcase) end end |
#warn(msg, opts = {}) ⇒ Object
95 96 97 |
# File 'lib/simple_structured_logger.rb', line 95 def warn(msg, opts={}) @logger.warn("#{msg}: #{(opts)}") end |