Class: SemanticLogger::Formatters::Raw
- Defined in:
- lib/semantic_logger/formatters/raw.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#hash ⇒ 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.
-
#environment ⇒ Object
Environment.
-
#exception ⇒ Object
Exception.
-
#file_name_and_line ⇒ Object
Ruby file name and line number that logged the message.
-
#host ⇒ Object
Host name.
-
#initialize(time_format: :none, time_key: :time, **args) ⇒ 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.
-
#pid ⇒ Object
Process ID.
-
#tags ⇒ Object
Tags.
-
#thread_name ⇒ Object
Name of the thread that logged the message.
-
#time ⇒ Object
Date & time.
Methods inherited from Base
#backtrace, #fast_tag, #level=, #log, #measure, #pop_tags, #push_tags, #should_log?, #silence, #tagged
Constructor Details
#initialize(time_format: :none, time_key: :time, **args) ⇒ 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, time_key: :time, **args) @time_key = time_key super(time_format: time_format, **args) 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 |
#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 && logger.application end |
#call(log, logger) ⇒ Object
Returns log messages in Hash format
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/semantic_logger/formatters/raw.rb', line 115 def call(log, logger) self.hash = {} self.log = log self.logger = logger host application environment time level pid thread_name file_name_and_line duration name payload exception metric hash end |
#duration ⇒ Object
Duration
70 71 72 73 74 75 |
# File 'lib/semantic_logger/formatters/raw.rb', line 70 def duration return unless log.duration hash[:duration_ms] = log.duration hash[:duration] = log.duration_human end |
#environment ⇒ Object
Environment
25 26 27 |
# File 'lib/semantic_logger/formatters/raw.rb', line 25 def environment hash[:environment] = logger.environment if log_environment && logger && logger.environment end |
#exception ⇒ Object
Exception
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/semantic_logger/formatters/raw.rb', line 93 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 |
#file_name_and_line ⇒ Object
Ruby file name and line number that logged the message.
51 52 53 54 55 56 57 |
# File 'lib/semantic_logger/formatters/raw.rb', line 51 def file_name_and_line file, line = log.file_name_and_line return unless file hash[:file] = file hash[:line] = line.to_i 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
35 36 37 38 |
# File 'lib/semantic_logger/formatters/raw.rb', line 35 def level hash[:level] = log.level hash[:level_index] = log.level_index end |
#message ⇒ Object
Log message
83 84 85 |
# File 'lib/semantic_logger/formatters/raw.rb', line 83 def hash[:message] = log. if log. end |
#metric ⇒ Object
Metric
109 110 111 112 |
# File 'lib/semantic_logger/formatters/raw.rb', line 109 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
78 79 80 |
# File 'lib/semantic_logger/formatters/raw.rb', line 78 def name hash[:name] = log.name end |
#named_tags ⇒ Object
Named Tags
65 66 67 |
# File 'lib/semantic_logger/formatters/raw.rb', line 65 def hash[:named_tags] = log. if log. && !log..empty? end |
#payload ⇒ Object
Payload
88 89 90 |
# File 'lib/semantic_logger/formatters/raw.rb', line 88 def payload hash[:payload] = log.payload if log.payload.respond_to?(:empty?) && !log.payload.empty? end |
#pid ⇒ Object
Process ID
41 42 43 |
# File 'lib/semantic_logger/formatters/raw.rb', line 41 def pid hash[:pid] = super end |
#tags ⇒ Object
Tags
60 61 62 |
# File 'lib/semantic_logger/formatters/raw.rb', line 60 def hash[:tags] = log. if log. && !log..empty? end |
#thread_name ⇒ Object
Name of the thread that logged the message.
46 47 48 |
# File 'lib/semantic_logger/formatters/raw.rb', line 46 def thread_name hash[:thread] = log.thread_name end |
#time ⇒ Object
Date & time
30 31 32 |
# File 'lib/semantic_logger/formatters/raw.rb', line 30 def time hash[time_key] = format_time(log.time) end |