slogger 0.0.5 → 0.0.6
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/Gemfile.lock +1 -1
- data/lib/slogger/common_logger.rb +24 -12
- data/lib/slogger/version.rb +1 -1
- data/spec/slogger/common_logger_spec.rb +38 -11
- metadata +4 -4
data/Gemfile.lock
CHANGED
@@ -12,14 +12,14 @@ module Slogger
|
|
12
12
|
# That's all. The Rails application will log everything to the standard syslog.
|
13
13
|
#
|
14
14
|
class CommonLogger < Base
|
15
|
-
|
15
|
+
|
16
16
|
SEVERITIES = {
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:warning => Syslog::LOG_WARNING,
|
17
|
+
:emerg => Syslog::LOG_EMERG,
|
18
|
+
:alert => Syslog::LOG_ALERT,
|
19
|
+
:err => Syslog::LOG_ERR,
|
21
20
|
:info => Syslog::LOG_INFO,
|
22
|
-
:debug => Syslog::LOG_DEBUG
|
21
|
+
:debug => Syslog::LOG_DEBUG,
|
22
|
+
:warn => Syslog::LOG_WARNING,
|
23
23
|
}
|
24
24
|
|
25
25
|
#
|
@@ -29,7 +29,7 @@ module Slogger
|
|
29
29
|
:unknow => :emerg,
|
30
30
|
:fatal => :alert,
|
31
31
|
:error => :err,
|
32
|
-
:
|
32
|
+
:warn => :warning,
|
33
33
|
:info => :info,
|
34
34
|
:debug => :debug
|
35
35
|
}
|
@@ -44,7 +44,7 @@ module Slogger
|
|
44
44
|
#
|
45
45
|
# +app_name+:: The appliaction name to be logged
|
46
46
|
# +severity+:: The log severity (according to standard Ruby Logger): :unknow, :fatal,
|
47
|
-
# :error, :
|
47
|
+
# :error, :warn, :info, or :debug. It can be changed at anytime.
|
48
48
|
# +facility+:: A typical syslog facility: :kernel, :user, :mail, :daemon, :auth,
|
49
49
|
# :syslog, :lpr, :news, :uucp, :cron, :authpriv, :ftp,
|
50
50
|
# :local0, :local1, :local2, :local3, :local4, :local5,
|
@@ -55,14 +55,26 @@ module Slogger
|
|
55
55
|
def initialize(app_name, severity, facility)
|
56
56
|
super app_name, severity, facility, SEVERITIES
|
57
57
|
end
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
|
59
|
+
def log(severity, message = nil, &block)
|
60
|
+
if block_given? and message != nil
|
61
|
+
super(severity, message, &block)
|
62
|
+
else
|
63
|
+
super(severity, (message || (block_given? && block.call) || @app_name), &nil)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def add(severity, message = nil, &block)
|
68
|
+
log(BRIDGE_SEVERITIES[severity], message, &block)
|
69
|
+
end
|
70
|
+
|
71
|
+
BRIDGE_SEVERITIES.each_key do |severity|
|
72
|
+
define_method severity do |message = nil, &block|
|
61
73
|
log BRIDGE_SEVERITIES[severity], message, &block
|
62
74
|
end
|
63
75
|
|
64
76
|
define_method "#{severity}?" do
|
65
|
-
SEVERITIES[severity] <= SEVERITIES[@severity]
|
77
|
+
SEVERITIES[BRIDGE_SEVERITIES[severity]] <= SEVERITIES[BRIDGE_SEVERITIES[@severity]]
|
66
78
|
end
|
67
79
|
end
|
68
80
|
end
|
data/lib/slogger/version.rb
CHANGED
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), "..", "/spec_helper")
|
|
2
2
|
|
3
3
|
describe Slogger::CommonLogger do
|
4
4
|
subject { Slogger::CommonLogger.new "test_app", :debug, :local0 }
|
5
|
-
|
5
|
+
|
6
6
|
describe "valid state" do
|
7
7
|
it "should have an app_name attribute" do
|
8
8
|
subject.app_name.should == "test_app"
|
@@ -42,8 +42,8 @@ describe Slogger::CommonLogger do
|
|
42
42
|
describe "severity setup" do
|
43
43
|
it "should be possible to change severity attribute" do
|
44
44
|
subject.severity.should be :debug
|
45
|
-
subject.severity = :
|
46
|
-
subject.severity.should be :
|
45
|
+
subject.severity = :warn
|
46
|
+
subject.severity.should be :warn
|
47
47
|
subject.severity = :info
|
48
48
|
subject.severity.should be :info
|
49
49
|
end
|
@@ -54,9 +54,16 @@ describe Slogger::CommonLogger do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
describe "logging" do
|
57
|
-
describe "when is in
|
58
|
-
subject { Slogger::CommonLogger.new "test_app", :
|
59
|
-
|
57
|
+
describe "when is in WARN severity" do
|
58
|
+
subject { Slogger::CommonLogger.new "test_app", :warn, :local0 }
|
59
|
+
|
60
|
+
it { should respond_to(:add) }
|
61
|
+
|
62
|
+
it "should log ERROR messsages with the add method" do
|
63
|
+
Syslog.should_receive(:err).with('ERROR message').and_return(Syslog)
|
64
|
+
subject.add(:error, 'ERROR message')
|
65
|
+
end
|
66
|
+
|
60
67
|
it "should log UNKNOW messages" do
|
61
68
|
Syslog.should_receive(:emerg).with(anything).and_return(Syslog)
|
62
69
|
|
@@ -74,11 +81,16 @@ describe Slogger::CommonLogger do
|
|
74
81
|
|
75
82
|
subject.error "ERROR message"
|
76
83
|
end
|
77
|
-
|
78
|
-
it "should log WARNING
|
84
|
+
|
85
|
+
it "should log WARN messsages with the add method to the WARNING severity" do
|
86
|
+
Syslog.should_receive(:warning).with('WARN message').and_return(Syslog)
|
87
|
+
subject.add(:warn, 'WARN message')
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should log WARN messages to the WARNING severity" do
|
79
91
|
Syslog.should_receive(:warning).with(anything).and_return(Syslog)
|
80
92
|
|
81
|
-
subject.
|
93
|
+
subject.warn "WARN message"
|
82
94
|
end
|
83
95
|
|
84
96
|
it "shouldn't log INFO messages" do
|
@@ -97,11 +109,26 @@ describe Slogger::CommonLogger do
|
|
97
109
|
end
|
98
110
|
end
|
99
111
|
end
|
100
|
-
|
112
|
+
|
113
|
+
describe "when no message is passed to the log method" do
|
114
|
+
it "should use the block to form the message" do
|
115
|
+
subject.severity = :info
|
116
|
+
|
117
|
+
messenger = mock('messenger')
|
118
|
+
messenger.should_receive(:message).and_return('this is a message %{name}')
|
119
|
+
|
120
|
+
Syslog.should_receive(:info).with('this is a message logger').and_return(Syslog)
|
121
|
+
|
122
|
+
subject.info { messenger.message % {:name => 'logger'} }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
101
126
|
describe "when a block is passed to log method" do
|
102
127
|
it "should add spent time to the message" do
|
128
|
+
Syslog.should_receive(:info).with(/\[time: [0-9.]+\] a block wrapped by log/)
|
129
|
+
|
103
130
|
subject.info "a block wrapped by log" do
|
104
|
-
sleep(
|
131
|
+
sleep(1)
|
105
132
|
end
|
106
133
|
end
|
107
134
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slogger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Leandro Silva
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-08-24 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|