Class: Rsodx::Logger
- Inherits:
-
Object
- Object
- Rsodx::Logger
- Defined in:
- lib/rsodx/logger.rb
Defined Under Namespace
Classes: LogEntry
Constant Summary collapse
- LEVELS =
%i[info debug warn error fatal].freeze
- OPTIONS =
{ with_backtrace: false }.freeze
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(adapter, options = {}) ⇒ Logger
constructor
A new instance of Logger.
- #log(level = :info, code:, message:, context: {}, backtrace: nil) ⇒ Object
Constructor Details
#initialize(adapter, options = {}) ⇒ Logger
Returns a new instance of Logger.
13 14 15 16 17 |
# File 'lib/rsodx/logger.rb', line 13 def initialize(adapter, = {}) raise ArgumentError, 'Invalid LoggerAdapter' unless adapter.is_a?(LoggerAdapter) @adapter = adapter @options = OPTIONS.merge().slice(*OPTIONS.keys) end |
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
7 8 9 |
# File 'lib/rsodx/logger.rb', line 7 def adapter @adapter end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/rsodx/logger.rb', line 7 def @options end |
Instance Method Details
#log(level = :info, code:, message:, context: {}, backtrace: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rsodx/logger.rb', line 19 def log(level = :info, code:, message:, context: {}, backtrace: nil) raise ArgumentError, "Invalid log level: #{level}" unless LEVELS.include?(level) entry = LogEntry.new( timestamp: Time.now.utc.iso8601, appname: appname, level: level, code: code, message: , context: context, backtrace: include_backtrace?(level) ? (backtrace || caller).take(10) : nil ) adapter.puts(entry) end |