lumberjack 1.2.7 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -11
- data/README.md +4 -3
- data/VERSION +1 -1
- data/lib/lumberjack.rb +34 -30
- data/lib/lumberjack/device.rb +12 -12
- data/lib/lumberjack/device/date_rolling_log_file.rb +7 -7
- data/lib/lumberjack/device/log_file.rb +6 -6
- data/lib/lumberjack/device/multi.rb +6 -6
- data/lib/lumberjack/device/null.rb +1 -1
- data/lib/lumberjack/device/rolling_log_file.rb +43 -19
- data/lib/lumberjack/device/size_rolling_log_file.rb +9 -9
- data/lib/lumberjack/device/writer.rb +12 -12
- data/lib/lumberjack/formatter.rb +15 -15
- data/lib/lumberjack/formatter/date_time_formatter.rb +2 -3
- data/lib/lumberjack/formatter/exception_formatter.rb +0 -2
- data/lib/lumberjack/formatter/id_formatter.rb +2 -2
- data/lib/lumberjack/formatter/pretty_print_formatter.rb +4 -4
- data/lib/lumberjack/log_entry.rb +8 -10
- data/lib/lumberjack/logger.rb +42 -23
- data/lib/lumberjack/rack.rb +3 -3
- data/lib/lumberjack/rack/request_id.rb +1 -1
- data/lib/lumberjack/rack/unit_of_work.rb +1 -1
- data/lib/lumberjack/severity.rb +1 -2
- data/lib/lumberjack/tag_formatter.rb +1 -3
- data/lib/lumberjack/tagged_logger_support.rb +0 -1
- data/lib/lumberjack/tagged_logging.rb +1 -1
- data/lib/lumberjack/tags.rb +1 -1
- data/lib/lumberjack/template.rb +2 -2
- data/lumberjack.gemspec +11 -14
- metadata +3 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7912cf1bfe32dcaa911a6a65a0b755fb3051eebc2a7e4a65ff5d422f2f61ad7
|
4
|
+
data.tar.gz: b4077d2ef97be7169ed0e7bca7d107ec3f42372dde45cae1e7cdcedae1fb4e61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a092775aec0c7670eda8ff4959a7cc928a57b0934ecc8a1190efe395b437bc0a681bdbd2f3455b98f3cf757904f5f39b31c96e24e9c8bcd7a481b806027e92c8
|
7
|
+
data.tar.gz: 885f76da2738f3f6236a363d9a7dea68f83a80a03e123a3c52c578984f963e959de6fd60d0fd222d9a9933c22ed959181538abb4118163c8fd6528292e88673c
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
+
## 1.2.8
|
2
|
+
|
3
|
+
* Add `Logger#untagged` to remove previously set logging tags from a block.
|
4
|
+
* Return result of the block when a block is passed to `Logger#tag`.
|
5
|
+
|
1
6
|
## 1.2.7
|
2
7
|
|
3
|
-
* Allow passing frozen hashes to `Logger
|
8
|
+
* Allow passing frozen hashes to `Logger#tag`. Tags passed to this method are now duplicated so the logger maintains it's own copy of the hash.
|
4
9
|
|
5
10
|
## 1.2.6
|
6
11
|
|
7
|
-
* Fix Logger#tag so it only ads to the current block's logger tags instead of the global tags if called inside a `Logger#tag` block.
|
12
|
+
* Fix `Logger#tag` so it only ads to the current block's logger tags instead of the global tags if called inside a `Logger#tag` block.
|
8
13
|
* Add Logger#remove_tag
|
9
14
|
|
10
15
|
## 1.2.5
|
@@ -14,7 +19,7 @@
|
|
14
19
|
|
15
20
|
## 1.2.4
|
16
21
|
|
17
|
-
* Enhance ActiveSupport::TaggedLogging support so code that Lumberjack loggers can be wrapped with a tagged logger.
|
22
|
+
* Enhance `ActiveSupport::TaggedLogging` support so code that Lumberjack loggers can be wrapped with a tagged logger.
|
18
23
|
|
19
24
|
## 1.2.3
|
20
25
|
|
@@ -30,7 +35,7 @@
|
|
30
35
|
|
31
36
|
## 1.2.0
|
32
37
|
|
33
|
-
* Enable compatibility with ActiveSupport::TaggedLogger by calling `tagged_logger!` on a logger.
|
38
|
+
* Enable compatibility with `ActiveSupport::TaggedLogger` by calling `tagged_logger!` on a logger.
|
34
39
|
* Add `tag_formatter` to logger to specify formatting of tags for output.
|
35
40
|
* Allow adding and removing classes by name to formatters.
|
36
41
|
* Allow adding and removing multiple classes in a single call to a formatter.
|
@@ -49,7 +54,7 @@
|
|
49
54
|
|
50
55
|
## 1.1.0
|
51
56
|
|
52
|
-
* Change Lumberjack::Logger to inherit from ::Logger
|
57
|
+
* Change `Lumberjack::Logger` to inherit from ::Logger
|
53
58
|
* Add support for tags on log messages
|
54
59
|
* Add global tag context for all loggers
|
55
60
|
* Add per logger tags and tag contexts
|
@@ -57,8 +62,8 @@
|
|
57
62
|
* Add support for setting datetime format on log devices
|
58
63
|
* Performance optimizations
|
59
64
|
* Add Multi device to output to multiple devices
|
60
|
-
* Add DateTimeFormatter
|
61
|
-
* Add rack Context middleware for setting thread global context
|
65
|
+
* Add `DateTimeFormatter`, `IdFormatter`, `ObjectFormatter`, and `StructuredFormatter`
|
66
|
+
* Add rack `Context` middleware for setting thread global context
|
62
67
|
* End support for ruby versions < 2.3
|
63
68
|
* Add support for modules in formatters
|
64
69
|
|
@@ -70,7 +75,7 @@
|
|
70
75
|
|
71
76
|
## 1.0.12
|
72
77
|
|
73
|
-
* Add support for ActionDispatch request id for better Rails compatibility.
|
78
|
+
* Add support for `ActionDispatch` request id for better Rails compatibility.
|
74
79
|
|
75
80
|
## 1.0.11
|
76
81
|
|
@@ -84,11 +89,11 @@
|
|
84
89
|
|
85
90
|
## 1.0.9
|
86
91
|
|
87
|
-
* Add method so Formatter is compatible with ActiveSupport logging extensions.
|
92
|
+
* Add method so Formatter is compatible with `ActiveSupport` logging extensions.
|
88
93
|
|
89
94
|
## 1.0.8
|
90
95
|
|
91
|
-
* Fix another internal variable name conflict with ActiveSupport logging extensions.
|
96
|
+
* Fix another internal variable name conflict with `ActiveSupport` logging extensions.
|
92
97
|
|
93
98
|
## 1.0.7
|
94
99
|
|
@@ -96,7 +101,7 @@
|
|
96
101
|
|
97
102
|
## 1.0.6
|
98
103
|
|
99
|
-
* Fix internal variable name conflict with ActiveSupport logging extensions.
|
104
|
+
* Fix internal variable name conflict with `ActiveSupport` logging extensions.
|
100
105
|
|
101
106
|
## 1.0.5
|
102
107
|
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
[![Build Status](https://travis-ci.org/bdurand/lumberjack.svg?branch=master)](https://travis-ci.org/bdurand/lumberjack)
|
1
|
+
![Continuous Integration](https://github.com/bdurand/lumberjack/workflows/Continuous%20Integration/badge.svg)
|
4
2
|
[![Maintainability](https://api.codeclimate.com/v1/badges/a0abc03721fff9b0cde1/maintainability)](https://codeclimate.com/github/bdurand/lumberjack/maintainability)
|
3
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
|
4
|
+
|
5
|
+
# Lumberjack
|
5
6
|
|
6
7
|
Lumberjack is a simple, powerful, and fast logging implementation in Ruby. It uses nearly the same API as the Logger class in the Ruby standard library and as ActiveSupport::BufferedLogger in Rails.
|
7
8
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.8
|
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
|
@@ -54,20 +53,26 @@ module Lumberjack
|
|
54
53
|
#
|
55
54
|
# Otherwise, it will return the current context. If one doesn't exist, it will return a new one
|
56
55
|
# but that context will not be in any scope.
|
57
|
-
def context
|
56
|
+
def context(&block)
|
58
57
|
current_context = Thread.current[:lumberjack_context]
|
59
|
-
if
|
60
|
-
|
61
|
-
begin
|
62
|
-
yield
|
63
|
-
ensure
|
64
|
-
Thread.current[:lumberjack_context] = current_context
|
65
|
-
end
|
58
|
+
if block
|
59
|
+
use_context(Context.new(current_context), &block)
|
66
60
|
else
|
67
61
|
current_context || Context.new
|
68
62
|
end
|
69
63
|
end
|
70
|
-
|
64
|
+
|
65
|
+
# Set the context to use within a block.
|
66
|
+
def use_context(context, &block)
|
67
|
+
current_context = Thread.current[:lumberjack_context]
|
68
|
+
begin
|
69
|
+
Thread.current[:lumberjack_context] = (context || Context.new)
|
70
|
+
yield
|
71
|
+
ensure
|
72
|
+
Thread.current[:lumberjack_context] = current_context
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
71
76
|
# Return true if inside a context block.
|
72
77
|
def context?
|
73
78
|
!!Thread.current[:lumberjack_context]
|
@@ -76,14 +81,13 @@ module Lumberjack
|
|
76
81
|
# Return the tags from the current context or nil if there are no tags.
|
77
82
|
def context_tags
|
78
83
|
context = Thread.current[:lumberjack_context]
|
79
|
-
context
|
84
|
+
context&.tags
|
80
85
|
end
|
81
86
|
|
82
87
|
# Set tags on the current context
|
83
88
|
def tag(tags)
|
84
89
|
context = Thread.current[:lumberjack_context]
|
85
|
-
context
|
90
|
+
context&.tag(tags)
|
86
91
|
end
|
87
|
-
|
88
92
|
end
|
89
93
|
end
|
data/lib/lumberjack/device.rb
CHANGED
@@ -4,37 +4,37 @@ module Lumberjack
|
|
4
4
|
# This is an abstract class for logging devices. Subclasses must implement the +write+ method and
|
5
5
|
# may implement the +close+ and +flush+ methods if applicable.
|
6
6
|
class Device
|
7
|
-
require_relative "device/writer
|
8
|
-
require_relative "device/log_file
|
9
|
-
require_relative "device/rolling_log_file
|
10
|
-
require_relative "device/date_rolling_log_file
|
11
|
-
require_relative "device/size_rolling_log_file
|
12
|
-
require_relative "device/multi
|
13
|
-
require_relative "device/null
|
7
|
+
require_relative "device/writer"
|
8
|
+
require_relative "device/log_file"
|
9
|
+
require_relative "device/rolling_log_file"
|
10
|
+
require_relative "device/date_rolling_log_file"
|
11
|
+
require_relative "device/size_rolling_log_file"
|
12
|
+
require_relative "device/multi"
|
13
|
+
require_relative "device/null"
|
14
14
|
|
15
15
|
# Subclasses must implement this method to write a LogEntry.
|
16
16
|
def write(entry)
|
17
17
|
raise NotImplementedError
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
# Subclasses may implement this method to close the device.
|
21
21
|
def close
|
22
22
|
flush
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
# Subclasses may implement this method to reopen the device.
|
26
26
|
def reopen(logdev = nil)
|
27
27
|
flush
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
# Subclasses may implement this method to flush any buffers used by the device.
|
31
31
|
def flush
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
# Subclasses may implement this method to get the format for log timestamps.
|
35
35
|
def datetime_format
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
# Subclasses may implement this method to set a format for log timestamps.
|
39
39
|
def datetime_format=(format)
|
40
40
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literals: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "date"
|
4
4
|
|
5
5
|
module Lumberjack
|
6
6
|
class Device
|
@@ -16,7 +16,7 @@ module Lumberjack
|
|
16
16
|
def initialize(path, options = {})
|
17
17
|
@manual = options[:manual]
|
18
18
|
@file_date = Date.today
|
19
|
-
if options[:roll]
|
19
|
+
if options[:roll]&.to_s&.match(/(daily)|(weekly)|(monthly)/i)
|
20
20
|
@roll_period = $~[0].downcase.to_sym
|
21
21
|
options.delete(:roll)
|
22
22
|
else
|
@@ -28,11 +28,11 @@ module Lumberjack
|
|
28
28
|
def archive_file_suffix
|
29
29
|
case @roll_period
|
30
30
|
when :weekly
|
31
|
-
|
31
|
+
@file_date.strftime("week-of-%Y-%m-%d").to_s
|
32
32
|
when :monthly
|
33
|
-
|
33
|
+
@file_date.strftime("%Y-%m").to_s
|
34
34
|
else
|
35
|
-
|
35
|
+
@file_date.strftime("%Y-%m-%d").to_s
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -54,9 +54,9 @@ module Lumberjack
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
protected
|
59
|
-
|
59
|
+
|
60
60
|
def after_roll
|
61
61
|
@file_date = Date.today
|
62
62
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literals: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "fileutils"
|
4
4
|
|
5
5
|
module Lumberjack
|
6
6
|
class Device
|
@@ -10,23 +10,23 @@ module Lumberjack
|
|
10
10
|
|
11
11
|
# The absolute path of the file being logged to.
|
12
12
|
attr_reader :path
|
13
|
-
|
13
|
+
|
14
14
|
# Create a logger to the file at +path+. Options are passed through to the Writer constructor.
|
15
15
|
def initialize(path, options = {})
|
16
16
|
@path = File.expand_path(path)
|
17
17
|
FileUtils.mkdir_p(File.dirname(@path))
|
18
18
|
super(file_stream, options)
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def reopen(logdev = nil)
|
22
22
|
close
|
23
23
|
@stream = file_stream
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
private
|
27
|
-
|
27
|
+
|
28
28
|
def file_stream
|
29
|
-
File.new(@path,
|
29
|
+
File.new(@path, "a", encoding: EXTERNAL_ENCODING)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -7,35 +7,35 @@ module Lumberjack
|
|
7
7
|
def initialize(*devices)
|
8
8
|
@devices = devices.flatten
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def write(entry)
|
12
12
|
@devices.each do |device|
|
13
13
|
device.write(entry)
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def flush
|
18
18
|
@devices.each do |device|
|
19
19
|
device.flush
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def close
|
24
24
|
@devices.each do |device|
|
25
25
|
device.close
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def reopen(logdev = nil)
|
30
30
|
@devices.each do |device|
|
31
31
|
device.reopen(logdev = nil)
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def datetime_format
|
36
36
|
@devices.detect(&:datetime_format).datetime_format
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def datetime_format=(format)
|
40
40
|
@devices.each do |device|
|
41
41
|
device.datetime_format = format
|
@@ -14,35 +14,43 @@ module Lumberjack
|
|
14
14
|
class RollingLogFile < LogFile
|
15
15
|
attr_reader :path
|
16
16
|
attr_accessor :keep
|
17
|
-
|
17
|
+
|
18
18
|
def initialize(path, options = {})
|
19
19
|
@path = File.expand_path(path)
|
20
20
|
@keep = options[:keep]
|
21
21
|
super(path, options)
|
22
|
-
@file_inode =
|
22
|
+
@file_inode = begin
|
23
|
+
stream.lstat.ino
|
24
|
+
rescue
|
25
|
+
nil
|
26
|
+
end
|
23
27
|
@@rolls = []
|
24
28
|
@next_stat_check = Time.now.to_f
|
25
29
|
@min_roll_check = (options[:min_roll_check] || 1.0).to_f
|
26
30
|
end
|
27
|
-
|
31
|
+
|
28
32
|
# Returns a suffix that will be appended to the file name when it is archived.. The suffix should
|
29
33
|
# change after it is time to roll the file. The log file will be renamed when it is rolled.
|
30
34
|
def archive_file_suffix
|
31
35
|
raise NotImplementedError
|
32
36
|
end
|
33
|
-
|
37
|
+
|
34
38
|
# Return +true+ if the file should be rolled.
|
35
39
|
def roll_file?
|
36
40
|
raise NotImplementedError
|
37
41
|
end
|
38
|
-
|
42
|
+
|
39
43
|
# Roll the log file by renaming it to the archive file name and then re-opening a stream to the log
|
40
44
|
# file path. Rolling a file is safe in multi-threaded or multi-process environments.
|
41
45
|
def roll_file! #:nodoc:
|
42
46
|
do_once(stream) do
|
43
47
|
archive_file = "#{path}.#{archive_file_suffix}"
|
44
48
|
stream.flush
|
45
|
-
current_inode =
|
49
|
+
current_inode = begin
|
50
|
+
File.stat(path).ino
|
51
|
+
rescue
|
52
|
+
nil
|
53
|
+
end
|
46
54
|
if @file_inode && current_inode == @file_inode && !File.exist?(archive_file) && File.exist?(path)
|
47
55
|
begin
|
48
56
|
File.rename(path, archive_file)
|
@@ -59,41 +67,49 @@ module Lumberjack
|
|
59
67
|
end
|
60
68
|
|
61
69
|
protected
|
62
|
-
|
70
|
+
|
63
71
|
# This method will be called after a file has been rolled. Subclasses can
|
64
72
|
# implement code to reset the state of the device. This method is thread safe.
|
65
73
|
def after_roll
|
66
74
|
end
|
67
|
-
|
75
|
+
|
68
76
|
# Handle rolling the file before flushing.
|
69
77
|
def before_flush # :nodoc:
|
70
78
|
if @min_roll_check <= 0.0 || Time.now.to_f >= @next_stat_check
|
71
79
|
@next_stat_check += @min_roll_check
|
72
|
-
path_inode =
|
80
|
+
path_inode = begin
|
81
|
+
File.lstat(path).ino
|
82
|
+
rescue
|
83
|
+
nil
|
84
|
+
end
|
73
85
|
if path_inode != @file_inode
|
74
86
|
@file_inode = path_inode
|
75
87
|
reopen_file
|
76
|
-
|
77
|
-
roll_file!
|
88
|
+
elsif roll_file?
|
89
|
+
roll_file!
|
78
90
|
end
|
79
91
|
end
|
80
92
|
end
|
81
|
-
|
93
|
+
|
82
94
|
private
|
83
95
|
|
84
96
|
def reopen_file
|
85
97
|
old_stream = stream
|
86
|
-
new_stream = File.open(path,
|
98
|
+
new_stream = File.open(path, "a", encoding: EXTERNAL_ENCODING)
|
87
99
|
new_stream.sync = true if buffer_size > 0
|
88
|
-
@file_inode =
|
100
|
+
@file_inode = begin
|
101
|
+
new_stream.lstat.ino
|
102
|
+
rescue
|
103
|
+
nil
|
104
|
+
end
|
89
105
|
self.stream = new_stream
|
90
106
|
old_stream.close
|
91
107
|
end
|
92
108
|
end
|
93
|
-
|
109
|
+
|
94
110
|
def cleanup_files!
|
95
111
|
if keep
|
96
|
-
files = Dir.glob("#{path}.*").collect{|f| [f, File.ctime(f)]}.sort{|a,b| b.last <=> a.last}.collect{|a| a.first}
|
112
|
+
files = Dir.glob("#{path}.*").collect { |f| [f, File.ctime(f)] }.sort { |a, b| b.last <=> a.last }.collect { |a| a.first }
|
97
113
|
if files.size > keep
|
98
114
|
files[keep, files.length].each do |f|
|
99
115
|
File.delete(f)
|
@@ -101,7 +117,7 @@ module Lumberjack
|
|
101
117
|
end
|
102
118
|
end
|
103
119
|
end
|
104
|
-
|
120
|
+
|
105
121
|
def do_once(file)
|
106
122
|
begin
|
107
123
|
file.flock(File::LOCK_EX)
|
@@ -110,11 +126,19 @@ module Lumberjack
|
|
110
126
|
return
|
111
127
|
end
|
112
128
|
begin
|
113
|
-
verify =
|
129
|
+
verify = begin
|
130
|
+
file.lstat
|
131
|
+
rescue
|
132
|
+
nil
|
133
|
+
end
|
114
134
|
# Execute only if the file we locked is still the same one that needed to be rolled
|
115
135
|
yield if verify && verify.ino == @file_inode && verify.size > 0
|
116
136
|
ensure
|
117
|
-
|
137
|
+
begin
|
138
|
+
file.flock(File::LOCK_UN)
|
139
|
+
rescue
|
140
|
+
nil
|
141
|
+
end
|
118
142
|
end
|
119
143
|
end
|
120
144
|
end
|
@@ -8,30 +8,30 @@ module Lumberjack
|
|
8
8
|
# production.log.1, then production.log.2, etc.
|
9
9
|
class SizeRollingLogFile < RollingLogFile
|
10
10
|
attr_reader :max_size
|
11
|
-
|
11
|
+
|
12
12
|
# Create an new log device to the specified file. The maximum size of the log file is specified with
|
13
13
|
# the :max_size option. The unit can also be specified: "32K", "100M", "2G" are all valid.
|
14
14
|
def initialize(path, options = {})
|
15
15
|
@manual = options[:manual]
|
16
16
|
@max_size = options[:max_size]
|
17
17
|
if @max_size.is_a?(String)
|
18
|
-
if @max_size
|
18
|
+
if @max_size =~ /^(\d+(\.\d+)?)([KMG])?$/i
|
19
19
|
@max_size = $~[1].to_f
|
20
20
|
units = $~[3].to_s.upcase
|
21
21
|
case units
|
22
22
|
when "K"
|
23
23
|
@max_size *= 1024
|
24
24
|
when "M"
|
25
|
-
@max_size *= 1024
|
25
|
+
@max_size *= 1024**2
|
26
26
|
when "G"
|
27
|
-
@max_size *= 1024
|
27
|
+
@max_size *= 1024**3
|
28
28
|
end
|
29
29
|
@max_size = @max_size.round
|
30
30
|
else
|
31
31
|
raise ArgumentError.new("illegal value for :max_size (#{@max_size})")
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
super
|
36
36
|
end
|
37
37
|
|
@@ -44,15 +44,15 @@ module Lumberjack
|
|
44
44
|
rescue SystemCallError
|
45
45
|
false
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
protected
|
49
|
-
|
49
|
+
|
50
50
|
# Calculate the next archive file name extension.
|
51
51
|
def next_archive_number # :nodoc:
|
52
52
|
max = 0
|
53
53
|
Dir.glob("#{path}.*").each do |filename|
|
54
|
-
if
|
55
|
-
suffix = filename.split(
|
54
|
+
if /\.\d+\z/ =~ filename
|
55
|
+
suffix = filename.split(".").last.to_i
|
56
56
|
max = suffix if suffix > max
|
57
57
|
end
|
58
58
|
end
|
@@ -71,7 +71,7 @@ module Lumberjack
|
|
71
71
|
@template = template
|
72
72
|
else
|
73
73
|
additional_lines = (options[:additional_lines] || DEFAULT_ADDITIONAL_LINES_TEMPLATE)
|
74
|
-
@template = Template.new(template, :
|
74
|
+
@template = Template.new(template, additional_lines: additional_lines, time_format: options[:time_format])
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -133,14 +133,10 @@ module Lumberjack
|
|
133
133
|
protected
|
134
134
|
|
135
135
|
# Set the underlying stream.
|
136
|
-
|
137
|
-
@stream = stream
|
138
|
-
end
|
136
|
+
attr_writer :stream
|
139
137
|
|
140
138
|
# Get the underlying stream.
|
141
|
-
|
142
|
-
@stream
|
143
|
-
end
|
139
|
+
attr_reader :stream
|
144
140
|
|
145
141
|
private
|
146
142
|
|
@@ -149,10 +145,10 @@ module Lumberjack
|
|
149
145
|
lines = lines.first if lines.is_a?(Array) && lines.size == 1
|
150
146
|
|
151
147
|
out = nil
|
152
|
-
if lines.is_a?(Array)
|
153
|
-
|
148
|
+
out = if lines.is_a?(Array)
|
149
|
+
"#{lines.join(Lumberjack::LINE_SEPARATOR)}#{Lumberjack::LINE_SEPARATOR}"
|
154
150
|
else
|
155
|
-
|
151
|
+
"#{lines}#{Lumberjack::LINE_SEPARATOR}"
|
156
152
|
end
|
157
153
|
|
158
154
|
begin
|
@@ -170,9 +166,13 @@ module Lumberjack
|
|
170
166
|
end
|
171
167
|
end
|
172
168
|
end
|
173
|
-
|
169
|
+
begin
|
170
|
+
stream.flush
|
171
|
+
rescue
|
172
|
+
nil
|
173
|
+
end
|
174
174
|
rescue => e
|
175
|
-
$stderr.write("#{e.class.name}: #{e.message}#{
|
175
|
+
$stderr.write("#{e.class.name}: #{e.message}#{" at " + e.backtrace.first if e.backtrace}")
|
176
176
|
$stderr.write(out)
|
177
177
|
$stderr.flush
|
178
178
|
end
|
data/lib/lumberjack/formatter.rb
CHANGED
@@ -12,15 +12,15 @@ module Lumberjack
|
|
12
12
|
#
|
13
13
|
# Enumerable objects (including Hash and Array) will call the formatter recursively for each element.
|
14
14
|
class Formatter
|
15
|
-
require_relative "formatter/date_time_formatter
|
16
|
-
require_relative "formatter/exception_formatter
|
17
|
-
require_relative "formatter/id_formatter
|
18
|
-
require_relative "formatter/inspect_formatter
|
19
|
-
require_relative "formatter/object_formatter
|
20
|
-
require_relative "formatter/pretty_print_formatter
|
21
|
-
require_relative "formatter/string_formatter
|
22
|
-
require_relative "formatter/strip_formatter
|
23
|
-
require_relative "formatter/structured_formatter
|
15
|
+
require_relative "formatter/date_time_formatter"
|
16
|
+
require_relative "formatter/exception_formatter"
|
17
|
+
require_relative "formatter/id_formatter"
|
18
|
+
require_relative "formatter/inspect_formatter"
|
19
|
+
require_relative "formatter/object_formatter"
|
20
|
+
require_relative "formatter/pretty_print_formatter"
|
21
|
+
require_relative "formatter/string_formatter"
|
22
|
+
require_relative "formatter/strip_formatter"
|
23
|
+
require_relative "formatter/structured_formatter"
|
24
24
|
|
25
25
|
class << self
|
26
26
|
# Returns a new empty formatter with no mapping. For historical reasons, a formatter
|
@@ -30,7 +30,7 @@ module Lumberjack
|
|
30
30
|
new.clear
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def initialize
|
35
35
|
@class_formatters = {}
|
36
36
|
@module_formatters = {}
|
@@ -72,10 +72,10 @@ module Lumberjack
|
|
72
72
|
remove(klass)
|
73
73
|
else
|
74
74
|
if formatter.is_a?(Symbol)
|
75
|
-
formatter_class_name = "#{formatter.to_s.gsub(/(^|_)([a-z])/){|m| $~[2].upcase}}Formatter"
|
75
|
+
formatter_class_name = "#{formatter.to_s.gsub(/(^|_)([a-z])/) { |m| $~[2].upcase }}Formatter"
|
76
76
|
formatter = Formatter.const_get(formatter_class_name).new
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
Array(klass).each do |k|
|
80
80
|
if k.class == Module
|
81
81
|
@module_formatters[k] = formatter
|
@@ -106,7 +106,7 @@ module Lumberjack
|
|
106
106
|
end
|
107
107
|
self
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
# Remove all formatters including the default formatter. Can be chained to add method calls.
|
111
111
|
def clear
|
112
112
|
@class_formatters.clear
|
@@ -117,7 +117,7 @@ module Lumberjack
|
|
117
117
|
# Format a message object as a string.
|
118
118
|
def format(message)
|
119
119
|
formatter = formatter_for(message.class)
|
120
|
-
if formatter
|
120
|
+
if formatter&.respond_to?(:call)
|
121
121
|
formatter.call(message)
|
122
122
|
else
|
123
123
|
message
|
@@ -135,7 +135,7 @@ module Lumberjack
|
|
135
135
|
# Find the formatter for a class by looking it up using the class hierarchy.
|
136
136
|
def formatter_for(klass) #:nodoc:
|
137
137
|
check_modules = true
|
138
|
-
|
138
|
+
until klass.nil?
|
139
139
|
formatter = @class_formatters[klass.name]
|
140
140
|
return formatter if formatter
|
141
141
|
|
@@ -5,13 +5,12 @@ module Lumberjack
|
|
5
5
|
# Format a Date, Time, or DateTime object. If you don't specify a format in the constructor,
|
6
6
|
# it will use the ISO-8601 format.
|
7
7
|
class DateTimeFormatter
|
8
|
-
|
9
8
|
attr_reader :format
|
10
|
-
|
9
|
+
|
11
10
|
def initialize(format = nil)
|
12
11
|
@format = format.dup.to_s.freeze unless format.nil?
|
13
12
|
end
|
14
|
-
|
13
|
+
|
15
14
|
def call(obj)
|
16
15
|
if @format && obj.respond_to?(:strftime)
|
17
16
|
obj.strftime(@format)
|
@@ -7,7 +7,6 @@ module Lumberjack
|
|
7
7
|
# passed to this object and the returned array is what will be logged. You can
|
8
8
|
# use this to clean out superfluous lines.
|
9
9
|
class ExceptionFormatter
|
10
|
-
|
11
10
|
attr_accessor :backtrace_cleaner
|
12
11
|
|
13
12
|
def initialize(backtrace_cleaner = nil)
|
@@ -33,7 +32,6 @@ module Lumberjack
|
|
33
32
|
trace
|
34
33
|
end
|
35
34
|
end
|
36
|
-
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
@@ -9,11 +9,11 @@ module Lumberjack
|
|
9
9
|
def initialize(id_attribute = :id)
|
10
10
|
@id_attribute = id_attribute
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def call(obj)
|
14
14
|
if obj.respond_to?(@id_attribute)
|
15
15
|
id = obj.send(@id_attribute)
|
16
|
-
{
|
16
|
+
{"class" => obj.class.name, "id" => id}
|
17
17
|
else
|
18
18
|
obj.to_s
|
19
19
|
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
# frozen_string_literals: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "pp"
|
4
|
+
require "stringio"
|
5
5
|
|
6
6
|
module Lumberjack
|
7
7
|
class Formatter
|
8
8
|
# Format an object with it's pretty print method.
|
9
9
|
class PrettyPrintFormatter
|
10
10
|
attr_accessor :width
|
11
|
-
|
11
|
+
|
12
12
|
# Create a new formatter. The maximum width of the message can be specified with the width
|
13
13
|
# parameter (defaults to 79 characters).
|
14
14
|
def initialize(width = 79)
|
15
15
|
@width = width
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def call(obj)
|
19
19
|
s = StringIO.new
|
20
20
|
PP.pp(obj, s)
|
data/lib/lumberjack/log_entry.rb
CHANGED
@@ -17,10 +17,10 @@ module Lumberjack
|
|
17
17
|
@progname = progname
|
18
18
|
@pid = pid
|
19
19
|
# backward compatibility with 1.0 API where the last argument was the unit of work id
|
20
|
-
if tags.nil? || tags.is_a?(Hash)
|
21
|
-
|
20
|
+
@tags = if tags.nil? || tags.is_a?(Hash)
|
21
|
+
tags
|
22
22
|
else
|
23
|
-
|
23
|
+
{UNIT_OF_WORK_ID => tags}
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -29,7 +29,7 @@ module Lumberjack
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def to_s
|
32
|
-
"[#{time.strftime(TIME_FORMAT)}.#{(time.usec / 1000.0).round.to_s.rjust(3,
|
32
|
+
"[#{time.strftime(TIME_FORMAT)}.#{(time.usec / 1000.0).round.to_s.rjust(3, "0")} #{severity_label} #{progname}(#{pid})#{tags_to_s}] #{message}"
|
33
33
|
end
|
34
34
|
|
35
35
|
def inspect
|
@@ -46,10 +46,10 @@ module Lumberjack
|
|
46
46
|
if tags
|
47
47
|
tags[UNIT_OF_WORK_ID] = value
|
48
48
|
else
|
49
|
-
@tags = {
|
49
|
+
@tags = {UNIT_OF_WORK_ID => value}
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
# Return the tag with the specified name.
|
54
54
|
def tag(name)
|
55
55
|
tags[name.to_s] if tags
|
@@ -58,10 +58,8 @@ module Lumberjack
|
|
58
58
|
private
|
59
59
|
|
60
60
|
def tags_to_s
|
61
|
-
tags_string =
|
62
|
-
|
63
|
-
tags.each { |name, value| tags_string << " #{name}:#{value.inspect}" }
|
64
|
-
end
|
61
|
+
tags_string = ""
|
62
|
+
tags&.each { |name, value| tags_string << " #{name}:#{value.inspect}" }
|
65
63
|
tags_string
|
66
64
|
end
|
67
65
|
end
|
data/lib/lumberjack/logger.rb
CHANGED
@@ -63,7 +63,7 @@ module Lumberjack
|
|
63
63
|
# * :max_size - If the log device is a file path, it will be a Device::SizeRollingLogFile if this is set.
|
64
64
|
#
|
65
65
|
# All other options are passed to the device constuctor.
|
66
|
-
def initialize(device =
|
66
|
+
def initialize(device = $stdout, options = {})
|
67
67
|
options = options.dup
|
68
68
|
self.level = options.delete(:level) || INFO
|
69
69
|
self.progname = options.delete(:progname)
|
@@ -100,19 +100,19 @@ module Lumberjack
|
|
100
100
|
thread_local_value(:lumberjack_logger_level) || @level
|
101
101
|
end
|
102
102
|
|
103
|
-
|
103
|
+
alias sev_threshold level
|
104
104
|
|
105
105
|
# Set the log level using either an integer level like Logger::INFO or a label like
|
106
106
|
# :info or "info"
|
107
107
|
def level=(value)
|
108
|
-
if value.is_a?(Integer)
|
109
|
-
|
108
|
+
@level = if value.is_a?(Integer)
|
109
|
+
value
|
110
110
|
else
|
111
|
-
|
111
|
+
Severity.label_to_level(value)
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
|
115
|
+
alias sev_threshold= level=
|
116
116
|
|
117
117
|
# Set the Lumberjack::Formatter used to format objects for logging as messages.
|
118
118
|
def formatter=(value)
|
@@ -137,7 +137,7 @@ module Lumberjack
|
|
137
137
|
# in an array under the "tagged" tag. So calling `logger.tagged("foo", "bar")` will result
|
138
138
|
# in tags `{"tagged" => ["foo", "bar"]}`.
|
139
139
|
def tagged_logger!
|
140
|
-
|
140
|
+
extend(TaggedLoggerSupport)
|
141
141
|
self
|
142
142
|
end
|
143
143
|
|
@@ -173,10 +173,10 @@ module Lumberjack
|
|
173
173
|
if current_tags.empty?
|
174
174
|
tags = Tags.stringify_keys(tags) unless tags.nil?
|
175
175
|
else
|
176
|
-
if tags.nil?
|
177
|
-
|
176
|
+
tags = if tags.nil?
|
177
|
+
current_tags.dup
|
178
178
|
else
|
179
|
-
|
179
|
+
current_tags.merge(Tags.stringify_keys(tags))
|
180
180
|
end
|
181
181
|
end
|
182
182
|
tags = Tags.expand_runtime_values(tags)
|
@@ -203,7 +203,7 @@ module Lumberjack
|
|
203
203
|
add_entry(severity, message, progname)
|
204
204
|
end
|
205
205
|
|
206
|
-
|
206
|
+
alias log add
|
207
207
|
|
208
208
|
# Flush the logging device. Messages are not guaranteed to be written until this method is called.
|
209
209
|
def flush
|
@@ -325,7 +325,7 @@ module Lumberjack
|
|
325
325
|
def silence(temporary_level = ERROR, &block)
|
326
326
|
if silencer
|
327
327
|
unless temporary_level.is_a?(Integer)
|
328
|
-
temporary_level = Severity
|
328
|
+
temporary_level = Severity.label_to_level(temporary_level)
|
329
329
|
end
|
330
330
|
push_thread_local_value(:lumberjack_logger_level, temporary_level, &block)
|
331
331
|
else
|
@@ -361,10 +361,11 @@ module Lumberjack
|
|
361
361
|
push_thread_local_value(:lumberjack_logger_tags, merged_tags, &block)
|
362
362
|
elsif thread_tags
|
363
363
|
thread_tags.merge!(tags)
|
364
|
+
nil
|
364
365
|
else
|
365
366
|
@tags.merge!(tags)
|
367
|
+
nil
|
366
368
|
end
|
367
|
-
nil
|
368
369
|
end
|
369
370
|
|
370
371
|
# Remove a tag from the current tag context. If this is called inside a block to a
|
@@ -380,17 +381,35 @@ module Lumberjack
|
|
380
381
|
end
|
381
382
|
|
382
383
|
# Return all tags in scope on the logger including global tags set on the Lumberjack
|
383
|
-
# context, tags set on the logger, and tags set on the current block for the logger
|
384
|
+
# context, tags set on the logger, and tags set on the current block for the logger.
|
384
385
|
def tags
|
385
386
|
tags = {}
|
386
387
|
context_tags = Lumberjack.context_tags
|
387
388
|
tags.merge!(context_tags) if context_tags && !context_tags.empty?
|
388
|
-
tags.merge!(@tags) if !@tags.empty?
|
389
|
+
tags.merge!(@tags) if !@tags.empty? && !thread_local_value(:lumberjack_logger_untagged)
|
389
390
|
scope_tags = thread_local_value(:lumberjack_logger_tags)
|
390
391
|
tags.merge!(scope_tags) if scope_tags && !scope_tags.empty?
|
391
392
|
tags
|
392
393
|
end
|
393
394
|
|
395
|
+
# Remove all tags on the current logger and logging context within a block.
|
396
|
+
# You can still set new block scoped tags within theuntagged block and provide
|
397
|
+
# tags on individual log methods.
|
398
|
+
def untagged(&block)
|
399
|
+
Lumberjack.use_context(nil) do
|
400
|
+
scope_tags = thread_local_value(:lumberjack_logger_tags)
|
401
|
+
untagged = thread_local_value(:lumberjack_logger_untagged)
|
402
|
+
begin
|
403
|
+
set_thread_local_value(:lumberjack_logger_untagged, true)
|
404
|
+
set_thread_local_value(:lumberjack_logger_tags, nil)
|
405
|
+
tag({}, &block)
|
406
|
+
ensure
|
407
|
+
set_thread_local_value(:lumberjack_logger_untagged, untagged)
|
408
|
+
set_thread_local_value(:lumberjack_logger_tags, scope_tags)
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
394
413
|
private
|
395
414
|
|
396
415
|
# Dereference arguments to log calls so we can have methods with compatibility with ::Logger
|
@@ -473,12 +492,12 @@ module Lumberjack
|
|
473
492
|
end
|
474
493
|
|
475
494
|
def write_to_device(entry) #:nodoc:
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
495
|
+
device.write(entry)
|
496
|
+
rescue => e
|
497
|
+
# rubocop:disable Style/StderrPuts
|
498
|
+
$stderr.puts("#{e.class.name}: #{e.message}#{" at " + e.backtrace.first if e.backtrace}")
|
499
|
+
$stderr.puts(entry.to_s)
|
500
|
+
# rubocop:enable Style/StderrPuts
|
482
501
|
end
|
483
502
|
|
484
503
|
# Create a thread that will periodically call flush.
|
@@ -487,12 +506,12 @@ module Lumberjack
|
|
487
506
|
begin
|
488
507
|
logger = self
|
489
508
|
Thread.new do
|
490
|
-
|
509
|
+
until closed?
|
491
510
|
begin
|
492
511
|
sleep(flush_seconds)
|
493
512
|
logger.flush if Time.now - logger.last_flushed_at >= flush_seconds
|
494
513
|
rescue => e
|
495
|
-
|
514
|
+
warn("Error flushing log: #{e.inspect}")
|
496
515
|
end
|
497
516
|
end
|
498
517
|
end
|
data/lib/lumberjack/rack.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Lumberjack
|
4
4
|
module Rack
|
5
|
-
require_relative "rack/unit_of_work
|
6
|
-
require_relative "rack/request_id
|
7
|
-
require_relative "rack/context
|
5
|
+
require_relative "rack/unit_of_work"
|
6
|
+
require_relative "rack/request_id"
|
7
|
+
require_relative "rack/context"
|
8
8
|
end
|
9
9
|
end
|
@@ -16,7 +16,7 @@ module Lumberjack
|
|
16
16
|
def call(env)
|
17
17
|
request_id = env[REQUEST_ID]
|
18
18
|
if request_id && @abbreviated
|
19
|
-
request_id = request_id.split(
|
19
|
+
request_id = request_id.split("-", 2).first
|
20
20
|
end
|
21
21
|
Lumberjack.unit_of_work(request_id) do
|
22
22
|
@app.call(env)
|
data/lib/lumberjack/severity.rb
CHANGED
@@ -11,7 +11,7 @@ module Lumberjack
|
|
11
11
|
FATAL = ::Logger::Severity::FATAL
|
12
12
|
UNKNOWN = ::Logger::Severity::UNKNOWN
|
13
13
|
|
14
|
-
SEVERITY_LABELS = %w
|
14
|
+
SEVERITY_LABELS = %w[DEBUG INFO WARN ERROR FATAL UNKNOWN].freeze
|
15
15
|
|
16
16
|
class << self
|
17
17
|
def level_to_label(severity)
|
@@ -22,6 +22,5 @@ module Lumberjack
|
|
22
22
|
SEVERITY_LABELS.index(label.to_s.upcase) || UNKNOWN
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
26
25
|
end
|
27
26
|
end
|
@@ -9,7 +9,6 @@ module Lumberjack
|
|
9
9
|
# tag_formatter.add(["password", "email"]) { |value| "***" }
|
10
10
|
# tag_formatter.add("finished_at", Lumberjack::Formatter::DateTimeFormatter.new("%Y-%m-%dT%H:%m:%S%z"))
|
11
11
|
class TagFormatter
|
12
|
-
|
13
12
|
def initialize
|
14
13
|
@formatters = {}
|
15
14
|
@default_formatter = nil
|
@@ -87,12 +86,11 @@ module Lumberjack
|
|
87
86
|
if formatter.is_a?(TaggedLoggerSupport::Formatter)
|
88
87
|
formatter.__formatter
|
89
88
|
elsif formatter.is_a?(Symbol)
|
90
|
-
formatter_class_name = "#{formatter.to_s.gsub(/(^|_)([a-z])/){|m| $~[2].upcase}}Formatter"
|
89
|
+
formatter_class_name = "#{formatter.to_s.gsub(/(^|_)([a-z])/) { |m| $~[2].upcase }}Formatter"
|
91
90
|
Formatter.const_get(formatter_class_name).new
|
92
91
|
else
|
93
92
|
formatter
|
94
93
|
end
|
95
94
|
end
|
96
|
-
|
97
95
|
end
|
98
96
|
end
|
@@ -6,7 +6,6 @@ require "forwardable"
|
|
6
6
|
module Lumberjack
|
7
7
|
# Methods to make Lumberjack::Logger API compatible with ActiveSupport::TaggedLogger.
|
8
8
|
module TaggedLoggerSupport
|
9
|
-
|
10
9
|
class Formatter < DelegateClass(Lumberjack::Formatter)
|
11
10
|
extend Forwardable
|
12
11
|
def_delegators :@logger, :tagged, :push_tags, :pop_tags, :clear_tags!
|
data/lib/lumberjack/tags.rb
CHANGED
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
|
@@ -86,7 +86,7 @@ module Lumberjack
|
|
86
86
|
def tag_args(tags, tag_vars)
|
87
87
|
return [nil] * (tag_vars.size + 1) if tags.nil? || tags.size == 0
|
88
88
|
|
89
|
-
tags_string =
|
89
|
+
tags_string = ""
|
90
90
|
tags.each do |name, value|
|
91
91
|
unless value.nil? || tag_vars.include?(name)
|
92
92
|
value = value.to_s
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Durand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-31 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
|
- - ">="
|