green_log 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3c301ce67ee757ddf2093b93fc973ff46ad005f2ea7e8da3e693ca01a6c7444
4
- data.tar.gz: 0ec5551c9554ec465acfd815f4a95514f8dbf48529427a0187d51b02657e2671
3
+ metadata.gz: e5b5433755b4109fd922e8b52ddb5548f197a138828440db5a34d3e36cbfef7a
4
+ data.tar.gz: 7662ef6e5b9ffa36b325ef0a35d024291063a5862824e98c026e0792a5d50947
5
5
  SHA512:
6
- metadata.gz: 889da34f831f8d7b95bb79343b6905f88d0ffde04a308773ec6775ed70f2b7ffd8668f7eb9c0c8b6ec5fc4d7a2ffbbc6ff59ccecbbdac34fec6ac598c35bba0b
7
- data.tar.gz: f72a8e18d791b8d57a6a413d40c870c7dfb3b34414dc6e00862972acf927ef34d3520676cc973f2fdb7c29f0d92b9d15a69fed230d257b8f19c069b9f8523e7e
6
+ metadata.gz: ba12d366ae1cad087af69a2f237657f5f25671dce6f9c0ad91394afa63ec0b6f537906f022dabc8e5bf00c973504f4353c9500e4d80481eec530eb58c930f905
7
+ data.tar.gz: 640bd883b9b8acb70d338e67d7c891f816a9763e73fe19e249c7de52c642fb56067bc31c9769a4a154f35bf64752cee7e5150893c23a5c2520f17ed564192beb
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # GreenLog
2
2
 
3
- ![](https://github.com/greensync/green_log/workflows/CI/badge.svg)
3
+ [![Gem Version](https://badge.fury.io/rb/green_log.svg)](http://badge.fury.io/rb/green_log)
4
+ [![Build Status](https://github.com/mdub/green_log/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/mdub/green_log/actions/workflows/ci.yml)
4
5
 
5
6
  GreenLog is a logging library for Ruby applications. It:
6
7
 
@@ -140,6 +141,14 @@ Logs go to STDOUT by default; specify `dest` to override, e.g.
140
141
  logger = GreenLog::Logger.build(dest: STDERR)
141
142
  ```
142
143
 
144
+ ### Null logger
145
+
146
+ `GreenLog::Logger.null` returns a "null object" Logger, which routes log entries to `/dev/null`.
147
+
148
+ ```ruby
149
+ logger = GreenLog::Logger.null
150
+ ```
151
+
143
152
  ### Filtering by log severity
144
153
 
145
154
  By default all log entries will result in output. You can add a severity-threshold to avoid emitting debug-level log messages, e.g.
@@ -185,9 +194,21 @@ legacy_logger.warn("Old skool")
185
194
  # outputs: W -- Old skool
186
195
  ```
187
196
 
197
+ ### Rack request-logging
198
+
199
+ GreenLog bundles a Rack middleware - an alternative to [`Rack::CommonLogger`](https://www.rubydoc.info/gems/rack/Rack/CommonLogger) - that generates structured HTTP access logs:
200
+
201
+ ```ruby
202
+ require "green_log"
203
+ require "green_log/rack/request_logging"
204
+
205
+ logger = GreenLog::Logger.build(format: "json")
206
+ use GreenLog::Rack::RequestLogging, logger
207
+ ```
208
+
188
209
  ## Contributing
189
210
 
190
- Bug reports and pull requests are welcome on GitHub at https://github.com/greensync/green_log.
211
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mdub/green_log.
191
212
 
192
213
  ## License
193
214
 
data/green_log.gemspec CHANGED
@@ -8,10 +8,10 @@ Gem::Specification.new do |spec|
8
8
  spec.name = "green_log"
9
9
  spec.version = GreenLog::VERSION
10
10
  spec.authors = ["Mike Williams"]
11
- spec.email = ["mike.williams@greensync.com.au"]
11
+ spec.email = ["mdub@dogbiscuit.org"]
12
12
 
13
13
  spec.summary = "Structured logging for cloud-native systems."
14
- spec.homepage = "https://github.com/greensync/green_log"
14
+ spec.homepage = "https://github.com/mdub/green_log"
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
@@ -24,11 +24,12 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
26
 
27
- spec.add_runtime_dependency "values", "~> 1.8"
27
+ spec.required_ruby_version = ">= 2.7.0"
28
+
28
29
  spec.add_development_dependency "bundler", "~> 2.0"
29
30
  spec.add_development_dependency "pry", "~> 0.12.2"
30
31
  spec.add_development_dependency "rack"
31
- spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rake", "~> 13.0"
32
33
  spec.add_development_dependency "rspec", "~> 3.0"
33
34
  spec.add_development_dependency "rubocop", "~> 0.77"
34
35
 
@@ -28,6 +28,14 @@ module GreenLog
28
28
 
29
29
  end
30
30
 
31
+ refine ::Array do
32
+
33
+ def to_loggable_value
34
+ map(&:to_loggable_value).freeze
35
+ end
36
+
37
+ end
38
+
31
39
  refine ::Numeric do
32
40
 
33
41
  def to_loggable_value
@@ -2,15 +2,28 @@
2
2
 
3
3
  require "green_log/core_refinements"
4
4
  require "green_log/severity"
5
- require "values"
6
5
 
7
6
  module GreenLog
8
7
 
9
8
  # Represents a structured log entry.
10
- class Entry < Value.new(:severity, :message, :context, :data, :exception)
9
+ class Entry
11
10
 
12
11
  using CoreRefinements
13
12
 
13
+ def initialize(severity:, message:, context:, data:, exception:)
14
+ @severity = severity
15
+ @message = message
16
+ @context = context
17
+ @data = data
18
+ @exception = exception
19
+ end
20
+
21
+ attr_reader :severity
22
+ attr_reader :message
23
+ attr_reader :context
24
+ attr_reader :data
25
+ attr_reader :exception
26
+
14
27
  class << self
15
28
 
16
29
  def with(**args)
@@ -21,7 +34,7 @@ module GreenLog
21
34
  args[:context] = args.fetch(:context, {}).to_loggable_value
22
35
  args[:data] = args.fetch(:data, {}).to_loggable_value
23
36
  args[:exception] ||= nil
24
- super(**args)
37
+ new(**args)
25
38
  end
26
39
 
27
40
  def build(severity, *args, &block)
@@ -31,7 +44,13 @@ module GreenLog
31
44
  end
32
45
 
33
46
  def in_context(extra_context)
34
- with(context: extra_context.integrate(context).to_loggable_value)
47
+ Entry.new(
48
+ severity: severity,
49
+ message: message,
50
+ context: extra_context.integrate(context).to_loggable_value,
51
+ data: data,
52
+ exception: exception,
53
+ )
35
54
  end
36
55
 
37
56
  # A builder for entries.
@@ -5,6 +5,7 @@ require "green_log/entry"
5
5
  require "green_log/severity"
6
6
  require "green_log/severity_filter"
7
7
  require "green_log/severity_threshold_support"
8
+ require "green_log/null_writer"
8
9
  require "green_log/simple_writer"
9
10
 
10
11
  module GreenLog
@@ -84,6 +85,11 @@ module GreenLog
84
85
  GreenLog.const_get("#{format.capitalize}Writer")
85
86
  end
86
87
 
88
+ # Return a null-object Logger.
89
+ def null
90
+ new(NullWriter.new)
91
+ end
92
+
87
93
  end
88
94
 
89
95
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "green_log/entry"
4
+ require "green_log/severity"
5
+ require "json"
6
+
7
+ module GreenLog
8
+
9
+ # A road to nowhere.
10
+ class NullWriter
11
+
12
+ def initialize; end
13
+
14
+ def <<(_entry); end
15
+
16
+ def severity_threshold
17
+ Severity::FATAL
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -64,11 +64,15 @@ module GreenLog
64
64
  end
65
65
 
66
66
  def request_body(request)
67
- original_position = request.body.pos
68
- request.body.rewind
69
- request.body.read
70
- ensure
71
- request.body.seek(original_position)
67
+ return "" if request.body.size.zero?
68
+
69
+ begin
70
+ original_position = request.body.pos
71
+ request.body.rewind
72
+ request.body.read
73
+ ensure
74
+ request.body.seek(original_position)
75
+ end
72
76
  end
73
77
 
74
78
  def response_details(response)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GreenLog
4
4
 
5
- VERSION = "0.1.0"
5
+ VERSION = "1.0.0"
6
6
 
7
7
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: green_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Williams
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-04 00:00:00.000000000 Z
11
+ date: 2023-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: values
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.8'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.8'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +58,14 @@ dependencies:
72
58
  requirements:
73
59
  - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: '10.0'
61
+ version: '13.0'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: '10.0'
68
+ version: '13.0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: rspec
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -108,9 +94,9 @@ dependencies:
108
94
  - - "~>"
109
95
  - !ruby/object:Gem::Version
110
96
  version: '0.77'
111
- description:
97
+ description:
112
98
  email:
113
- - mike.williams@greensync.com.au
99
+ - mdub@dogbiscuit.org
114
100
  executables: []
115
101
  extensions: []
116
102
  extra_rdoc_files: []
@@ -134,17 +120,18 @@ files:
134
120
  - lib/green_log/entry.rb
135
121
  - lib/green_log/json_writer.rb
136
122
  - lib/green_log/logger.rb
123
+ - lib/green_log/null_writer.rb
137
124
  - lib/green_log/rack/request_logging.rb
138
125
  - lib/green_log/severity.rb
139
126
  - lib/green_log/severity_filter.rb
140
127
  - lib/green_log/severity_threshold_support.rb
141
128
  - lib/green_log/simple_writer.rb
142
129
  - lib/green_log/version.rb
143
- homepage: https://github.com/greensync/green_log
130
+ homepage: https://github.com/mdub/green_log
144
131
  licenses:
145
132
  - MIT
146
133
  metadata: {}
147
- post_install_message:
134
+ post_install_message:
148
135
  rdoc_options: []
149
136
  require_paths:
150
137
  - lib
@@ -152,15 +139,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
139
  requirements:
153
140
  - - ">="
154
141
  - !ruby/object:Gem::Version
155
- version: '0'
142
+ version: 2.7.0
156
143
  required_rubygems_version: !ruby/object:Gem::Requirement
157
144
  requirements:
158
145
  - - ">="
159
146
  - !ruby/object:Gem::Version
160
147
  version: '0'
161
148
  requirements: []
162
- rubygems_version: 3.0.3
163
- signing_key:
149
+ rubygems_version: 3.1.2
150
+ signing_key:
164
151
  specification_version: 4
165
152
  summary: Structured logging for cloud-native systems.
166
153
  test_files: []