lumberjack 1.2.7 → 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 +114 -56
- data/README.md +6 -5
- data/VERSION +1 -1
- data/lib/lumberjack/context.rb +13 -0
- data/lib/lumberjack/device/date_rolling_log_file.rb +16 -7
- data/lib/lumberjack/device/log_file.rb +13 -6
- data/lib/lumberjack/device/multi.rb +7 -6
- data/lib/lumberjack/device/null.rb +1 -1
- data/lib/lumberjack/device/rolling_log_file.rb +44 -20
- data/lib/lumberjack/device/size_rolling_log_file.rb +9 -9
- data/lib/lumberjack/device/writer.rb +32 -12
- data/lib/lumberjack/device.rb +27 -12
- data/lib/lumberjack/formatter/date_time_formatter.rb +3 -3
- data/lib/lumberjack/formatter/exception_formatter.rb +2 -2
- data/lib/lumberjack/formatter/id_formatter.rb +3 -2
- data/lib/lumberjack/formatter/pretty_print_formatter.rb +6 -4
- data/lib/lumberjack/formatter/structured_formatter.rb +2 -0
- data/lib/lumberjack/formatter/truncate_formatter.rb +27 -0
- data/lib/lumberjack/formatter.rb +69 -23
- data/lib/lumberjack/log_entry.rb +16 -10
- data/lib/lumberjack/logger.rb +167 -29
- data/lib/lumberjack/rack/request_id.rb +1 -1
- data/lib/lumberjack/rack/unit_of_work.rb +1 -1
- data/lib/lumberjack/rack.rb +3 -3
- data/lib/lumberjack/severity.rb +9 -2
- data/lib/lumberjack/tag_formatter.rb +20 -3
- data/lib/lumberjack/tagged_logger_support.rb +1 -2
- data/lib/lumberjack/tagged_logging.rb +1 -1
- data/lib/lumberjack/tags.rb +7 -1
- data/lib/lumberjack/template.rb +15 -3
- data/lib/lumberjack.rb +51 -30
- data/lumberjack.gemspec +11 -14
- metadata +9 -50
data/lib/lumberjack/template.rb
CHANGED
@@ -14,7 +14,7 @@ module Lumberjack
|
|
14
14
|
# If your tag name contains characters other than alpha numerics and the underscore, you must surround it
|
15
15
|
# with curly brackets: `:{http.request-id}`.
|
16
16
|
class Template
|
17
|
-
TEMPLATE_ARGUMENT_ORDER = %w
|
17
|
+
TEMPLATE_ARGUMENT_ORDER = %w[:time :severity :progname :pid :message :tags].freeze
|
18
18
|
MILLISECOND_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%3N"
|
19
19
|
MICROSECOND_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%6N"
|
20
20
|
PLACEHOLDER_PATTERN = /:(([a-z0-9_]+)|({[^}]+}))/i.freeze
|
@@ -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
|
|
@@ -86,7 +98,7 @@ module Lumberjack
|
|
86
98
|
def tag_args(tags, tag_vars)
|
87
99
|
return [nil] * (tag_vars.size + 1) if tags.nil? || tags.size == 0
|
88
100
|
|
89
|
-
tags_string =
|
101
|
+
tags_string = ""
|
90
102
|
tags.each do |name, value|
|
91
103
|
unless value.nil? || tag_vars.include?(name)
|
92
104
|
value = value.to_s
|
@@ -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
@@ -1,27 +1,26 @@
|
|
1
1
|
# frozen_string_literals: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require 'logger'
|
3
|
+
require "rbconfig"
|
4
|
+
require "time"
|
5
|
+
require "securerandom"
|
6
|
+
require "logger"
|
8
7
|
|
9
8
|
module Lumberjack
|
10
|
-
LINE_SEPARATOR = (RbConfig::CONFIG[
|
9
|
+
LINE_SEPARATOR = ((RbConfig::CONFIG["host_os"] =~ /mswin/i) ? "\r\n" : "\n")
|
11
10
|
|
12
|
-
require_relative "lumberjack/severity
|
13
|
-
require_relative "lumberjack/formatter
|
11
|
+
require_relative "lumberjack/severity"
|
12
|
+
require_relative "lumberjack/formatter"
|
14
13
|
|
15
|
-
require_relative "lumberjack/context
|
16
|
-
require_relative "lumberjack/log_entry
|
17
|
-
require_relative "lumberjack/device
|
18
|
-
require_relative "lumberjack/logger
|
19
|
-
require_relative "lumberjack/tags
|
20
|
-
require_relative "lumberjack/tag_formatter
|
21
|
-
require_relative "lumberjack/tagged_logger_support
|
22
|
-
require_relative "lumberjack/tagged_logging
|
23
|
-
require_relative "lumberjack/template
|
24
|
-
require_relative "lumberjack/rack
|
14
|
+
require_relative "lumberjack/context"
|
15
|
+
require_relative "lumberjack/log_entry"
|
16
|
+
require_relative "lumberjack/device"
|
17
|
+
require_relative "lumberjack/logger"
|
18
|
+
require_relative "lumberjack/tags"
|
19
|
+
require_relative "lumberjack/tag_formatter"
|
20
|
+
require_relative "lumberjack/tagged_logger_support"
|
21
|
+
require_relative "lumberjack/tagged_logging"
|
22
|
+
require_relative "lumberjack/template"
|
23
|
+
require_relative "lumberjack/rack"
|
25
24
|
|
26
25
|
class << self
|
27
26
|
# Define a unit of work within a block. Within the block supplied to this
|
@@ -33,6 +32,9 @@ module Lumberjack
|
|
33
32
|
#
|
34
33
|
# For the common use case of treating a single web request as a unit of work, see the
|
35
34
|
# Lumberjack::Rack::UnitOfWork class.
|
35
|
+
#
|
36
|
+
# @param [String] id The id for the unit of work.
|
37
|
+
# @return [void]
|
36
38
|
def unit_of_work(id = nil)
|
37
39
|
id ||= SecureRandom.hex(6)
|
38
40
|
context do
|
@@ -42,6 +44,8 @@ module Lumberjack
|
|
42
44
|
end
|
43
45
|
|
44
46
|
# Get the UniqueIdentifier for the current unit of work.
|
47
|
+
#
|
48
|
+
# @return [String, nil] The id for the current unit of work.
|
45
49
|
def unit_of_work_id
|
46
50
|
context[:unit_of_work_id]
|
47
51
|
end
|
@@ -54,36 +58,53 @@ module Lumberjack
|
|
54
58
|
#
|
55
59
|
# Otherwise, it will return the current context. If one doesn't exist, it will return a new one
|
56
60
|
# but that context will not be in any scope.
|
57
|
-
|
61
|
+
#
|
62
|
+
# @return [Lumberjack::Context] The current context if called without a block.
|
63
|
+
def context(&block)
|
58
64
|
current_context = Thread.current[:lumberjack_context]
|
59
|
-
if
|
60
|
-
|
61
|
-
begin
|
62
|
-
yield
|
63
|
-
ensure
|
64
|
-
Thread.current[:lumberjack_context] = current_context
|
65
|
-
end
|
65
|
+
if block
|
66
|
+
use_context(Context.new(current_context), &block)
|
66
67
|
else
|
67
68
|
current_context || Context.new
|
68
69
|
end
|
69
70
|
end
|
70
|
-
|
71
|
+
|
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.
|
76
|
+
def use_context(context, &block)
|
77
|
+
current_context = Thread.current[:lumberjack_context]
|
78
|
+
begin
|
79
|
+
Thread.current[:lumberjack_context] = (context || Context.new)
|
80
|
+
yield
|
81
|
+
ensure
|
82
|
+
Thread.current[:lumberjack_context] = current_context
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
71
86
|
# Return true if inside a context block.
|
87
|
+
#
|
88
|
+
# @return [Boolean]
|
72
89
|
def context?
|
73
90
|
!!Thread.current[:lumberjack_context]
|
74
91
|
end
|
75
92
|
|
76
93
|
# Return the tags from the current context or nil if there are no tags.
|
94
|
+
#
|
95
|
+
# @return [Hash, nil]
|
77
96
|
def context_tags
|
78
97
|
context = Thread.current[:lumberjack_context]
|
79
|
-
context
|
98
|
+
context&.tags
|
80
99
|
end
|
81
100
|
|
82
101
|
# Set tags on the current context
|
102
|
+
#
|
103
|
+
# @param [Hash] tags The tags to set.
|
104
|
+
# @return [void]
|
83
105
|
def tag(tags)
|
84
106
|
context = Thread.current[:lumberjack_context]
|
85
|
-
context
|
107
|
+
context&.tag(tags)
|
86
108
|
end
|
87
|
-
|
88
109
|
end
|
89
110
|
end
|
data/lumberjack.gemspec
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
|
-
spec.name =
|
3
|
-
spec.version = File.read(File.
|
4
|
-
spec.authors = [
|
5
|
-
spec.email = [
|
2
|
+
spec.name = "lumberjack"
|
3
|
+
spec.version = File.read(File.join(__dir__, "VERSION")).strip
|
4
|
+
spec.authors = ["Brian Durand"]
|
5
|
+
spec.email = ["bbdurand@gmail.com"]
|
6
6
|
|
7
7
|
spec.summary = "A simple, powerful, and very fast logging utility that can be a drop in replacement for Logger or ActiveSupport::BufferedLogger."
|
8
8
|
spec.homepage = "https://github.com/bdurand/lumberjack"
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
|
11
11
|
# Specify which files should be added to the gem when it is released.
|
12
12
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
13
|
-
ignore_files = %w
|
13
|
+
ignore_files = %w[
|
14
14
|
.
|
15
15
|
Appraisals
|
16
16
|
Gemfile
|
@@ -18,17 +18,14 @@ Gem::Specification.new do |spec|
|
|
18
18
|
Rakefile
|
19
19
|
gemfiles/
|
20
20
|
spec/
|
21
|
-
|
22
|
-
spec.files = Dir.chdir(
|
23
|
-
`git ls-files -z`.split("\x0").reject{ |f| ignore_files.any?{ |path| f.start_with?(path) } }
|
21
|
+
]
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| ignore_files.any? { |path| f.start_with?(path) } }
|
24
24
|
end
|
25
25
|
|
26
|
-
spec.require_paths = [
|
26
|
+
spec.require_paths = ["lib"]
|
27
27
|
|
28
|
-
spec.required_ruby_version =
|
28
|
+
spec.required_ruby_version = ">= 2.3.0"
|
29
29
|
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency("timecop")
|
32
|
-
spec.add_development_dependency "rake"
|
33
|
-
spec.add_development_dependency "appraisal"
|
30
|
+
spec.add_development_dependency "bundler"
|
34
31
|
end
|
metadata
CHANGED
@@ -1,59 +1,17 @@
|
|
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
|
-
name:
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '3.0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '3.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: timecop
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: appraisal
|
14
|
+
name: bundler
|
57
15
|
requirement: !ruby/object:Gem::Requirement
|
58
16
|
requirements:
|
59
17
|
- - ">="
|
@@ -66,7 +24,7 @@ dependencies:
|
|
66
24
|
- - ">="
|
67
25
|
- !ruby/object:Gem::Version
|
68
26
|
version: '0'
|
69
|
-
description:
|
27
|
+
description:
|
70
28
|
email:
|
71
29
|
- bbdurand@gmail.com
|
72
30
|
executables: []
|
@@ -97,6 +55,7 @@ files:
|
|
97
55
|
- lib/lumberjack/formatter/string_formatter.rb
|
98
56
|
- lib/lumberjack/formatter/strip_formatter.rb
|
99
57
|
- lib/lumberjack/formatter/structured_formatter.rb
|
58
|
+
- lib/lumberjack/formatter/truncate_formatter.rb
|
100
59
|
- lib/lumberjack/log_entry.rb
|
101
60
|
- lib/lumberjack/logger.rb
|
102
61
|
- lib/lumberjack/rack.rb
|
@@ -114,7 +73,7 @@ homepage: https://github.com/bdurand/lumberjack
|
|
114
73
|
licenses:
|
115
74
|
- MIT
|
116
75
|
metadata: {}
|
117
|
-
post_install_message:
|
76
|
+
post_install_message:
|
118
77
|
rdoc_options: []
|
119
78
|
require_paths:
|
120
79
|
- lib
|
@@ -129,8 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
88
|
- !ruby/object:Gem::Version
|
130
89
|
version: '0'
|
131
90
|
requirements: []
|
132
|
-
rubygems_version: 3.
|
133
|
-
signing_key:
|
91
|
+
rubygems_version: 3.4.12
|
92
|
+
signing_key:
|
134
93
|
specification_version: 4
|
135
94
|
summary: A simple, powerful, and very fast logging utility that can be a drop in replacement
|
136
95
|
for Logger or ActiveSupport::BufferedLogger.
|