logging_library 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +1 -0
- data/README.md +7 -0
- data/lib/logging_library/custom_formatter.rb +22 -11
- data/lib/logging_library/version.rb +1 -1
- data/logging_library.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e3cd0d59c85aef389748fadbeb9177a21d6c70b2253c108296d7594f544b2d3e
|
4
|
+
data.tar.gz: 8207d988ebe5845473d9c1bfded67fb1234e32c1473af1ab62b05294e382132b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f36d5f6aa5825a984da554389e7552f21eedc43c06d7bec64d9de6296433322d9382b666aac1369bdb5dde8022fa7d8a1abb2b650c38cec59f1a7079073afdd
|
7
|
+
data.tar.gz: 179c7018a4f584523841b5bc25862901859d78aed3525f47473c7cb2c04c693662629299b82ff571452158faf5701a1db54eaac5b7e83c9b5be790aad548486a
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -51,6 +51,13 @@ class MyClass
|
|
51
51
|
end
|
52
52
|
```
|
53
53
|
|
54
|
+
## Environment variables
|
55
|
+
|
56
|
+
- `LOGGING_LIBRARY_DISABLE_TIMESTAMPS` - set this to any value to disable
|
57
|
+
timestamping which is otherwise performed on log entries when running in
|
58
|
+
interactive/TTY mode. This setting can be useful in scenarios where you
|
59
|
+
would otherwise get double timestamps on each line.
|
60
|
+
|
54
61
|
## Development
|
55
62
|
|
56
63
|
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
@@ -9,8 +9,6 @@ module LoggingLibrary
|
|
9
9
|
DATE_PATTERN = '%Y-%m-%d %H:%M:%S.%L'.freeze
|
10
10
|
|
11
11
|
LogMessage = Struct.new(:severity, :time, :logger_name, :message) do
|
12
|
-
LINE_PREPEND = ' ' * 8
|
13
|
-
|
14
12
|
def to_formatted_string
|
15
13
|
if show_time?
|
16
14
|
format("%s %s %s %s\n", formatted_colored_severity, formatted_colored_time,
|
@@ -20,14 +18,20 @@ module LoggingLibrary
|
|
20
18
|
end
|
21
19
|
end
|
22
20
|
|
21
|
+
private
|
22
|
+
|
23
|
+
LINE_PREPEND = ' ' * 8
|
24
|
+
|
23
25
|
def colored_message
|
24
26
|
return formatted_message unless Rainbow.enabled
|
25
27
|
Rainbow(formatted_message).color(text_color_for_severity)
|
26
28
|
end
|
27
29
|
|
28
|
-
# Converts some argument to a Logger.severity() call to a string.
|
29
|
-
# normal, Exceptions get formatted as
|
30
|
-
# put through
|
30
|
+
# Converts some argument to a Logger.severity() call to a string.
|
31
|
+
# Regular strings pass through like normal, Exceptions get formatted as
|
32
|
+
# "message (class)\nbacktrace", and other random stuff gets put through
|
33
|
+
# "object.inspect"
|
34
|
+
|
31
35
|
def formatted_message
|
32
36
|
case message
|
33
37
|
when ::String
|
@@ -53,7 +57,7 @@ module LoggingLibrary
|
|
53
57
|
if Rainbow.enabled
|
54
58
|
Rainbow(formatted_time).color(time_color_for_severity)
|
55
59
|
else
|
56
|
-
|
60
|
+
formatted_time
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
@@ -94,7 +98,8 @@ module LoggingLibrary
|
|
94
98
|
end
|
95
99
|
end
|
96
100
|
|
97
|
-
# Returns a somewhat lighter color for the time, to make it stand out
|
101
|
+
# Returns a somewhat lighter color for the time, to make it stand out
|
102
|
+
# in the presentation.
|
98
103
|
def time_color_for_severity
|
99
104
|
case severity.downcase.to_sym
|
100
105
|
when :fatal then '#FF00FF'
|
@@ -106,13 +111,19 @@ module LoggingLibrary
|
|
106
111
|
end
|
107
112
|
end
|
108
113
|
|
109
|
-
# We want "something" to stand out. If time isn't being shown, we
|
114
|
+
# We want "something" to stand out. If time isn't being shown, we
|
115
|
+
# utilize its color for displaying the severity.
|
110
116
|
alias_method :color_for_severity_lighter, :time_color_for_severity
|
111
117
|
|
112
118
|
def show_time?
|
113
|
-
# When STDERR is redirected, we are likely running as a service with a
|
114
|
-
# line (and two
|
115
|
-
|
119
|
+
# When STDERR is redirected, we are likely running as a service with a
|
120
|
+
# syslog daemon already appending a timestamp to the line (and two
|
121
|
+
# timestamps is redundant).
|
122
|
+
tty? && !disable_timestamps?
|
123
|
+
end
|
124
|
+
|
125
|
+
def disable_timestamps?
|
126
|
+
ENV['LOGGING_LIBRARY_DISABLE_TIMESTAMPS']
|
116
127
|
end
|
117
128
|
|
118
129
|
def tty?
|
data/logging_library.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_runtime_dependency 'rainbow', '>= 2.2'
|
27
27
|
|
28
28
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
29
|
-
spec.add_development_dependency 'rake', '~>
|
29
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
30
30
|
spec.add_development_dependency 'rspec', '~> 3.5'
|
31
31
|
spec.add_development_dependency 'rubocop', '~> 0.50', '< 0.51'
|
32
32
|
spec.add_development_dependency 'yard', '~> 0.9'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logging_library
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tre Kronor
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-log
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '12.3'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '12.3'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
163
|
version: '0'
|
164
164
|
requirements: []
|
165
165
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.6
|
166
|
+
rubygems_version: 2.7.6
|
167
167
|
signing_key:
|
168
168
|
specification_version: 4
|
169
169
|
summary: Logging library
|