logging_library 1.2.0 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a180478efd645334f23af3ad6fe082b0cdff87e0
4
- data.tar.gz: d8c163e97a4e2a8350668c89d613da36fbd19542
2
+ SHA256:
3
+ metadata.gz: e3cd0d59c85aef389748fadbeb9177a21d6c70b2253c108296d7594f544b2d3e
4
+ data.tar.gz: 8207d988ebe5845473d9c1bfded67fb1234e32c1473af1ab62b05294e382132b
5
5
  SHA512:
6
- metadata.gz: ebd24bbe90cd64a02236f9dda3d506ab9f5ac89b0c82b73b2741884f55a45b7b5d9ceb83b79546cea5e6e374f43921a07173fb48aab5d10232421e742f073d19
7
- data.tar.gz: 674d27b70e8fb64c82c2f3ab9d5e4a958f18572bbeb84e8aeb05013e35341efde0c69c987134a5323babeaf788b7a928d20d8ef0db0a90c6ea4623651c98c4de
6
+ metadata.gz: 1f36d5f6aa5825a984da554389e7552f21eedc43c06d7bec64d9de6296433322d9382b666aac1369bdb5dde8022fa7d8a1abb2b650c38cec59f1a7079073afdd
7
+ data.tar.gz: 179c7018a4f584523841b5bc25862901859d78aed3525f47473c7cb2c04c693662629299b82ff571452158faf5701a1db54eaac5b7e83c9b5be790aad548486a
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ bin/
@@ -2,5 +2,6 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.3.4
5
+ - 2.5
5
6
  before_install:
6
7
  - gem install bundler
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. Regular strings pass through like
29
- # normal, Exceptions get formatted as "message (class)\nbacktrace", and other random stuff gets
30
- # put through "object.inspect"
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
- formatted_severity
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 in the presentation.
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 utilize its color for displaying the severity.
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 syslog daemon already appending a timestamp to the
114
- # line (and two timestamps is redundant).
115
- tty?
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?
@@ -1,3 +1,3 @@
1
1
  module LoggingLibrary
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.3.0'.freeze
3
3
  end
@@ -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', '~> 10.5'
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.2.0
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: 2017-12-18 00:00:00.000000000 Z
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: '10.5'
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: '10.5'
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.14
166
+ rubygems_version: 2.7.6
167
167
  signing_key:
168
168
  specification_version: 4
169
169
  summary: Logging library