loggability 0.15.0.pre20190714094638 → 0.15.1

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
2
  SHA256:
3
- metadata.gz: 207be54e5100e41c070a6b545448ea603ff0e8a7cf4754149a8c63ec0ed1afe7
4
- data.tar.gz: e50d8153d2da1b21e27dbb919307c9812d6b786a7eb5b6f69a7e045d30c877d8
3
+ metadata.gz: 4dd5d6f5605a1a639a0143107b4079272e35bb7ffba9e2b76b150c1fab57e11f
4
+ data.tar.gz: aef9016eb5f208d0d168d8e4aac0b03047851b582f8afcb437b37bb9f9b5ad4d
5
5
  SHA512:
6
- metadata.gz: 21ca3115d9fd4a16515e8b30bad3ba981f3b4c2f42076338aa8008e4037ea408b70e3e90e4821be7f74083022e66075f480f18e4ae4a554a5d9ab1a0f6996a92
7
- data.tar.gz: 02cf4ec3ad18e2f39ea9c1642f527c8e33fdeec54ae8ea109c5cef481d3adb3ef919c4282a317875ee1274ed97558824c7fef283e83e0c022a369a76f869a1ee
6
+ metadata.gz: e14c6919279635835bd126a7c878ef69149811640cd4c632022e1677c18abfb3ebadc67fe8a12e9d35e35a94296e2c3ca32614c0c998ed9089b8e9b72d25ec56
7
+ data.tar.gz: d2481edb5e1a26dcc7f2a78420831d127b9951dd36e02e898bbd7fded829895083071627d9d78616fbad692937eb05edbdd39456efa0034aae4647cce597c484
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
data/ChangeLog CHANGED
@@ -1,23 +1,6 @@
1
- 2019-07-14 Michael Granger <ged@FaerieMUD.org>
2
-
3
- @ * .gems, Manifest.txt, Rakefile, lib/loggability/formatter.rb,
4
- | lib/loggability/formatter/default.rb,
5
- | lib/loggability/formatter/html.rb,
6
- | lib/loggability/formatter/structured.rb, lib/loggability/logger.rb,
7
- | loggability.gemspec, spec/helpers.rb,
8
- | spec/loggability/formatter/color_spec.rb,
9
- | spec/loggability/formatter/default_spec.rb,
10
- | spec/loggability/formatter/html_spec.rb,
11
- | spec/loggability/formatter/structured_spec.rb,
12
- | spec/loggability/formatter_spec.rb, spec/loggability/logger_spec.rb,
13
- | spec/loggability/override_spec.rb,
14
- | spec/loggability/spechelpers_spec.rb:
15
- | Add a structured log formatter.
16
- | [55ea9e745f4d] [tip]
17
- |
18
1
  2019-07-13 Michael Granger <ged@FaerieMUD.org>
19
2
 
20
- o * .ruby-version, lib/loggability.rb, lib/loggability/constants.rb,
3
+ @ * .ruby-version, lib/loggability.rb, lib/loggability/constants.rb,
21
4
  | lib/loggability/formatter.rb, lib/loggability/formatter/color.rb,
22
5
  | lib/loggability/formatter/default.rb,
23
6
  | lib/loggability/formatter/html.rb, lib/loggability/logclient.rb,
@@ -29,7 +12,7 @@ o * .ruby-version, lib/loggability.rb, lib/loggability/constants.rb,
29
12
  | spec/loggability/loghost_spec.rb, spec/loggability/override_spec.rb,
30
13
  | spec/loggability/spechelpers_spec.rb, spec/loggability_spec.rb:
31
14
  | Make literal strings frozen by default
32
- | [0933e9ab9c01]
15
+ | [0933e9ab9c01] [tip]
33
16
  |
34
17
  2018-10-10 Michael Granger <ged@FaerieMUD.org>
35
18
 
data/History.rdoc CHANGED
@@ -1,3 +1,26 @@
1
+ = Release History for loggability
2
+
3
+ ---
4
+
5
+ == v0.15.1 [2020-01-09] Michael Granger <ged@faeriemud.org>
6
+
7
+ Bugfixes:
8
+
9
+ - Change the spec to require Ruby 2.5 or greater. This was because
10
+ of the use methods that are only public in newer versions.
11
+
12
+
13
+ == v0.15.0 [2020-01-08] Michael Granger <ged@faeriemud.org>
14
+
15
+ (Yanked)
16
+
17
+ Enhancements:
18
+
19
+ - Make literal strings frozen by default
20
+ - Add a structured log formatter.
21
+ - Add fixes for Ruby 2.6 and 2.7
22
+
23
+
1
24
  == v0.14.0 [2017-01-30] Michael Granger <ged@FaerieMUD.org>
2
25
 
3
26
  Enhancements:
data/Manifest.txt CHANGED
@@ -2,7 +2,7 @@
2
2
  ChangeLog
3
3
  History.rdoc
4
4
  Manifest.txt
5
- README.rdoc
5
+ README.md
6
6
  Rakefile
7
7
  lib/loggability.rb
8
8
  lib/loggability/constants.rb
@@ -1,12 +1,19 @@
1
- = loggability
1
+ # loggability
2
2
 
3
- home :: http://deveiate.org/projects/loggability
4
- code :: http://bitbucket.org/ged/loggability
5
- docs :: http://deveiate.org/code/loggability
6
- github :: http://github.com/ged/loggability
3
+ home
4
+ : https://hg.sr.ht/~ged/Loggability
7
5
 
6
+ code
7
+ : https://hg.sr.ht/~ged/Loggability/browse
8
8
 
9
- == Description
9
+ docs
10
+ : https://deveiate.org/code/loggability
11
+
12
+ github
13
+ : https://github.com/ged/loggability
14
+
15
+
16
+ ## Description
10
17
 
11
18
  A composable logging system built on the standard Logger library.
12
19
 
@@ -21,23 +28,23 @@ An example:
21
28
  require 'inversion'
22
29
  require 'treequel'
23
30
  require 'loggability'
24
-
31
+
25
32
  # Set up our own library
26
33
  module MyProject
27
34
  extend Loggability
28
35
  log_as :my_project
29
-
36
+
30
37
  class Server
31
38
  extend Loggability
32
39
  log_to :my_project
33
-
40
+
34
41
  def initialize
35
42
  self.log.debug "Listening."
36
43
  end
37
44
  end
38
-
45
+
39
46
  end
40
-
47
+
41
48
  # Now tell everything that's using Loggability to log to an HTML
42
49
  # log file at INFO level
43
50
  Loggability.write_to( '/usr/local/www/htdocs/log.html' )
@@ -45,30 +52,30 @@ An example:
45
52
  Loggability.level = :info
46
53
 
47
54
 
48
- == Prerequisites
55
+ ## Prerequisites
49
56
 
50
- * Ruby 1.9.3 or better, Rubinius 2.0 or better
57
+ * Ruby 2.4+
51
58
 
52
59
  It will probably work under any other interpreter in which Logger works, but
53
60
  it's only tested in the above.
54
61
 
55
62
 
56
- == Installation
63
+ ## Installation
57
64
 
58
65
  $ gem install loggability
59
66
 
60
67
 
61
- == Usage
68
+ ## Usage
62
69
 
63
- Loggability is split up into two parts: {log hosts}[rdoc-ref:Loggability::LogHost]
64
- and {log clients}[rdoc-ref:Loggability::LogClient]. A <b>log
70
+ Loggability is split up into two parts: [log hosts](rdoc-ref:Loggability::LogHost)
71
+ and [log clients](rdoc-ref:Loggability::LogClient). A <b>log
65
72
  host</b> is an object that contains a Logger instance that will be used to
66
73
  log stuff. A <b>log client</b> is an object that will write logging messages to a
67
74
  particular <b>log host</b>'s Logger.
68
75
 
69
76
  Both parts require that you extend the object with Loggability.
70
77
 
71
- === Setting Up A 'Log Host'
78
+ ### Setting Up A 'Log Host'
72
79
 
73
80
  To install a Logger into an object, you use the +log_as+ declaration with a
74
81
  Symbol that will be used as the key for the object's Logger:
@@ -116,10 +123,10 @@ or use a few new convenience methods for changing the logging level:
116
123
  log_messages = []
117
124
  MyProject.logger.output_to( log_messages )
118
125
 
119
- ...{and more}[rdoc-ref:Loggability::Logger].
126
+ ...[and more](rdoc-ref:Loggability::Logger).
120
127
 
121
128
 
122
- === Setting Up A 'Log Client'
129
+ ### Setting Up A 'Log Client'
123
130
 
124
131
  To add an object that will log to your log host, after you <tt>extend Loggability</tt>,
125
132
  use the +log_to+ declaration to hook up the object (and instances of the object if
@@ -153,7 +160,7 @@ You can also use the <b>log host</b> itself as the argument to +log_to+:
153
160
  end
154
161
 
155
162
 
156
- === Aggregate Logging
163
+ ### Aggregate Logging
157
164
 
158
165
  If you have several <b>log hosts</b>, and you want to affect them all simultaneously,
159
166
  you can do that using the aggregate functions of Loggability. They're the same as the
@@ -161,15 +168,15 @@ methods on Loggability::Logger:
161
168
 
162
169
  # Set all logs to log at INFO level
163
170
  Loggability.level = :info
164
-
171
+
165
172
  # Write HTML logs
166
173
  Loggability.format_with( :html )
167
-
174
+
168
175
  # Log everything to the same logfile
169
176
  Loggability.output_to( "/tmp/my_project_log.html" )
170
177
 
171
178
 
172
- === Temporarily Overriding Logging Behavior
179
+ ### Temporarily Overriding Logging Behavior
173
180
 
174
181
  Sometimes you want to log one particular chunk of code at a different
175
182
  level, or to a different destination, and then restore everything back
@@ -187,7 +194,7 @@ Loggability has a few ways of doing that:
187
194
  Loggability.outputting_to( logs ) do
188
195
  ...
189
196
  end
190
-
197
+
191
198
  # Log using the HTML formatter
192
199
  Loggability.formatted_with( :html ) do
193
200
  ...
@@ -210,7 +217,7 @@ You can also make the override only apply to the loggers for a subset of log hos
210
217
  ACME.start_up
211
218
  end
212
219
 
213
- === Configurability
220
+ ### Configurability
214
221
 
215
222
  Loggability has support for the Configurability[https://rubygems.org/gems/configurability]
216
223
  library, which does the same thing for configuration that Loggability does for
@@ -230,39 +237,41 @@ The format of the value of each logger is:
230
237
 
231
238
  where:
232
239
 
233
- [+SEVERITY+]
234
- The log level; one of: +debug+, +info+, +warn+, +error+, or +fatal+
235
- [+TARGET+]
236
- The destination for log messages. This can be the path to a log file, or
237
- one of <tt>'STDOUT'</tt> or <tt>'STDERR'</tt>, which get mapped to the
238
- equivalent filehandle. Optional.
239
- [+FORMAT+]
240
- The name of one of the formatters. Loggability comes with +default+ (plaintext),
241
- +color+ (ANSI colored text), and +html+ formatters. Optional.
240
+ +SEVERITY+
241
+ : The log level; one of: +debug+, +info+, +warn+, +error+, or +fatal+
242
242
 
243
- If the special key <tt>__default__</tt> is included, its config will be used to set
244
- global defaults before the individual configs are applied.
243
+ +TARGET+
244
+ : The destination for log messages. This can be the path to a log file, or
245
+ one of <tt>'STDOUT'</tt> or <tt>'STDERR'</tt>, which get mapped to the
246
+ equivalent filehandle. Optional.
245
247
 
246
- If either of the optional values is unspecified, it is left unchanged from what it
247
- was before configuration.
248
+ +FORMAT+
249
+ : The name of one of the formatters. Loggability comes with +default+
250
+ (plaintext), +color+ (ANSI colored text), and +html+ formatters. Optional.
248
251
 
252
+ If the special key <tt>__default__</tt> is included, its config will be used to
253
+ set global defaults before the individual configs are applied.
249
254
 
250
- === RSpec Helpers
255
+ If either of the optional values is unspecified, it is left unchanged from what
256
+ it was before configuration.
251
257
 
252
- Loggability includes a couple of helper functions for RSpec that allow you to control
253
- log levels for particular specs.
254
258
 
255
- To use it, require <tt>loggability/spechelpers</tt> in your specs (we put it in the
256
- spec helpers file) and then include the helpers from your RSpec config:
259
+ ### RSpec Helpers
257
260
 
258
- require 'loggability/spechelpers'
259
- RSpec.configure do |c|
260
- # ...
261
- c.include( Loggability::SpecHelpers )
262
- end
261
+ Loggability includes a couple of helper functions for RSpec that allow you to
262
+ control log levels for particular specs.
263
+
264
+ To use it, require <tt>loggability/spechelpers</tt> in your specs (we put it in
265
+ the spec helpers file) and then include the helpers from your RSpec config:
263
266
 
264
- This will install a before and after `:all` hook to set the logging levels before each
265
- example group and then reset it before moving on to the next group.
267
+ require 'loggability/spechelpers'
268
+ RSpec.configure do |c|
269
+ # ...
270
+ c.include( Loggability::SpecHelpers )
271
+ end
272
+
273
+ This will install a before and after `:all` hook to set the logging levels
274
+ before each example group and then reset it before moving on to the next group.
266
275
 
267
276
  You can also access the bodies of those hooks manually:
268
277
 
@@ -270,31 +279,31 @@ You can also access the bodies of those hooks manually:
270
279
  reset_logging()
271
280
 
272
281
  The helpers also allow you to set logging levels for a whole example group, for
273
- particular contexts, or even for individual examples using RSpec's metadata hash
274
- syntax:
282
+ particular contexts, or even for individual examples using RSpec's metadata
283
+ hash syntax:
275
284
 
276
285
  # Set logging to 'error' level for each example in this group
277
286
  describe MyClass, logging: :error do
278
-
287
+
279
288
  # ...but for examples in this context, set it to 'fatal'
280
289
  context 'created with a target', log: :fatal do
281
-
290
+
282
291
  # ...except for this one, which logs at 'debug' level
283
292
  it "does something to it", logging: :debug do
284
-
293
+
285
294
  end
286
-
295
+
287
296
  it "does some other stuff, too"
288
-
297
+
289
298
  end
290
-
299
+
291
300
  end
292
301
 
293
- The {setup_logging}[rdoc-ref:Loggability::SpecHelpers.setup_logging] helper
302
+ The [setup_logging](rdoc-ref:Loggability::SpecHelpers.setup_logging) helper
294
303
  also provides support for displaying the logs inline with spec formatters for
295
304
  which outputting the logs to STDERR isn't optimal. The only one that's
296
- currently uses it is the
297
- {'webkit' formatter}[https://rubygems.org/gems/rspec-formatter-webkit], but
305
+ currently uses it is the
306
+ ['webkit' formatter](https://rubygems.org/gems/rspec-formatter-webkit), but
298
307
  it should be easy to adapt to other HTML displays as well.
299
308
 
300
309
  It looks for either an +HTML_LOGGING+ environment variable, or for the
@@ -307,23 +316,21 @@ This can be used to append logs to each example when the formatter
307
316
  builds the output.
308
317
 
309
318
 
310
- == Contributing
319
+ ## Contributing
311
320
 
312
321
  You can check out the current development source with
313
- Mercurial[http://bitbucket.org/ged/loggability], or if you prefer Git, via
314
- {its Github mirror}[https://github.com/ged/loggability].
322
+ Mercurial[http://hg.sr.ht/~ged/Loggability], or if you prefer Git, via
323
+ [its Github mirror](https://github.com/ged/loggability).
315
324
 
316
- After checking out the source, run:
317
325
 
318
- $ rake newb
326
+ ## Author
319
327
 
320
- This task will install any missing dependencies, run the tests/specs,
321
- and generate the API documentation.
328
+ - Michael Granger <ged@faeriemud.org>
322
329
 
323
330
 
324
- == License
331
+ ## License
325
332
 
326
- Copyright (c) 2012-2017, Michael Granger
333
+ Copyright (c) 2012-2020, Michael Granger
327
334
  All rights reserved.
328
335
 
329
336
  Redistribution and use in source and binary forms, with or without
data/Rakefile CHANGED
@@ -1,82 +1,9 @@
1
- #!/usr/bin/env rake
1
+ #!/usr/bin/env ruby -S rake
2
2
 
3
- require 'rake/clean'
3
+ require 'rake/deveiate'
4
4
 
5
- begin
6
- require 'hoe'
7
- rescue LoadError
8
- abort "This Rakefile requires 'hoe' (gem install hoe)"
5
+ Rake::DevEiate.setup( 'loggability' ) do |project|
6
+ project.required_ruby_version = '~> 2.5'
7
+ project.publish_to = 'deveiate:/usr/local/www/public/code'
9
8
  end
10
9
 
11
- GEMSPEC = 'loggability.gemspec'
12
-
13
- Hoe.plugin :mercurial
14
- Hoe.plugin :signing
15
- Hoe.plugin :deveiate
16
-
17
- Hoe.plugins.delete :rubyforge
18
-
19
- hoespec = Hoe.spec 'loggability' do
20
- self.readme_file = 'README.rdoc'
21
- self.history_file = 'History.rdoc'
22
- self.extra_rdoc_files = FileList[ '*.rdoc' ]
23
-
24
- self.developer 'Michael Granger', 'ged@FaerieMUD.org'
25
-
26
- self.dependency 'hoe-deveiate', '~> 0.4', :developer
27
- self.dependency 'hoe-bundler', '~> 1.2', :developer
28
- self.dependency 'simplecov', '~> 0.7', :developer
29
- self.dependency 'configurability', '~> 3.1', :developer
30
- self.dependency 'timecop', '~> 0.9', :developer
31
-
32
- self.license "BSD-3-Clause"
33
- self.require_ruby_version( '>=1.9.3' )
34
- self.hg_sign_tags = true if self.respond_to?( :hg_sign_tags= )
35
- self.check_history_on_release = true if self.respond_to?( :check_history_on_release= )
36
-
37
- self.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}"
38
- end
39
-
40
- ENV['VERSION'] ||= hoespec.spec.version.to_s
41
-
42
- # Ensure the specs pass before checking in
43
- task 'hg:precheckin' => [ :check_history, :check_manifest, :gemspec, :spec ]
44
-
45
-
46
- desc "Build a coverage report"
47
- task :coverage do
48
- ENV["COVERAGE"] = 'yes'
49
- Rake::Task[:spec].invoke
50
- end
51
- CLOBBER.include( 'coverage' )
52
-
53
-
54
- # Use the fivefish formatter for docs generated from development checkout
55
- if File.directory?( '.hg' )
56
- require 'rdoc/task'
57
-
58
- Rake::Task[ 'docs' ].clear
59
- RDoc::Task.new( 'docs' ) do |rdoc|
60
- rdoc.main = "README.rdoc"
61
- rdoc.rdoc_files.include( "*.rdoc", "ChangeLog", "lib/**/*.rb" )
62
- rdoc.generator = :fivefish
63
- rdoc.title = 'Loggability'
64
- rdoc.rdoc_dir = 'doc'
65
- end
66
- end
67
-
68
- task :gemspec => GEMSPEC
69
- file GEMSPEC => [ __FILE__, 'lib/loggability.rb' ]
70
- task GEMSPEC do |task|
71
- hoespec = $hoespec.spec
72
- hoespec.files.delete( '.gemtest' )
73
- hoespec.signing_key = nil
74
- hoespec.version = "#{hoespec.version.bump}.0.pre#{Time.now.strftime("%Y%m%d%H%M%S")}"
75
- hoespec.cert_chain = [ 'certs/ged.pem' ]
76
- File.open( task.name, 'w' ) do |fh|
77
- fh.write( hoespec.to_ruby )
78
- end
79
- end
80
-
81
- CLOBBER.include( GEMSPEC.to_s )
82
-
data/lib/loggability.rb CHANGED
@@ -9,10 +9,7 @@ require 'date'
9
9
  module Loggability
10
10
 
11
11
  # Package version constant
12
- VERSION = '0.14.0'
13
-
14
- # VCS revision
15
- REVISION = %q$Revision$
12
+ VERSION = '0.15.1'
16
13
 
17
14
  # The key for the global logger (Loggability's own logger)
18
15
  GLOBAL_KEY = :__global__
@@ -29,13 +26,13 @@ module Loggability
29
26
  LOGSPEC_PATTERN = %r{
30
27
  ^
31
28
  \s*
32
- ((?i:debug|info|warn|error|fatal)) # severity
29
+ (?<severity>(?i:debug|info|warn|error|fatal))
33
30
  (?:
34
31
  \s+
35
- ((?:[\w\-/:\.]|\\[ ])+)
32
+ (?<target>(?:[\w\-/:\.]|\\[ ])+)
36
33
  )?
37
34
  (?: \s+\(
38
- (\w+)
35
+ (?<format>\w+)
39
36
  \) )?
40
37
  \s*
41
38
  $
@@ -64,14 +61,6 @@ module Loggability
64
61
  autoload :Override, 'loggability/override'
65
62
 
66
63
 
67
- ### Return the library's version string
68
- def self::version_string( include_buildnum=false )
69
- vstring = "%s %s" % [ self.name, VERSION ]
70
- vstring << " (build %s)" % [ REVISION[/: ([[:xdigit:]]+)/, 1] || '0' ] if include_buildnum
71
- return vstring
72
- end
73
-
74
-
75
64
  ### Cast the given +device+ to a Loggability::Logger, if possible, and return it. If
76
65
  ### it can't be converted, raises a ArgumentError.
77
66
  def self::Logger( device )
@@ -0,0 +1,35 @@
1
+ # -*- ruby -*-
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # frozen_string_literal: true
4
+
5
+ require 'time'
6
+ require 'json'
7
+
8
+ require 'loggability/formatter' unless defined?( Loggability::Formatter )
9
+
10
+
11
+ # Output logs as JSON.
12
+ class Loggability::Formatter::Structured < Loggability::Formatter
13
+
14
+ # The version of the format output
15
+ LOG_FORMAT_VERSION = 1
16
+
17
+
18
+ ### Format a message of the specified +severity+ using the given +time+,
19
+ ### +progname+, and +message+.
20
+ def call( severity, time, progname, message )
21
+ severity ||= 'DEBUG'
22
+ time ||= Time.now
23
+ entry = {
24
+ '@version' => LOG_FORMAT_VERSION,
25
+ '@timestamp' => time.iso8601( 3 ),
26
+ 'level' => severity,
27
+ 'progname' => progname,
28
+ 'message' => message,
29
+ }
30
+
31
+ return JSON.generate( entry )
32
+ end
33
+
34
+ end # class Loggability::Formatter::Default
35
+
@@ -28,7 +28,8 @@ class Loggability::Logger < ::Logger
28
28
  # to a file descriptor or a file.
29
29
  class AppendingLogDevice
30
30
 
31
- ### Create a new AppendingLogDevice that will append content to +array+.
31
+ ### Create a new AppendingLogDevice that will append content to +target+ (a
32
+ ### object that responds to #>>).
32
33
  def initialize( target )
33
34
  @target = target
34
35
  end
@@ -182,6 +183,28 @@ class Loggability::Logger < ::Logger
182
183
  end
183
184
 
184
185
 
186
+ ### Log a message if the +severity+ is high enough. Overridden to account for
187
+ ### the overridden #level.
188
+ def add( severity, message=nil, progname=nil )
189
+ return true if severity < self.sev_threshold
190
+ progname ||= @progname
191
+
192
+ unless message
193
+ if block_given?
194
+ message = yield
195
+ else
196
+ message = progname
197
+ progname = @progname
198
+ end
199
+ end
200
+
201
+ msg = self.format_message( self.format_severity(severity), Time.now, progname, message )
202
+ self.logdev.write( msg )
203
+
204
+ return true
205
+ end
206
+
207
+
185
208
  ### Append operator -- Override Logger's append so log messages always have
186
209
  ### formatting, and are always appended at :debug level.
187
210
  def <<( message )
@@ -224,8 +247,7 @@ class Loggability::Logger < ::Logger
224
247
 
225
248
  ### Return the logger's level as a Symbol.
226
249
  def level
227
- numeric_level = super
228
- return LOG_LEVEL_NAMES[ numeric_level ]
250
+ return LOG_LEVEL_NAMES[ self.sev_threshold ]
229
251
  end
230
252
 
231
253
 
@@ -256,7 +278,7 @@ class Loggability::Logger < ::Logger
256
278
  self.logdev = target
257
279
  elsif target.respond_to?( :write ) || target.is_a?( String )
258
280
  opts = { :shift_age => args.shift || 0, :shift_size => args.shift || 1048576 }
259
- self.logdev = Logger::LogDevice.new( target, opts )
281
+ self.logdev = Logger::LogDevice.new( target, **opts )
260
282
  elsif target.respond_to?( :<< )
261
283
  self.logdev = AppendingLogDevice.new( target )
262
284
  else
@@ -282,6 +304,13 @@ class Loggability::Logger < ::Logger
282
304
  end
283
305
 
284
306
 
307
+ ### Return the formatted name of the given +severity+.
308
+ def format_severity( severity )
309
+ name = LOG_LEVEL_NAMES[ severity ] || severity.to_s
310
+ return name.upcase
311
+ end
312
+
313
+
285
314
  ### Set a new +formatter+ for the logger. If +formatter+ is +nil+ or +:default+, this causes the
286
315
  ### logger to fall back to its default formatter. If it's a Symbol other than +:default+, it looks
287
316
  ### for a similarly-named formatter under loggability/formatter/ and uses that. If +formatter+ is
data/spec/helpers.rb CHANGED
@@ -99,6 +99,8 @@ RSpec.configure do |c|
99
99
  c.mock_with( :rspec ) do |mock|
100
100
  mock.syntax = :expect
101
101
  end
102
+ c.warnings = true
103
+ c.profile_examples = 5
102
104
 
103
105
  c.include( SpecHelpers )
104
106
  c.include( Loggability::SpecHelpers )
@@ -0,0 +1,50 @@
1
+ # -*- ruby -*-
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # frozen_string_literal: true
4
+
5
+ require_relative '../../helpers'
6
+
7
+ require 'loggability/formatter/default'
8
+
9
+
10
+ describe Loggability::Formatter::Default do
11
+
12
+ it "formats messages with the pattern it's constructed with" do
13
+ formatter = described_class.new( '[%5$s] %7$s' )
14
+ result = formatter.call( 'INFO', Time.at(1336286481), nil, 'Foom.' )
15
+ expect( result ).to match(/\[INFO\] Foom./i)
16
+ end
17
+
18
+
19
+ it "formats exceptions into useful messages" do
20
+ formatter = described_class.new( '[%5$s] %7$s' )
21
+ msg = nil
22
+
23
+ begin
24
+ raise ArgumentError, "invalid argument"
25
+ rescue => err
26
+ msg = formatter.call( 'INFO', Time.at(1336286481), nil, err )
27
+ end
28
+
29
+ expect( msg ).to match(/\[INFO\] ArgumentError: invalid argument/i)
30
+ end
31
+
32
+
33
+ it "formats regular objects into useful messages" do
34
+ formatter = described_class.new( '[%5$s] %7$s' )
35
+ result = formatter.call( 'INFO', Time.at(1336286481), nil, Object.new )
36
+
37
+ expect( result ).to match(/\[INFO\] #<Object:0x[[:xdigit:]]+>/i)
38
+ end
39
+
40
+
41
+ it "includes the thread ID if logging from a thread other than the main thread" do
42
+ formatter = described_class.new( '%4$d' )
43
+ thr = Thread.new do
44
+ formatter.call( 'INFO', Time.now, nil, 'Foom.' )
45
+ end
46
+ expect( thr.value ).to eq( thr.object_id.to_s )
47
+ end
48
+
49
+ end
50
+
@@ -0,0 +1,61 @@
1
+ # -*- ruby -*-
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # frozen_string_literal: true
4
+
5
+ require_relative '../../helpers'
6
+
7
+ require 'loggability/formatter/structured'
8
+
9
+
10
+ describe Loggability::Formatter::Structured do
11
+
12
+ before( :each ) do
13
+ ENV['TZ'] = 'UTC'
14
+ end
15
+
16
+
17
+ it "outputs a stream of JSON objects" do
18
+ expect(
19
+ subject.call('INFO', Time.at(1336286481), nil, "Foom.")
20
+ ).to eq(
21
+ %q|{"@version":1,"@timestamp":"2012-05-06T06:41:21.000+00:00"| +
22
+ %q|,"level":"INFO","progname":null,"message":"Foom."}|
23
+ )
24
+ end
25
+
26
+
27
+ it "includes a time even if called without one" do
28
+ Timecop.freeze( Time.at(1563114765.123) ) do
29
+ expect(
30
+ subject.call('WARN', nil, nil, "Right.")
31
+ ).to match( %r(
32
+ \{
33
+ "@version":1,
34
+ "@timestamp":"2019-07-14T14:32:45\.\d{3}\+00:00",
35
+ "level":"WARN",
36
+ "progname":null,
37
+ "message":"Right\."
38
+ \}
39
+ )x )
40
+ end
41
+ end
42
+
43
+
44
+ it "defaults to DEBUG severity" do
45
+ Timecop.freeze( Time.at(1563114765.123) ) do
46
+ expect(
47
+ subject.call(nil, nil, nil, "Crane.")
48
+ ).to match( %r(
49
+ \{
50
+ "@version":1,
51
+ "@timestamp":"2019-07-14T14:32:45\.\d{3}\+00:00",
52
+ "level":"DEBUG",
53
+ "progname":null,
54
+ "message":"Crane\."
55
+ \}
56
+ )x )
57
+ end
58
+ end
59
+
60
+ end
61
+
@@ -23,18 +23,6 @@ describe Loggability do
23
23
  end
24
24
 
25
25
 
26
- describe "version methods" do
27
- it "returns a version string if asked" do
28
- expect( described_class.version_string ).to match( /\w+ [\d.]+/ )
29
- end
30
-
31
- it "returns a version string with a build number if asked" do
32
- expect( described_class.version_string(true) ).
33
- to match(/\w+ [\d.]+ \(build [[:xdigit:]]+\)/)
34
- end
35
- end
36
-
37
-
38
26
  context "installed in a class as a log host" do
39
27
 
40
28
  before( :each ) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loggability
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0.pre20190714094638
4
+ version: 0.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
@@ -11,8 +11,8 @@ cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIENDCCApygAwIBAgIBATANBgkqhkiG9w0BAQsFADAiMSAwHgYDVQQDDBdnZWQv
14
- REM9RmFlcmllTVVEL0RDPW9yZzAeFw0xODExMjAxODI5NTlaFw0xOTExMjAxODI5
15
- NTlaMCIxIDAeBgNVBAMMF2dlZC9EQz1GYWVyaWVNVUQvREM9b3JnMIIBojANBgkq
14
+ REM9RmFlcmllTVVEL0RDPW9yZzAeFw0xOTEwMDkwMDM2NTdaFw0yMDEwMDgwMDM2
15
+ NTdaMCIxIDAeBgNVBAMMF2dlZC9EQz1GYWVyaWVNVUQvREM9b3JnMIIBojANBgkq
16
16
  hkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAvyVhkRzvlEs0fe7145BYLfN6njX9ih5H
17
17
  L60U0p0euIurpv84op9CNKF9tx+1WKwyQvQP7qFGuZxkSUuWcP/sFhDXL1lWUuIl
18
18
  M4uHbGCRmOshDrF4dgnBeOvkHr1fIhPlJm5FO+Vew8tSQmlDsosxLUx+VB7DrVFO
@@ -24,74 +24,32 @@ cert_chain:
24
24
  N2I4L/ZOIe2DIVuYH7aLHfjZDQv/mNgpAgMBAAGjdTBzMAkGA1UdEwQCMAAwCwYD
25
25
  VR0PBAQDAgSwMB0GA1UdDgQWBBRyjf55EbrHagiRLqt5YAd3yb8k4DAcBgNVHREE
26
26
  FTATgRFnZWRARmFlcmllTVVELm9yZzAcBgNVHRIEFTATgRFnZWRARmFlcmllTVVE
27
- Lm9yZzANBgkqhkiG9w0BAQsFAAOCAYEAP9Ffkvg4e8CjIWi8SykQ8oJSS8jbmbgF
28
- abke3vXWLG6V9kFiObuJd5wZRBluJANu7bEtjgc3fFaGVP2XxVdCpVjNbmMDg4Qp
29
- ovvczP53X6pQP2RSZgxF6Lblvy8y11RziUTVRG/Z2aJHsElo6gI7vQznE/OSDrhC
30
- gEhr8uaIUt7D+HZWRbU0+MkKPpL5uMqaFuJbqXEvSwPTuUuYkDfNfsjQO7ruWBac
31
- bxHCrvpZ6Tijc0nrlyXi6gPOCLeaqhau2xFnlvKgELwsGYSoKBJyDwqtQ5kwrOlU
32
- tkSyLrfZ+RZcH535Hyvif7ZxB0v5OxXXoec+N2vrUsEUMRDL9dg4/WFdN8hIOixF
33
- 3IPKpZ1ho0Ya5q7yhygtBK9/NBFHw+nbJjcltfPDBXleRe8u73gnQo8AZIhStYSP
34
- v4qqqa27Bs468d6SoPxjSm8a2mM9HZ4OdWhq4tFsbTeXDVquCfi64OTEaTt2xQdR
35
- JnC4lpJfCP6aCXa5h2XAQfPSH636cQap
27
+ Lm9yZzANBgkqhkiG9w0BAQsFAAOCAYEAFqsr6o0SvQRgjQVmhbQvExRnCMCoW1yb
28
+ FJiN7A5RA2Iy2E61OG1Ul5nGmaDmx/PNB/6JIbIV3B9Uq8aTZx4uOjK7r8vMl1/t
29
+ ZfY7r6HejJfXlcO2m6JDMbpdyEVv916LncBkzZRz6vnnNCx+31f15FKddxujpAFd
30
+ qpn3JRQY+oj7ZkoccL/IUiDpxQWeS3oOoz9qr2kVTp8R50InZimt79FqCl/1m66W
31
+ kdOuf+wM3DDx7Rt4IVNHrhGlyfMr7xjKW1Q3gll+pMN1DT6Ajx/t3JDSEg7BnnEW
32
+ r7AciSO6J4ApUdqyG+coLFlGdtgFTgRHv7ihbQtDI7Z/LV7A4Spn1j2PK3j0Omri
33
+ kSl1hPVigRytfgdVGiLXzvkkrkgj9EknCaj5UHbac7XvVBrljXj9hsnnqTANaKsg
34
+ jBZSA+N+xUTgUWpXjjwsLZjzJkhWATJWq+krNXcqpwXo6HsjmdUxoFMt63RBb+sI
35
+ XrxOxp8o0uOkU7FdLSGsyqJ2LzsR4obN
36
36
  -----END CERTIFICATE-----
37
- date: 2019-07-14 00:00:00.000000000 Z
37
+ date: 2020-01-09 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
- name: hoe-mercurial
40
+ name: rake-deveiate
41
41
  requirement: !ruby/object:Gem::Requirement
42
42
  requirements:
43
43
  - - "~>"
44
44
  - !ruby/object:Gem::Version
45
- version: '1.4'
46
- type: :development
47
- prerelease: false
48
- version_requirements: !ruby/object:Gem::Requirement
49
- requirements:
50
- - - "~>"
51
- - !ruby/object:Gem::Version
52
- version: '1.4'
53
- - !ruby/object:Gem::Dependency
54
- name: hoe-deveiate
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '0.10'
60
- type: :development
61
- prerelease: false
62
- version_requirements: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - "~>"
65
- - !ruby/object:Gem::Version
66
- version: '0.10'
67
- - !ruby/object:Gem::Dependency
68
- name: hoe-highline
69
- requirement: !ruby/object:Gem::Requirement
70
- requirements:
71
- - - "~>"
72
- - !ruby/object:Gem::Version
73
- version: '0.2'
74
- type: :development
75
- prerelease: false
76
- version_requirements: !ruby/object:Gem::Requirement
77
- requirements:
78
- - - "~>"
79
- - !ruby/object:Gem::Version
80
- version: '0.2'
81
- - !ruby/object:Gem::Dependency
82
- name: hoe-bundler
83
- requirement: !ruby/object:Gem::Requirement
84
- requirements:
85
- - - "~>"
86
- - !ruby/object:Gem::Version
87
- version: '1.2'
45
+ version: '0.7'
88
46
  type: :development
89
47
  prerelease: false
90
48
  version_requirements: !ruby/object:Gem::Requirement
91
49
  requirements:
92
50
  - - "~>"
93
51
  - !ruby/object:Gem::Version
94
- version: '1.2'
52
+ version: '0.7'
95
53
  - !ruby/object:Gem::Dependency
96
54
  name: simplecov
97
55
  requirement: !ruby/object:Gem::Requirement
@@ -135,65 +93,31 @@ dependencies:
135
93
  - !ruby/object:Gem::Version
136
94
  version: '0.9'
137
95
  - !ruby/object:Gem::Dependency
138
- name: rdoc
139
- requirement: !ruby/object:Gem::Requirement
140
- requirements:
141
- - - ">="
142
- - !ruby/object:Gem::Version
143
- version: '4.0'
144
- - - "<"
145
- - !ruby/object:Gem::Version
146
- version: '7'
147
- type: :development
148
- prerelease: false
149
- version_requirements: !ruby/object:Gem::Requirement
150
- requirements:
151
- - - ">="
152
- - !ruby/object:Gem::Version
153
- version: '4.0'
154
- - - "<"
155
- - !ruby/object:Gem::Version
156
- version: '7'
157
- - !ruby/object:Gem::Dependency
158
- name: hoe
96
+ name: rdoc-generator-fivefish
159
97
  requirement: !ruby/object:Gem::Requirement
160
98
  requirements:
161
99
  - - "~>"
162
100
  - !ruby/object:Gem::Version
163
- version: '3.18'
101
+ version: '0.4'
164
102
  type: :development
165
103
  prerelease: false
166
104
  version_requirements: !ruby/object:Gem::Requirement
167
105
  requirements:
168
106
  - - "~>"
169
107
  - !ruby/object:Gem::Version
170
- version: '3.18'
171
- description: "A composable logging system built on the standard Logger library.\n\nYou
172
- can add Loggability to large libraries and systems, then hook everything\nup later
173
- when you know where you want logs to be written, at what level of\nseverity, and
174
- in which format.\n\nAn example:\n\n # Load a bunch of libraries that use Loggability\n
175
- \ require 'strelka'\n require 'inversion'\n require 'treequel'\n require
176
- 'loggability'\n \n # Set up our own library\n module MyProject\n extend
177
- Loggability\n log_as :my_project\n \n class Server\n extend
178
- Loggability\n log_to :my_project\n \n def initialize\n
179
- \ self.log.debug \"Listening.\"\n end\n end\n \n
180
- \ end\n \n # Now tell everything that's using Loggability to log to an HTML\n
181
- \ # log file at INFO level\n Loggability.write_to( '/usr/local/www/htdocs/log.html'
182
- )\n Loggability.format_as( :html )\n Loggability.level = :info"
108
+ version: '0.4'
109
+ description: A composable logging system built on the standard Logger library.
183
110
  email:
184
- - ged@FaerieMUD.org
111
+ - ged@faeriemud.org
185
112
  executables: []
186
113
  extensions: []
187
- extra_rdoc_files:
188
- - History.rdoc
189
- - Manifest.txt
190
- - README.rdoc
114
+ extra_rdoc_files: []
191
115
  files:
192
116
  - ".simplecov"
193
117
  - ChangeLog
194
118
  - History.rdoc
195
119
  - Manifest.txt
196
- - README.rdoc
120
+ - README.md
197
121
  - Rakefile
198
122
  - lib/loggability.rb
199
123
  - lib/loggability/constants.rb
@@ -201,6 +125,7 @@ files:
201
125
  - lib/loggability/formatter/color.rb
202
126
  - lib/loggability/formatter/default.rb
203
127
  - lib/loggability/formatter/html.rb
128
+ - lib/loggability/formatter/structured.rb
204
129
  - lib/loggability/logclient.rb
205
130
  - lib/loggability/logger.rb
206
131
  - lib/loggability/loghost.rb
@@ -208,36 +133,36 @@ files:
208
133
  - lib/loggability/spechelpers.rb
209
134
  - spec/helpers.rb
210
135
  - spec/loggability/formatter/color_spec.rb
136
+ - spec/loggability/formatter/default_spec.rb
211
137
  - spec/loggability/formatter/html_spec.rb
138
+ - spec/loggability/formatter/structured_spec.rb
212
139
  - spec/loggability/formatter_spec.rb
213
140
  - spec/loggability/logger_spec.rb
214
141
  - spec/loggability/loghost_spec.rb
215
142
  - spec/loggability/override_spec.rb
216
143
  - spec/loggability/spechelpers_spec.rb
217
144
  - spec/loggability_spec.rb
218
- homepage: http://deveiate.org/projects/loggability
145
+ homepage: https://hg.sr.ht/~ged/Loggability
219
146
  licenses:
220
147
  - BSD-3-Clause
221
148
  metadata: {}
222
149
  post_install_message:
223
- rdoc_options:
224
- - "--main"
225
- - README.rdoc
150
+ rdoc_options: []
226
151
  require_paths:
227
152
  - lib
228
153
  required_ruby_version: !ruby/object:Gem::Requirement
229
154
  requirements:
230
- - - ">="
155
+ - - "~>"
231
156
  - !ruby/object:Gem::Version
232
- version: 1.9.3
157
+ version: '2.5'
233
158
  required_rubygems_version: !ruby/object:Gem::Requirement
234
159
  requirements:
235
- - - ">"
160
+ - - ">="
236
161
  - !ruby/object:Gem::Version
237
- version: 1.3.1
162
+ version: '0'
238
163
  requirements: []
239
- rubygems_version: 3.0.3
164
+ rubygems_version: 3.1.2
240
165
  signing_key:
241
166
  specification_version: 4
242
- summary: A composable logging system built on the standard Logger library
167
+ summary: A composable logging system built on the standard Logger library.
243
168
  test_files: []
metadata.gz.sig ADDED
Binary file