loglevel 0.3.0 → 0.4.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 +4 -4
- data/README.md +23 -1
- data/lib/loglevel.rb +12 -1
- data/lib/loglevel/exception.rb +6 -0
- data/lib/loglevel/help.rb +2 -2
- data/lib/loglevel/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27d935b0bba808acac6f2dc481350410698cb44d
|
4
|
+
data.tar.gz: 1434b05ae0a081a45df1dfb0b62f7f3d10ce0100
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
|
data/lib/loglevel.rb
CHANGED
@@ -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
|
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
|
data/lib/loglevel/help.rb
CHANGED
@@ -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
|
|
data/lib/loglevel/version.rb
CHANGED
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.
|
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-
|
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
|