lumberjack 1.2.8 → 1.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +111 -58
- data/README.md +2 -2
- data/VERSION +1 -1
- data/lib/lumberjack/context.rb +13 -0
- data/lib/lumberjack/device/date_rolling_log_file.rb +9 -0
- data/lib/lumberjack/device/log_file.rb +7 -0
- data/lib/lumberjack/device/multi.rb +1 -0
- data/lib/lumberjack/device/rolling_log_file.rb +21 -21
- data/lib/lumberjack/device/writer.rb +20 -0
- data/lib/lumberjack/device.rb +15 -0
- data/lib/lumberjack/formatter/date_time_formatter.rb +1 -0
- data/lib/lumberjack/formatter/exception_formatter.rb +2 -0
- data/lib/lumberjack/formatter/id_formatter.rb +1 -0
- data/lib/lumberjack/formatter/pretty_print_formatter.rb +2 -0
- data/lib/lumberjack/formatter/structured_formatter.rb +2 -0
- data/lib/lumberjack/formatter/truncate_formatter.rb +27 -0
- data/lib/lumberjack/formatter.rb +54 -8
- data/lib/lumberjack/log_entry.rb +8 -0
- data/lib/lumberjack/logger.rb +131 -12
- data/lib/lumberjack/severity.rb +8 -0
- data/lib/lumberjack/tag_formatter.rb +19 -0
- data/lib/lumberjack/tagged_logger_support.rb +1 -1
- data/lib/lumberjack/tags.rb +6 -0
- data/lib/lumberjack/template.rb +13 -1
- data/lib/lumberjack.rb +18 -1
- metadata +8 -7
data/lib/lumberjack/template.rb
CHANGED
@@ -30,6 +30,9 @@ module Lumberjack
|
|
30
30
|
# specified precision.
|
31
31
|
#
|
32
32
|
# Messages will have white space stripped from both ends.
|
33
|
+
#
|
34
|
+
# @param [String] first_line The template to use to format the first line of a message.
|
35
|
+
# @param [Hash] options The options for the template.
|
33
36
|
def initialize(first_line, options = {})
|
34
37
|
@first_line_template, @first_line_tags = compile(first_line)
|
35
38
|
additional_lines = options[:additional_lines] || "#{Lumberjack::LINE_SEPARATOR}:message"
|
@@ -39,6 +42,9 @@ module Lumberjack
|
|
39
42
|
self.datetime_format = (options[:time_format] || :milliseconds)
|
40
43
|
end
|
41
44
|
|
45
|
+
# Set the format used to format the time.
|
46
|
+
#
|
47
|
+
# @param [String] format The format to use to format the time.
|
42
48
|
def datetime_format=(format)
|
43
49
|
if format == :milliseconds
|
44
50
|
format = MILLISECOND_TIME_FORMAT
|
@@ -48,11 +54,17 @@ module Lumberjack
|
|
48
54
|
@time_formatter = Formatter::DateTimeFormatter.new(format)
|
49
55
|
end
|
50
56
|
|
57
|
+
# Get the format used to format the time.
|
58
|
+
#
|
59
|
+
# @return [String]
|
51
60
|
def datetime_format
|
52
61
|
@time_formatter.format
|
53
62
|
end
|
54
63
|
|
55
64
|
# Convert an entry into a string using the template.
|
65
|
+
#
|
66
|
+
# @param [Lumberjack::LogEntry] entry The entry to convert to a string.
|
67
|
+
# @return [String] The entry converted to a string.
|
56
68
|
def call(entry)
|
57
69
|
return entry unless entry.is_a?(LogEntry)
|
58
70
|
|
@@ -103,7 +115,7 @@ module Lumberjack
|
|
103
115
|
end
|
104
116
|
|
105
117
|
# Compile the template string into a value that can be used with sprintf.
|
106
|
-
def compile(template)
|
118
|
+
def compile(template) # :nodoc:
|
107
119
|
tag_vars = []
|
108
120
|
template = template.gsub(PLACEHOLDER_PATTERN) do |match|
|
109
121
|
var_name = match.sub("{", "").sub("}", "")
|
data/lib/lumberjack.rb
CHANGED
@@ -6,7 +6,7 @@ require "securerandom"
|
|
6
6
|
require "logger"
|
7
7
|
|
8
8
|
module Lumberjack
|
9
|
-
LINE_SEPARATOR = (RbConfig::CONFIG["host_os"] =~ /mswin/i ? "\r\n" : "\n")
|
9
|
+
LINE_SEPARATOR = ((RbConfig::CONFIG["host_os"] =~ /mswin/i) ? "\r\n" : "\n")
|
10
10
|
|
11
11
|
require_relative "lumberjack/severity"
|
12
12
|
require_relative "lumberjack/formatter"
|
@@ -32,6 +32,9 @@ module Lumberjack
|
|
32
32
|
#
|
33
33
|
# For the common use case of treating a single web request as a unit of work, see the
|
34
34
|
# Lumberjack::Rack::UnitOfWork class.
|
35
|
+
#
|
36
|
+
# @param [String] id The id for the unit of work.
|
37
|
+
# @return [void]
|
35
38
|
def unit_of_work(id = nil)
|
36
39
|
id ||= SecureRandom.hex(6)
|
37
40
|
context do
|
@@ -41,6 +44,8 @@ module Lumberjack
|
|
41
44
|
end
|
42
45
|
|
43
46
|
# Get the UniqueIdentifier for the current unit of work.
|
47
|
+
#
|
48
|
+
# @return [String, nil] The id for the current unit of work.
|
44
49
|
def unit_of_work_id
|
45
50
|
context[:unit_of_work_id]
|
46
51
|
end
|
@@ -53,6 +58,8 @@ module Lumberjack
|
|
53
58
|
#
|
54
59
|
# Otherwise, it will return the current context. If one doesn't exist, it will return a new one
|
55
60
|
# but that context will not be in any scope.
|
61
|
+
#
|
62
|
+
# @return [Lumberjack::Context] The current context if called without a block.
|
56
63
|
def context(&block)
|
57
64
|
current_context = Thread.current[:lumberjack_context]
|
58
65
|
if block
|
@@ -63,6 +70,9 @@ module Lumberjack
|
|
63
70
|
end
|
64
71
|
|
65
72
|
# Set the context to use within a block.
|
73
|
+
#
|
74
|
+
# @param [Lumberjack::Context] context The context to use within the block.
|
75
|
+
# @return [Object] The result of the block.
|
66
76
|
def use_context(context, &block)
|
67
77
|
current_context = Thread.current[:lumberjack_context]
|
68
78
|
begin
|
@@ -74,17 +84,24 @@ module Lumberjack
|
|
74
84
|
end
|
75
85
|
|
76
86
|
# Return true if inside a context block.
|
87
|
+
#
|
88
|
+
# @return [Boolean]
|
77
89
|
def context?
|
78
90
|
!!Thread.current[:lumberjack_context]
|
79
91
|
end
|
80
92
|
|
81
93
|
# Return the tags from the current context or nil if there are no tags.
|
94
|
+
#
|
95
|
+
# @return [Hash, nil]
|
82
96
|
def context_tags
|
83
97
|
context = Thread.current[:lumberjack_context]
|
84
98
|
context&.tags
|
85
99
|
end
|
86
100
|
|
87
101
|
# Set tags on the current context
|
102
|
+
#
|
103
|
+
# @param [Hash] tags The tags to set.
|
104
|
+
# @return [void]
|
88
105
|
def tag(tags)
|
89
106
|
context = Thread.current[:lumberjack_context]
|
90
107
|
context&.tag(tags)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lumberjack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Durand
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email:
|
29
29
|
- bbdurand@gmail.com
|
30
30
|
executables: []
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- lib/lumberjack/formatter/string_formatter.rb
|
56
56
|
- lib/lumberjack/formatter/strip_formatter.rb
|
57
57
|
- lib/lumberjack/formatter/structured_formatter.rb
|
58
|
+
- lib/lumberjack/formatter/truncate_formatter.rb
|
58
59
|
- lib/lumberjack/log_entry.rb
|
59
60
|
- lib/lumberjack/logger.rb
|
60
61
|
- lib/lumberjack/rack.rb
|
@@ -72,7 +73,7 @@ homepage: https://github.com/bdurand/lumberjack
|
|
72
73
|
licenses:
|
73
74
|
- MIT
|
74
75
|
metadata: {}
|
75
|
-
post_install_message:
|
76
|
+
post_install_message:
|
76
77
|
rdoc_options: []
|
77
78
|
require_paths:
|
78
79
|
- lib
|
@@ -87,8 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
88
|
- !ruby/object:Gem::Version
|
88
89
|
version: '0'
|
89
90
|
requirements: []
|
90
|
-
rubygems_version: 3.
|
91
|
-
signing_key:
|
91
|
+
rubygems_version: 3.4.12
|
92
|
+
signing_key:
|
92
93
|
specification_version: 4
|
93
94
|
summary: A simple, powerful, and very fast logging utility that can be a drop in replacement
|
94
95
|
for Logger or ActiveSupport::BufferedLogger.
|