Class: Dataflow::Logger
- Inherits:
-
Object
- Object
- Dataflow::Logger
- Defined in:
- lib/dataflow/logger.rb
Defined Under Namespace
Classes: LoggerImpl
Instance Attribute Summary collapse
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#use_notifications ⇒ Object
Returns the value of attribute use_notifications.
Instance Method Summary collapse
- #error(error:, custom_message: '') ⇒ Object
-
#initialize(prefix:, use_notifications: false) ⇒ Logger
constructor
A new instance of Logger.
- #log(str) ⇒ Object
- #trace_id ⇒ Object
Constructor Details
#initialize(prefix:, use_notifications: false) ⇒ Logger
Returns a new instance of Logger.
7 8 9 10 11 |
# File 'lib/dataflow/logger.rb', line 7 def initialize(prefix:, use_notifications: false) @prefix = prefix @use_notifications = use_notifications @@impl = LoggerImpl.new end |
Instance Attribute Details
#prefix ⇒ Object
Returns the value of attribute prefix.
4 5 6 |
# File 'lib/dataflow/logger.rb', line 4 def prefix @prefix end |
#use_notifications ⇒ Object
Returns the value of attribute use_notifications.
5 6 7 |
# File 'lib/dataflow/logger.rb', line 5 def use_notifications @use_notifications end |
Instance Method Details
#error(error:, custom_message: '') ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/dataflow/logger.rb', line 21 def error(error:, custom_message: '') first_line = "[ERROR => #{error.class}: '#{error.}']" first_line += " #{}" if .present? first_line += ' Backtrace: ' log(first_line) log('--') (error.backtrace || []).each_with_index { |line, idx| log("#{idx}: #{line}") } end |
#log(str) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/dataflow/logger.rb', line 13 def log(str) return if ENV['DATAFLOW_SKIP_LOGGING'] now = DateTime.now.strftime('%y-%m-%d %H:%M:%S') = "[#{now}][#{trace_id}] #{prefix} | #{str}" logger_impl = @@impl logger_impl.log() end |
#trace_id ⇒ Object
30 31 32 |
# File 'lib/dataflow/logger.rb', line 30 def trace_id (Process.pid + Thread.current.object_id).to_s(16)[-8..-1] end |