loglevel 0.3.0 → 0.4.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
  SHA1:
3
- metadata.gz: 1505dc964fe83a014f6d4fe8aacfcbb233719374
4
- data.tar.gz: b85714e7f5ed83aa6e1c406e98406bc3e46c7ace
3
+ metadata.gz: 27d935b0bba808acac6f2dc481350410698cb44d
4
+ data.tar.gz: 1434b05ae0a081a45df1dfb0b62f7f3d10ce0100
5
5
  SHA512:
6
- metadata.gz: 71c930051600a6b5a8643a7860921ac2e6b1dbfac260f08b88a9574b7bf31878d28a31b0e2f0bd2f0a4894d36afd475bbf55a27db270c354c74708f3d005d90d
7
- data.tar.gz: 7d0b79417fde7f52badc0150a31db0df9c65f5735510743dd8135cab5719bc33ca70461185ae8e1c298bfe3919ad63c4fe3d32ff9147863d1c829ac13458d195
6
+ metadata.gz: 5000a19490bec0ecad39c9f1b9347b695118db51d077f5961b39a6425cc4da7c3053e9bc441335d446d3b162c9a74bab26b9e0f5a4f045e966167ddb378317db
7
+ data.tar.gz: 3e84eb62bbfb745a499ccedf45eb5e2bb2e1b76861602f74433de3401b309db4dc76e30061e06da30535d07e8fcc38bcc7a60959cf88ece4de7d135f6ae2727a
data/README.md CHANGED
@@ -58,9 +58,31 @@ There are specific options to handle Railsy logging scenarios: things like
58
58
  controlling ActiveRecord logging. There are also specific options for handling
59
59
  the HttpLogger gem.
60
60
 
61
+ ### Rails initialization
62
+
63
+ In a Rails context, we want Loglevel to be configured *after* Rails's own logger
64
+ has been initialized but before any other app initialization has taken place.
65
+ This allows us to control the logging of other components' initialization.
66
+
67
+ The best way I have found of doing this is to create a script in the
68
+ `config/initializers` directory. These initializers are executed in alphabetical
69
+ order so you can control when Loglevel is initialized by carefully naming your
70
+ script.
71
+
72
+ To initialize Loglevel first, create a script called `01_loglevel.rb` with the
73
+ single line
74
+
75
+ ```
76
+ Loglevel.setup
77
+ ```
78
+
79
+ To understand which other points in the Rails initialization process you can
80
+ choose, see [The Rails Initialization Process](http://guides.rubyonrails.org/initialization.html).
81
+
61
82
  ### Logger
62
83
 
63
- By default Loglevel will instantiate Ruby's default Logger class. If you want to
84
+ By default Loglevel will instantiate Ruby's default Logger class (in a Rails
85
+ context this will be something like ActiveSupport::TaggedLogging). If you want to
64
86
  use a different logger then you can use an environment variable to tell Loglevel
65
87
  which logger you use:
66
88
 
@@ -1,3 +1,4 @@
1
+ require 'loglevel/exception'
1
2
  require 'loglevel/classes'
2
3
  require 'loglevel/active_record'
3
4
  require 'loglevel/http_logger'
@@ -79,7 +80,17 @@ class Loglevel
79
80
  end
80
81
 
81
82
  def logger_class
82
- Object.const_get ENV.fetch(ENV_VAR_LOGGER, 'Logger')
83
+ Object.const_get logger_class_name
84
+ rescue NameError => e
85
+ fail Loglevel::Exception::BadLoggerClass, "Can't find logger class #{logger_class_name} - have you required it?"
86
+ end
87
+
88
+ def logger_class_name
89
+ @logger_class_name ||= ENV.fetch(ENV_VAR_LOGGER, logger_class_name_default)
90
+ end
91
+
92
+ def logger_class_name_default
93
+ @logger_class_default ||= defined?(::Rails) && ::Rails.logger ? ::Rails.logger.class.name : 'Logger'
83
94
  end
84
95
 
85
96
  def device
@@ -0,0 +1,6 @@
1
+ class Loglevel
2
+ # Local exception classes to make handling exceptions easier
3
+ class Exception < RuntimeError
4
+ BadLoggerClass = Class.new(self)
5
+ end
6
+ end
@@ -29,8 +29,8 @@ class Loglevel
29
29
  debug = classes.map do |klass|
30
30
  l = klass.logger || Struct.new(:level).new(0)
31
31
  d = l.instance_variable_get('@logdev') || Struct.new(:filename, :dev).new
32
- f = d.filename || d.dev || 'nil'
33
- v = self.class::LOGLEVELS[l.level]
32
+ f = d.filename || d.dev.inspect || 'nil'
33
+ v = l.level.is_a?(0.class) ? self.class::LOGLEVELS[l.level] : 'nil'
34
34
  "#{klass}: logger=#{l.class}, device=#{f}, level=#{v}"
35
35
  end
36
36
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Loglevel
4
- VERSION = '0.3.0'.freeze
4
+ VERSION = '0.4.0'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loglevel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominic Sayers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-05 00:00:00.000000000 Z
11
+ date: 2017-04-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple gem to control logging at runtime with an environment variable
14
14
  email:
@@ -34,6 +34,7 @@ files:
34
34
  - lib/loglevel.rb
35
35
  - lib/loglevel/active_record.rb
36
36
  - lib/loglevel/classes.rb
37
+ - lib/loglevel/exception.rb
37
38
  - lib/loglevel/help.rb
38
39
  - lib/loglevel/http_logger.rb
39
40
  - lib/loglevel/version.rb