Module: Legion::Logging
- Extended by:
- Builder, Methods
- Defined in:
- lib/legion/logging.rb,
lib/legion/logging/hooks.rb,
lib/legion/logging/helper.rb,
lib/legion/logging/logger.rb,
lib/legion/logging/builder.rb,
lib/legion/logging/methods.rb,
lib/legion/logging/shipper.rb,
lib/legion/logging/version.rb,
lib/legion/logging/multi_io.rb,
lib/legion/logging/redactor.rb,
lib/legion/logging/settings.rb,
lib/legion/logging/async_writer.rb,
lib/legion/logging/event_builder.rb,
lib/legion/logging/method_tracer.rb,
lib/legion/logging/siem_exporter.rb,
lib/legion/logging/tagged_logger.rb,
lib/legion/logging/category_registry.rb,
lib/legion/logging/shipper/file_transport.rb,
lib/legion/logging/shipper/http_transport.rb
Defined Under Namespace
Modules: Builder, CategoryRegistry, EventBuilder, Helper, Hooks, MethodTracer, Methods, Redactor, SIEMExporter, Settings, Shipper
Classes: AsyncWriter, Logger, MultiIO, TaggedLogger
Constant Summary
collapse
- DEFAULT_LOG_WRITER =
->(_event, routing_key:) {}
- DEFAULT_EXCEPTION_WRITER =
->(_event, routing_key:, headers:, properties:) {}
- VERSION =
'1.5.2'
Constants included
from Methods
Methods::COMPONENT_REGEX, Methods::EXCEPTION_PRIORITY
Class Attribute Summary collapse
Class Method Summary
collapse
Methods included from Builder
async?, build_runner_trace, json?, json_format, level, log, log_format, log_level, output, prepare_log_path, resolve_lex_tag, set_log, start_async_writer, stop_async_writer, text_format
Methods included from Methods
debug, emit_tagged, error, fatal, info, log_exception, runner_exception, thread, trace, unknown, warn
Class Attribute Details
.color ⇒ Object
Returns the value of attribute color.
25
26
27
|
# File 'lib/legion/logging.rb', line 25
def color
@color
end
|
.exception_writer ⇒ Object
.log_writer ⇒ Object
31
32
33
|
# File 'lib/legion/logging.rb', line 31
def log_writer
@log_writer || DEFAULT_LOG_WRITER
end
|
Class Method Details
.clear_hooks! ⇒ Object
75
76
77
|
# File 'lib/legion/logging.rb', line 75
def clear_hooks!
Hooks.clear_hooks!
end
|
.configuration_generation ⇒ Object
43
44
45
|
# File 'lib/legion/logging.rb', line 43
def configuration_generation
@configuration_generation || 0
end
|
.current_settings ⇒ Object
39
40
41
|
# File 'lib/legion/logging.rb', line 39
def current_settings
(@current_settings || {}).dup
end
|
.enable_hooks! ⇒ Object
67
68
69
|
# File 'lib/legion/logging.rb', line 67
def enable_hooks!
Hooks.enable_hooks!
end
|
.on_error ⇒ Object
59
60
61
|
# File 'lib/legion/logging.rb', line 59
def on_error(&)
Hooks.on_error(&)
end
|
.on_fatal ⇒ Object
55
56
57
|
# File 'lib/legion/logging.rb', line 55
def on_fatal(&)
Hooks.on_fatal(&)
end
|
.on_warn ⇒ Object
63
64
65
|
# File 'lib/legion/logging.rb', line 63
def on_warn(&)
Hooks.on_warn(&)
end
|
.register_category(name, description: nil, expected_fields: []) ⇒ Object
47
48
49
|
# File 'lib/legion/logging.rb', line 47
def register_category(name, description: nil, expected_fields: [])
CategoryRegistry.register_category(name, description: description, expected_fields: expected_fields)
end
|
.registered_categories ⇒ Object
.setup(level: 'debug', format: :text, async: true, **options) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/legion/logging.rb', line 79
def setup(level: 'debug', format: :text, async: true, **options)
output(**options)
log_level(level)
log_format(format: format, **options)
@color = options[:color]
@color = format != :json && (options[:color] || (options[:color].nil? && options[:log_file].nil?))
@current_settings = {
level: level,
format: format.to_sym,
async: async,
trace: options.fetch(:trace, true),
trace_size: options.fetch(:trace_size, 4),
extended: options.fetch(:extended, true),
log_file: options[:log_file],
log_stdout: options[:log_stdout],
include_pid: options.fetch(:include_pid, false),
color: @color
}.freeze
@configuration_generation = configuration_generation + 1
Legion::Logging::Redactor.refresh_patterns! if defined?(Legion::Logging::Redactor)
if async
buffer = if defined?(Legion::Settings) && Legion::Settings.respond_to?(:[])
logging_settings = Legion::Settings[:logging]
async_settings = logging_settings[:async] if logging_settings.is_a?(Hash)
async_settings[:buffer_size] if async_settings.is_a?(Hash)
end
buffer ||= 10_000
start_async_writer(buffer_size: buffer)
else
stop_async_writer
end
end
|