lumberjack 1.4.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ARCHITECTURE.md +524 -176
- data/CHANGELOG.md +89 -0
- data/README.md +604 -211
- data/UPGRADE_GUIDE.md +80 -0
- data/VERSION +1 -1
- data/lib/lumberjack/attribute_formatter.rb +451 -0
- data/lib/lumberjack/attributes_helper.rb +100 -0
- data/lib/lumberjack/context.rb +120 -23
- data/lib/lumberjack/context_logger.rb +620 -0
- data/lib/lumberjack/device/buffer.rb +209 -0
- data/lib/lumberjack/device/date_rolling_log_file.rb +10 -62
- data/lib/lumberjack/device/log_file.rb +76 -29
- data/lib/lumberjack/device/logger_wrapper.rb +137 -0
- data/lib/lumberjack/device/multi.rb +92 -30
- data/lib/lumberjack/device/null.rb +26 -8
- data/lib/lumberjack/device/size_rolling_log_file.rb +13 -54
- data/lib/lumberjack/device/test.rb +337 -0
- data/lib/lumberjack/device/writer.rb +184 -176
- data/lib/lumberjack/device.rb +134 -15
- data/lib/lumberjack/device_registry.rb +90 -0
- data/lib/lumberjack/entry_formatter.rb +357 -0
- data/lib/lumberjack/fiber_locals.rb +55 -0
- data/lib/lumberjack/forked_logger.rb +143 -0
- data/lib/lumberjack/formatter/date_time_formatter.rb +14 -3
- data/lib/lumberjack/formatter/exception_formatter.rb +12 -2
- data/lib/lumberjack/formatter/id_formatter.rb +13 -1
- data/lib/lumberjack/formatter/inspect_formatter.rb +14 -1
- data/lib/lumberjack/formatter/multiply_formatter.rb +10 -0
- data/lib/lumberjack/formatter/object_formatter.rb +13 -1
- data/lib/lumberjack/formatter/pretty_print_formatter.rb +15 -2
- data/lib/lumberjack/formatter/redact_formatter.rb +18 -3
- data/lib/lumberjack/formatter/round_formatter.rb +12 -0
- data/lib/lumberjack/formatter/string_formatter.rb +9 -1
- data/lib/lumberjack/formatter/strip_formatter.rb +13 -1
- data/lib/lumberjack/formatter/structured_formatter.rb +18 -2
- data/lib/lumberjack/formatter/tagged_message.rb +10 -32
- data/lib/lumberjack/formatter/tags_formatter.rb +32 -0
- data/lib/lumberjack/formatter/truncate_formatter.rb +8 -1
- data/lib/lumberjack/formatter.rb +271 -141
- data/lib/lumberjack/formatter_registry.rb +84 -0
- data/lib/lumberjack/io_compatibility.rb +133 -0
- data/lib/lumberjack/local_log_template.rb +209 -0
- data/lib/lumberjack/log_entry.rb +154 -79
- data/lib/lumberjack/log_entry_matcher/score.rb +276 -0
- data/lib/lumberjack/log_entry_matcher.rb +126 -0
- data/lib/lumberjack/logger.rb +328 -556
- data/lib/lumberjack/message_attributes.rb +38 -0
- data/lib/lumberjack/rack/context.rb +66 -15
- data/lib/lumberjack/rack.rb +0 -2
- data/lib/lumberjack/remap_attribute.rb +24 -0
- data/lib/lumberjack/severity.rb +52 -15
- data/lib/lumberjack/tag_context.rb +8 -71
- data/lib/lumberjack/tag_formatter.rb +22 -188
- data/lib/lumberjack/tags.rb +15 -21
- data/lib/lumberjack/template.rb +252 -62
- data/lib/lumberjack/template_registry.rb +60 -0
- data/lib/lumberjack/utils.rb +198 -48
- data/lib/lumberjack.rb +167 -59
- data/lumberjack.gemspec +4 -2
- metadata +41 -15
- data/lib/lumberjack/device/rolling_log_file.rb +0 -145
- data/lib/lumberjack/rack/request_id.rb +0 -31
- data/lib/lumberjack/rack/unit_of_work.rb +0 -21
- data/lib/lumberjack/tagged_logger_support.rb +0 -81
- data/lib/lumberjack/tagged_logging.rb +0 -29
data/lib/lumberjack/context.rb
CHANGED
@@ -1,55 +1,152 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Lumberjack
|
4
|
-
#
|
4
|
+
# Context stores logging settings and attributes that can be scoped to specific code blocks
|
5
|
+
# or inherited between loggers. It provides a hierarchical system for managing logging state
|
6
|
+
# including level, progname, default severity, and custom attributes.
|
7
|
+
#
|
8
|
+
# Child contexts inherit all configuration from their parent but can override any values.
|
9
|
+
# Changes to child contexts don't affect parent contexts, providing true isolation.
|
10
|
+
#
|
11
|
+
# @see Lumberjack::ContextLogger
|
12
|
+
# @see Lumberjack::AttributesHelper
|
5
13
|
class Context
|
6
|
-
|
14
|
+
# The attributes hash containing key-value pairs to include in log entries.
|
15
|
+
# @return [Hash, nil] The attributes hash, or nil if no attributes are set.
|
16
|
+
attr_reader :attributes
|
7
17
|
|
8
|
-
#
|
18
|
+
# The logging level for this context.
|
19
|
+
# @return [Integer, nil] The logging level, or nil if not set (inherits from parent or default).
|
20
|
+
attr_reader :level
|
21
|
+
|
22
|
+
# The program name for this context.
|
23
|
+
# @return [String, nil] The program name, or nil if not set (inherits from parent or default).
|
24
|
+
attr_reader :progname
|
25
|
+
|
26
|
+
# The default severity used when writing log messages directly to a stream.
|
27
|
+
# @return [Integer, nil] The default severity level, or nil if not set.
|
28
|
+
attr_reader :default_severity
|
29
|
+
|
30
|
+
# The parent context from which this context inherited its initial attributes.
|
31
|
+
# @return [Lumberjack::Context, nil] The parent context, or nil if this is a top-level context.
|
32
|
+
# @api private
|
33
|
+
attr_accessor :parent
|
34
|
+
|
35
|
+
# Create a new context, optionally inheriting configuration from a parent context.
|
36
|
+
#
|
37
|
+
# When a parent context is provided, the new context inherits all configuration
|
38
|
+
# (level, progname, default_severity) and a copy of all attributes. Changes to the
|
39
|
+
# new context won't affect the parent context, providing true isolation.
|
40
|
+
#
|
41
|
+
# @param parent_context [Lumberjack::Context, nil] The parent context to inherit from.
|
9
42
|
def initialize(parent_context = nil)
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
43
|
+
@attributes = nil
|
44
|
+
@level = nil
|
45
|
+
@progname = nil
|
46
|
+
@default_severity = nil
|
47
|
+
|
48
|
+
if parent_context
|
49
|
+
@attributes = parent_context.attributes.dup if parent_context.attributes
|
50
|
+
self.level = parent_context.level
|
51
|
+
self.progname = parent_context.progname
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Set the logging level for this context. The level determines which log entries
|
56
|
+
# will be processed when this context is active.
|
57
|
+
#
|
58
|
+
# @param value [Integer, Symbol, String, nil] The logging level. Can be a numeric level,
|
59
|
+
# symbol (:debug, :info, :warn, :error, :fatal), string, or nil to unset.
|
60
|
+
# @return [void]
|
61
|
+
def level=(value)
|
62
|
+
value = Severity.coerce(value) unless value.nil?
|
63
|
+
@level = value
|
64
|
+
end
|
65
|
+
|
66
|
+
# Set the program name for this context. The progname identifies the component
|
67
|
+
# or program that is generating log entries.
|
68
|
+
#
|
69
|
+
# @param value [String, Symbol, nil] The program name. Will be converted to a frozen string.
|
70
|
+
# @return [void]
|
71
|
+
def progname=(value)
|
72
|
+
@progname = value&.to_s&.freeze
|
13
73
|
end
|
14
74
|
|
15
|
-
#
|
75
|
+
# Assign multiple attributes to this context from a hash. This method allows
|
76
|
+
# bulk assignment of context attributes and supports nested attribute names
|
77
|
+
# using dot notation.
|
16
78
|
#
|
17
|
-
# @param
|
79
|
+
# @param attributes [Hash] A hash of attribute names to values. Keys can be strings
|
80
|
+
# or symbols, and support dot notation for nested attributes.
|
18
81
|
# @return [void]
|
19
|
-
|
20
|
-
|
82
|
+
# @see #[]= for setting individual attributes
|
83
|
+
def assign_attributes(attributes)
|
84
|
+
attributes_helper.update(attributes)
|
21
85
|
end
|
22
86
|
|
23
|
-
# Get a context
|
87
|
+
# Get a context attribute by key. Supports both string and symbol keys,
|
88
|
+
# and can access nested attributes using dot notation.
|
24
89
|
#
|
25
|
-
# @param key [String, Symbol] The
|
26
|
-
# @return [Object] The
|
90
|
+
# @param key [String, Symbol] The attribute key. Supports dot notation for nested access.
|
91
|
+
# @return [Object] The attribute value, or nil if the key doesn't exist.
|
27
92
|
def [](key)
|
28
|
-
|
93
|
+
attributes_helper[key]
|
29
94
|
end
|
30
95
|
|
31
|
-
# Set a context
|
96
|
+
# Set a context attribute by key. Supports both string and symbol keys,
|
97
|
+
# and can set nested attributes using dot notation.
|
32
98
|
#
|
33
|
-
# @param key [String, Symbol] The
|
34
|
-
# @param value [Object] The
|
99
|
+
# @param key [String, Symbol] The attribute key. Supports dot notation for nested assignment.
|
100
|
+
# @param value [Object] The attribute value to set.
|
35
101
|
# @return [void]
|
36
102
|
def []=(key, value)
|
37
|
-
|
103
|
+
attributes_helper[key] = value
|
38
104
|
end
|
39
105
|
|
40
|
-
# Remove
|
106
|
+
# Remove all attributes from this context. This only affects attributes
|
107
|
+
# directly set on this context, not those inherited from parent contexts.
|
108
|
+
def clear_attributes
|
109
|
+
@attributes&.clear
|
110
|
+
end
|
111
|
+
|
112
|
+
# Remove specific attributes from this context. This only affects attributes
|
113
|
+
# directly set on this context, not those inherited from parent contexts.
|
114
|
+
# Supports dot notation for nested attribute removal.
|
41
115
|
#
|
42
|
-
# @param keys [Array<String, Symbol>] The
|
116
|
+
# @param keys [Array<String, Symbol>] The attribute keys to remove. Can use
|
117
|
+
# dot notation for nested attributes.
|
43
118
|
# @return [void]
|
44
119
|
def delete(*keys)
|
45
|
-
|
120
|
+
attributes_helper.delete(*keys)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Set the default severity level for this context. This determines the minimum
|
124
|
+
# severity level for log entries when no explicit level is specified.
|
125
|
+
#
|
126
|
+
# @param value [Integer, Symbol, String, nil] The default severity level. Can be a numeric level,
|
127
|
+
# symbol (:debug, :info, :warn, :error, :fatal), string, or nil to unset.
|
128
|
+
# @return [void]
|
129
|
+
def default_severity=(value)
|
130
|
+
value = Severity.coerce(value) unless value.nil?
|
131
|
+
@default_severity = value
|
46
132
|
end
|
47
133
|
|
48
|
-
# Clear all
|
134
|
+
# Clear all context data including attributes, level, and progname.
|
135
|
+
# This resets the context to its initial state while preserving the
|
136
|
+
# parent context relationship.
|
49
137
|
#
|
50
138
|
# @return [void]
|
51
139
|
def reset
|
52
|
-
@
|
140
|
+
@attributes&.clear
|
141
|
+
@level = nil
|
142
|
+
@progname = nil
|
143
|
+
end
|
144
|
+
|
145
|
+
private
|
146
|
+
|
147
|
+
def attributes_helper
|
148
|
+
@attributes ||= {}
|
149
|
+
AttributesHelper.new(@attributes)
|
53
150
|
end
|
54
151
|
end
|
55
152
|
end
|