Class: SemanticLogger::Formatters::Raw
- Defined in:
- lib/semantic_logger/formatters/raw.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
Fields are added by populating this hash.
-
#log ⇒ Object
Fields are added by populating this hash.
-
#logger ⇒ Object
Fields are added by populating this hash.
-
#time_key ⇒ Object
Fields are added by populating this hash.
Attributes inherited from Base
Instance Method Summary collapse
-
#application ⇒ Object
Application name.
-
#call(log, logger) ⇒ Object
Returns log messages in Hash format.
-
#duration ⇒ Object
Duration.
-
#exception ⇒ Object
Exception.
-
#host ⇒ Object
Host name.
-
#initialize(time_format: :none, log_host: true, log_application: true, time_key: :time, precision: PRECISION) ⇒ Raw
constructor
By default Raw formatter does not reformat the time.
-
#level ⇒ Object
Log level.
-
#message ⇒ Object
Log message.
-
#metric ⇒ Object
Metric.
-
#name ⇒ Object
Class / app name.
-
#named_tags ⇒ Object
Named Tags.
-
#payload ⇒ Object
Payload.
-
#process_info ⇒ Object
Process info.
-
#tags ⇒ Object
Tags.
-
#time ⇒ Object
Date & time.
Methods inherited from Base
#backtrace, #fast_tag, #level=, #measure, #pop_tags, #push_tags, #should_log?, #silence, #tagged, #with_payload
Constructor Details
#initialize(time_format: :none, log_host: true, log_application: true, time_key: :time, precision: PRECISION) ⇒ Raw
By default Raw formatter does not reformat the time
9 10 11 12 |
# File 'lib/semantic_logger/formatters/raw.rb', line 9 def initialize(time_format: :none, log_host: true, log_application: true, time_key: :time, precision: PRECISION) @time_key = time_key super(time_format: time_format, log_host: log_host, log_application: log_application, precision: precision) end |
Instance Attribute Details
#hash ⇒ Object
Fields are added by populating this hash.
6 7 8 |
# File 'lib/semantic_logger/formatters/raw.rb', line 6 def hash @hash end |
#log ⇒ Object
Fields are added by populating this hash.
6 7 8 |
# File 'lib/semantic_logger/formatters/raw.rb', line 6 def log @log end |
#logger ⇒ Object
Fields are added by populating this hash.
6 7 8 |
# File 'lib/semantic_logger/formatters/raw.rb', line 6 def logger @logger end |
#time_key ⇒ Object
Fields are added by populating this hash.
6 7 8 |
# File 'lib/semantic_logger/formatters/raw.rb', line 6 def time_key @time_key end |
Instance Method Details
#application ⇒ Object
Application name
20 21 22 |
# File 'lib/semantic_logger/formatters/raw.rb', line 20 def application hash[:application] = logger.application if log_application && logger.application end |
#call(log, logger) ⇒ Object
Returns log messages in Hash format
102 103 104 105 106 107 108 109 |
# File 'lib/semantic_logger/formatters/raw.rb', line 102 def call(log, logger) self.hash = {} self.log = log self.logger = logger host; application; time; level; process_info; duration; ; ; name; ; payload; exception; metric hash end |
#duration ⇒ Object
Duration
58 59 60 61 62 63 |
# File 'lib/semantic_logger/formatters/raw.rb', line 58 def duration return unless log.duration hash[:duration_ms] = log.duration hash[:duration] = log.duration_human end |
#exception ⇒ Object
Exception
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/semantic_logger/formatters/raw.rb', line 81 def exception return unless log.exception root = hash log.each_exception do |exception, i| name = i.zero? ? :exception : :cause root[name] = { name: exception.class.name, message: exception., stack_trace: exception.backtrace } root = root[name] end end |
#host ⇒ Object
Host name
15 16 17 |
# File 'lib/semantic_logger/formatters/raw.rb', line 15 def host hash[:host] = logger.host if log_host && logger.host end |
#level ⇒ Object
Log level
30 31 32 33 |
# File 'lib/semantic_logger/formatters/raw.rb', line 30 def level hash[:level] = log.level hash[:level_index] = log.level_index end |
#message ⇒ Object
Log message
71 72 73 |
# File 'lib/semantic_logger/formatters/raw.rb', line 71 def hash[:message] = log. if log. end |
#metric ⇒ Object
Metric
96 97 98 99 |
# File 'lib/semantic_logger/formatters/raw.rb', line 96 def metric hash[:metric] = log.metric if log.metric hash[:metric_amount] = log.metric_amount if log.metric_amount end |
#name ⇒ Object
Class / app name
66 67 68 |
# File 'lib/semantic_logger/formatters/raw.rb', line 66 def name hash[:name] = log.name end |
#named_tags ⇒ Object
Named Tags
53 54 55 |
# File 'lib/semantic_logger/formatters/raw.rb', line 53 def hash[:named_tags] = log. if log. && !log..empty? end |
#payload ⇒ Object
Payload
76 77 78 |
# File 'lib/semantic_logger/formatters/raw.rb', line 76 def payload hash[:payload] = log.payload if log.payload&.respond_to?(:empty?) && !log.payload.empty? end |
#process_info ⇒ Object
Process info
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/semantic_logger/formatters/raw.rb', line 36 def process_info hash[:pid] = $$ hash[:thread] = log.thread_name file, line = log.file_name_and_line return unless file hash[:file] = file hash[:line] = line.to_i end |
#tags ⇒ Object
Tags
48 49 50 |
# File 'lib/semantic_logger/formatters/raw.rb', line 48 def hash[:tags] = log. if log. && !log..empty? end |
#time ⇒ Object
Date & time
25 26 27 |
# File 'lib/semantic_logger/formatters/raw.rb', line 25 def time hash[time_key] = format_time(log.time) end |