logjam 0.0.3 → 1.0.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.
- data/README +63 -7
- data/lib/logjam/logjam.rb +7 -0
- data/lib/logjam/version.rb +3 -0
- data/lib/logjam.rb +1 -0
- metadata +35 -36
data/README
CHANGED
@@ -49,7 +49,8 @@ which the following keys are recognised (either as Strings or Symbols)...
|
|
49
49
|
----------------------- --------------------------------------------------
|
50
50
|
default A boolean indicating whether this logger is the
|
51
51
|
default (i.e. the one to be used when no other
|
52
|
-
fits the bill).
|
52
|
+
fits the bill). Only one logger should be declared
|
53
|
+
as a default.
|
53
54
|
datetime_format The date/time format to be used by the logger. See
|
54
55
|
the documentation for the standard Ruby Logger
|
55
56
|
class for more details.
|
@@ -58,14 +59,16 @@ which the following keys are recognised (either as Strings or Symbols)...
|
|
58
59
|
recognised in this value. STDOUT and STDERR are
|
59
60
|
translated to mean the standard output or error
|
60
61
|
streams respectively.
|
61
|
-
level The logging level to set on the logger.
|
62
|
+
level The logging level to set on the logger. If not
|
63
|
+
explicitly specified this defaults to DEBUG.
|
62
64
|
max_size When rotation is set to an integer value this value
|
63
65
|
can be set to indicate the maximum permitted file
|
64
66
|
size for a log file.
|
65
67
|
name The name to associate with the logger. This allows
|
66
68
|
loggers to be tied to classes or for the creation
|
67
69
|
of aliases that tie multiple names to a single
|
68
|
-
logger.
|
70
|
+
logger. Note that you should always use Strings
|
71
|
+
(and not Symbols) when specifying aliases.
|
69
72
|
rotation The frequency with which the log file is rotated.
|
70
73
|
This may be an integer to indicate how many old log
|
71
74
|
files are retained or may be a String such as
|
@@ -86,7 +89,9 @@ fashion. In this case the method searches for a configuration file that it can
|
|
86
89
|
use given a default set of files names (basically logging.yaml, logging.yml and
|
87
90
|
logging.json in the current working directory and in a subdirectory of the
|
88
91
|
current working directory called config). The first of these files that it finds
|
89
|
-
it attempts to use as configuration for the logging set up.
|
92
|
+
it attempts to use as configuration for the logging set up. If it doesn't find
|
93
|
+
a configuration file then this type of call becomes equivalent to passing an
|
94
|
+
empty Hash to the configure() method.
|
90
95
|
|
91
96
|
See the end of this document for some example configurations.
|
92
97
|
|
@@ -114,9 +119,12 @@ specified or if a matching logger does not exist, the class will fall back in
|
|
114
119
|
using the default logger.
|
115
120
|
|
116
121
|
Once this line has been added to the class definition it will cause the class to
|
117
|
-
be extended with
|
118
|
-
|
119
|
-
|
122
|
+
be extended with three methods - two class level methods (one called log() and
|
123
|
+
one called log=()) and an instance level method called log(). The log() methods
|
124
|
+
retrieve the Logger instance to be used by the class instances. The log=()
|
125
|
+
method allows the Logger instance associated with a class to be altered. Note
|
126
|
+
the instance level log() method will only be added if an existing method with
|
127
|
+
that name does not already exist on the class.
|
120
128
|
|
121
129
|
The following complete (although contrived) example gives an overview of how
|
122
130
|
this would work...
|
@@ -263,3 +271,51 @@ JSON
|
|
263
271
|
{"file": "STDOUT",
|
264
272
|
"name": "verbose"}],
|
265
273
|
"aliases": {"database":"verbose"}}
|
274
|
+
|
275
|
+
The following configuration can be used as an example of how to drive logging
|
276
|
+
from different parts of the code to different destinations. The configuration
|
277
|
+
declares two loggers which deliver their output to two different log files and
|
278
|
+
then declares aliases for those loggers that can be used to divide up the
|
279
|
+
logging coming from different areas of the code.
|
280
|
+
|
281
|
+
Hash
|
282
|
+
{:loggers => [{:default => true,
|
283
|
+
:file => "./log/main.log",
|
284
|
+
:name => "main"},
|
285
|
+
{:file => "./log/secondary.log",
|
286
|
+
:name => "secondary"}],
|
287
|
+
:aliases => {"database" => "secondary",
|
288
|
+
"model" => "secondary",
|
289
|
+
"controller" => "main"}}
|
290
|
+
|
291
|
+
YAML
|
292
|
+
---
|
293
|
+
:loggers:
|
294
|
+
- :default: true
|
295
|
+
:file: ./log/main.log
|
296
|
+
:name: main
|
297
|
+
- :file: ./log/secondary.log
|
298
|
+
:name: secondary
|
299
|
+
:aliases:
|
300
|
+
database: secondary
|
301
|
+
model: secondary
|
302
|
+
controller: main
|
303
|
+
|
304
|
+
JSON
|
305
|
+
{"loggers": [{"default":true,
|
306
|
+
"file": "./log/main.log",
|
307
|
+
"name": "main"},
|
308
|
+
{"file": "./log/secondary.log",
|
309
|
+
"name": "secondary"}],
|
310
|
+
"aliases": {"database":"secondary",
|
311
|
+
"model": "secondary",
|
312
|
+
"controller": "main"}}
|
313
|
+
|
314
|
+
Testing
|
315
|
+
-------
|
316
|
+
LogJam uses the test-unit Ruby library for testing. The best approach to running
|
317
|
+
the tests are to create a new gemset (assuming you're using RVM), do a bundle
|
318
|
+
install on this gemset from within the LogJam root directory and then use a
|
319
|
+
command such as the following to run the tests...
|
320
|
+
|
321
|
+
$> ruby -I./lib -I./test ./test/unit/test_logjam.rb
|
data/lib/logjam/logjam.rb
CHANGED
@@ -69,6 +69,7 @@ module LogJam
|
|
69
69
|
# to indicate use of the default logger.
|
70
70
|
def self.apply(target, name=nil)
|
71
71
|
target.extend(LogJam.get_module(name))
|
72
|
+
target.send(:define_method, :log) {LogJam.get_logger(name)} if !target.method_defined?(:log)
|
72
73
|
end
|
73
74
|
|
74
75
|
# This method attempts to fetch the logger for a specified name. If this
|
@@ -86,6 +87,12 @@ module LogJam
|
|
86
87
|
def self.names
|
87
88
|
@@logjam_loggers.keys.compact
|
88
89
|
end
|
90
|
+
|
91
|
+
# A convenience mechanism that provides an instance level access to the
|
92
|
+
# class level logger.
|
93
|
+
def log
|
94
|
+
self.class.log
|
95
|
+
end
|
89
96
|
|
90
97
|
private
|
91
98
|
|
data/lib/logjam.rb
CHANGED
metadata
CHANGED
@@ -1,37 +1,40 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: logjam
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.3
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Black North
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-01-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: json
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
24
22
|
type: :runtime
|
25
|
-
|
26
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: LogJam is a library to simplify the use of logging across libraries and
|
31
|
+
applications.
|
27
32
|
email: ruby@blacknorth.com
|
28
33
|
executables: []
|
29
|
-
|
30
34
|
extensions: []
|
31
|
-
|
32
35
|
extra_rdoc_files: []
|
33
|
-
|
34
|
-
|
36
|
+
files:
|
37
|
+
- lib/logjam/version.rb
|
35
38
|
- lib/logjam/logjam_logger.rb
|
36
39
|
- lib/logjam/logjam.rb
|
37
40
|
- lib/logjam/exceptions.rb
|
@@ -40,30 +43,26 @@ files:
|
|
40
43
|
- README
|
41
44
|
homepage: https://github.com/free-beer/LogJam
|
42
45
|
licenses: []
|
43
|
-
|
44
46
|
post_install_message:
|
45
47
|
rdoc_options: []
|
46
|
-
|
47
|
-
require_paths:
|
48
|
+
require_paths:
|
48
49
|
- lib
|
49
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
51
|
none: false
|
51
|
-
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
57
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version:
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
61
62
|
requirements: []
|
62
|
-
|
63
63
|
rubyforge_project:
|
64
|
-
rubygems_version: 1.8.
|
64
|
+
rubygems_version: 1.8.24
|
65
65
|
signing_key:
|
66
66
|
specification_version: 3
|
67
67
|
summary: A library to aggregate logging.
|
68
68
|
test_files: []
|
69
|
-
|