slogger 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,7 @@ 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
17
  :unknow => Syslog::LOG_EMERG,
18
18
  :fatal => Syslog::LOG_ALERT,
@@ -38,7 +38,7 @@ module Slogger
38
38
  # Just a little sugar
39
39
  #
40
40
  FACILITIES = ::Slogger::Base::SYSLOG_FACILITIES
41
-
41
+
42
42
  #
43
43
  # To build a Slogger::CommonLogger instance.
44
44
  #
@@ -60,6 +60,10 @@ module Slogger
60
60
  define_method severity do |message, &block|
61
61
  log BRIDGE_SEVERITIES[severity], message, &block
62
62
  end
63
+
64
+ define_method "#{severity}?" do
65
+ SEVERITIES[severity] <= SEVERITIES[@severity]
66
+ end
63
67
  end
64
68
  end
65
69
  end
@@ -2,7 +2,7 @@ module Slogger
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 4
5
+ PATCH = 5
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -7,16 +7,16 @@ describe Slogger::CommonLogger do
7
7
  it "should have an app_name attribute" do
8
8
  subject.app_name.should == "test_app"
9
9
  end
10
-
10
+
11
11
  it "should have a severity attribute" do
12
12
  subject.severity.should == :debug
13
13
  end
14
-
14
+
15
15
  it "should have a facility attribute" do
16
16
  subject.facility.should == :local0
17
17
  end
18
18
  end
19
-
19
+
20
20
  describe "invalid state" do
21
21
  it "should raise ArgumentError if doesn't have app_name" do
22
22
  lambda { Slogger::CommonLogger.new nil, :debug, :local0 }.should raise_error
@@ -29,11 +29,11 @@ describe Slogger::CommonLogger do
29
29
  it "should raise ArgumentError if doesn't have facility" do
30
30
  lambda { Slogger::CommonLogger.new "test_app", :debug, nil }.should raise_error
31
31
  end
32
-
32
+
33
33
  it "should raise ArgumentError if severity level is invalid" do
34
34
  lambda { Slogger::CommonLogger.new "test_app", :junk, :local0 }.should raise_error
35
35
  end
36
-
36
+
37
37
  it "should raise ArgumentError if facility is invalid" do
38
38
  lambda { Slogger::CommonLogger.new "test_app", :describe, :junk }.should raise_error
39
39
  end
@@ -47,12 +47,12 @@ describe Slogger::CommonLogger do
47
47
  subject.severity = :info
48
48
  subject.severity.should be :info
49
49
  end
50
-
50
+
51
51
  it "should raise ArgumentError if try to change severity attribute to a invalid one" do
52
52
  lambda { subject.severity = :junk }.should raise_error
53
53
  end
54
54
  end
55
-
55
+
56
56
  describe "logging" do
57
57
  describe "when is in WARNING severity" do
58
58
  subject { Slogger::CommonLogger.new "test_app", :warning, :local0 }
@@ -68,7 +68,7 @@ describe Slogger::CommonLogger do
68
68
 
69
69
  subject.fatal "FATAL message"
70
70
  end
71
-
71
+
72
72
  it "should log ERROR messages" do
73
73
  Syslog.should_receive(:err).with(anything).and_return(Syslog)
74
74
 
@@ -80,19 +80,19 @@ describe Slogger::CommonLogger do
80
80
 
81
81
  subject.warning "WARNING message"
82
82
  end
83
-
83
+
84
84
  it "shouldn't log INFO messages" do
85
85
  Syslog.should_not_receive(:info).with(anything).and_return(Syslog)
86
86
 
87
87
  subject.info "INFO message"
88
88
  end
89
-
89
+
90
90
  describe "but when severity is changed to INFO" do
91
91
  it "should log INFO messages" do
92
92
  subject.severity = :info
93
-
93
+
94
94
  Syslog.should_receive(:info).with(anything).and_return(Syslog)
95
-
95
+
96
96
  subject.info "INFO message"
97
97
  end
98
98
  end
@@ -106,4 +106,19 @@ describe Slogger::CommonLogger do
106
106
  end
107
107
  end
108
108
  end
109
+
110
+ describe "severity appliance checking" do
111
+ it "should validate appliance for selected severity" do
112
+ subject.debug?.should be_true
113
+ end
114
+
115
+ it "should validate appliance for less restrict severities" do
116
+ subject.error?.should be_true
117
+ end
118
+
119
+ it "should invalidate appliance for more restrict severities" do
120
+ subject.severity = :info
121
+ subject.debug?.should be_false
122
+ end
123
+ end
109
124
  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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
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-04-29 00:00:00 -03:00
18
+ date: 2011-05-18 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency