lager 0.0.1.4 → 0.2.0.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.
- data/VERSION +1 -1
- data/lib/lager.rb +65 -31
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.1
|
1
|
+
0.2.0.1
|
data/lib/lager.rb
CHANGED
@@ -1,52 +1,86 @@
|
|
1
1
|
require 'logger'
|
2
2
|
|
3
|
-
module Lager
|
4
|
-
def self.version
|
5
|
-
vpath = File.join(File.dirname(__FILE__), '..', 'VERSION')
|
6
|
-
File.read(vpath).chomp
|
7
|
-
end
|
8
|
-
|
9
|
-
|
10
3
|
# this module is meant to be mixed in at a class level
|
11
4
|
# e.g.
|
12
5
|
# class Foo
|
13
6
|
# extend Lager
|
7
|
+
# log_to '/tmp/foo.log'
|
14
8
|
# ...
|
15
9
|
# end
|
16
10
|
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
11
|
+
# It provides the class instance variable @lager, which may be used in class methods
|
12
|
+
#
|
13
|
+
# e.g. @lager.debug { "example log message" }
|
14
|
+
#
|
15
|
+
# Note that using the block invocation means that the block contents are
|
16
|
+
# not evaluated if the log level is above the message level.
|
17
|
+
#
|
18
|
+
# Make sure to call log_to within the class definition, so that class methods
|
19
|
+
# will already have @lager defined.
|
20
|
+
|
21
|
+
# For instance methods, you need to set @lager directly, within initialize
|
22
|
+
# Note: the instance layer and class layer each have their own independent
|
23
|
+
# @lager
|
24
|
+
# Here we will make the instance @lager reference the class @lager
|
25
|
+
#
|
26
|
+
# def initialize
|
27
|
+
# @lager = self.class.lager
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# Outside of initialize or a call to log_to within the class definition,
|
31
|
+
# you should only ever call the message methods: debug, info, warn, error,
|
32
|
+
# and fatal within your class code.
|
33
|
+
#
|
34
|
+
# Let the destination and log level be managed from outside.
|
35
|
+
#
|
36
|
+
module Lager
|
37
|
+
def self.version
|
38
|
+
vpath = File.join(File.dirname(__FILE__), '..', 'VERSION')
|
39
|
+
File.read(vpath).chomp
|
40
|
+
end
|
41
|
+
|
42
|
+
# create @lager
|
43
|
+
# supports IO and String (filename, presumably) for log destination
|
44
|
+
# (passed straight through to Logger.new)
|
45
|
+
# supports symbols, strings, and integers for log level
|
46
|
+
#
|
47
|
+
def log_to(dest = $stderr, level = :warn)
|
32
48
|
@lager = Logger.new dest
|
33
49
|
@lager.formatter = proc { |sev, time, progname, msg|
|
34
50
|
line = "[#{time.strftime('%Y-%m-%d %H:%M:%S')}] #{sev.to_s.upcase}: "
|
35
51
|
line << "(#{progname}) " if progname
|
36
52
|
line << msg << "\n"
|
37
53
|
}
|
38
|
-
|
39
|
-
@lager
|
54
|
+
log_level level
|
55
|
+
nil # don't expose @lager here
|
40
56
|
end
|
41
57
|
|
42
|
-
|
43
|
-
|
58
|
+
# call without argument to get the log level
|
59
|
+
# call with argument to set the log level
|
60
|
+
# :debug, 'debug', and Logger::DEBUG (0) are all supported
|
61
|
+
#
|
62
|
+
def log_level(level = nil)
|
63
|
+
raise "no @lager available" unless defined?(@lager)
|
64
|
+
case level
|
65
|
+
when nil
|
66
|
+
@lager.level
|
67
|
+
when Symbol, String
|
68
|
+
begin
|
69
|
+
@lager.level = Logger.const_get(level.to_s.upcase)
|
70
|
+
rescue NameError
|
71
|
+
raise "unknown log level #{level}"
|
72
|
+
end
|
73
|
+
when Numeric
|
74
|
+
@lager.level = level
|
75
|
+
else
|
76
|
+
raise "unknown log level: #{level}"
|
77
|
+
end
|
44
78
|
end
|
45
79
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
@lager
|
80
|
+
# provide access to the class instance variable
|
81
|
+
# typically only used within initialize
|
82
|
+
#
|
83
|
+
def lager
|
84
|
+
@lager || log_to
|
51
85
|
end
|
52
86
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
4
|
+
version: 0.2.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|