Class: NatsWork::Logger
- Inherits:
-
Object
- Object
- NatsWork::Logger
- Defined in:
- lib/natswork/logger.rb
Constant Summary collapse
- LEVELS =
{ debug: ::Logger::DEBUG, info: ::Logger::INFO, warn: ::Logger::WARN, error: ::Logger::ERROR, fatal: ::Logger::FATAL }.freeze
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#structured ⇒ Object
readonly
Returns the value of attribute structured.
Class Method Summary collapse
- .configure(options = {}) ⇒ Object
- .global ⇒ Object
- .method_missing(method, *args, &block) ⇒ Object
- .respond_to_missing?(method, include_private = false) ⇒ Boolean
Instance Method Summary collapse
- #debug(message, context = {}, &block) ⇒ Object
- #error(message, context = {}, &block) ⇒ Object
- #fatal(message, context = {}, &block) ⇒ Object
- #info(message, context = {}, &block) ⇒ Object
-
#initialize(options = {}) ⇒ Logger
constructor
A new instance of Logger.
- #level=(level) ⇒ Object
- #warn(message, context = {}, &block) ⇒ Object
- #with_namespace(namespace) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Logger
Returns a new instance of Logger.
19 20 21 22 23 24 25 26 27 |
# File 'lib/natswork/logger.rb', line 19 def initialize( = {}) @namespace = [:namespace] || 'natswork' @structured = .fetch(:structured, false) @output = [:output] || $stdout @level = [:level] || :info @formatter = [:formatter] setup_logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
17 18 19 |
# File 'lib/natswork/logger.rb', line 17 def logger @logger end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
17 18 19 |
# File 'lib/natswork/logger.rb', line 17 def namespace @namespace end |
#structured ⇒ Object (readonly)
Returns the value of attribute structured.
17 18 19 |
# File 'lib/natswork/logger.rb', line 17 def structured @structured end |
Class Method Details
.configure(options = {}) ⇒ Object
143 144 145 |
# File 'lib/natswork/logger.rb', line 143 def configure( = {}) @global = new() end |
.global ⇒ Object
139 140 141 |
# File 'lib/natswork/logger.rb', line 139 def global @global ||= new end |
.method_missing(method, *args, &block) ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/natswork/logger.rb', line 147 def method_missing(method, *args, &block) if global.respond_to?(method) global.send(method, *args, &block) else super end end |
.respond_to_missing?(method, include_private = false) ⇒ Boolean
155 156 157 |
# File 'lib/natswork/logger.rb', line 155 def respond_to_missing?(method, include_private = false) global.respond_to?(method, include_private) || super end |
Instance Method Details
#debug(message, context = {}, &block) ⇒ Object
29 30 31 |
# File 'lib/natswork/logger.rb', line 29 def debug(, context = {}, &block) log(:debug, , context, &block) end |
#error(message, context = {}, &block) ⇒ Object
41 42 43 |
# File 'lib/natswork/logger.rb', line 41 def error(, context = {}, &block) log(:error, , context, &block) end |
#fatal(message, context = {}, &block) ⇒ Object
45 46 47 |
# File 'lib/natswork/logger.rb', line 45 def fatal(, context = {}, &block) log(:fatal, , context, &block) end |
#info(message, context = {}, &block) ⇒ Object
33 34 35 |
# File 'lib/natswork/logger.rb', line 33 def info(, context = {}, &block) log(:info, , context, &block) end |
#level=(level) ⇒ Object
59 60 61 62 |
# File 'lib/natswork/logger.rb', line 59 def level=(level) @level = level @logger.level = LEVELS[level] || ::Logger::INFO end |
#warn(message, context = {}, &block) ⇒ Object
37 38 39 |
# File 'lib/natswork/logger.rb', line 37 def warn(, context = {}, &block) log(:warn, , context, &block) end |
#with_namespace(namespace) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/natswork/logger.rb', line 49 def with_namespace(namespace) self.class.new( namespace: "#{@namespace}.#{namespace}", structured: @structured, output: @output, level: @level, formatter: @formatter ) end |