slogger 0.0.7 → 0.0.8

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.
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slogger (0.0.6)
4
+ slogger (0.0.8)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
9
  diff-lcs (1.1.2)
10
+ rake (0.9.2.2)
10
11
  rspec (2.6.0.rc2)
11
12
  rspec-core (= 2.6.0.rc2)
12
13
  rspec-expectations (= 2.6.0.rc2)
@@ -20,5 +21,6 @@ PLATFORMS
20
21
  ruby
21
22
 
22
23
  DEPENDENCIES
24
+ rake (~> 0.9)
23
25
  rspec (~> 2.6.0.rc2)
24
26
  slogger!
@@ -1,3 +1,5 @@
1
+ require 'logger'
2
+
1
3
  module Slogger
2
4
  #
3
5
  # It just exposes Ruby's Syslog with the same API of Ruby's standard Logger class. So
@@ -12,7 +14,7 @@ module Slogger
12
14
  # That's all. The Rails application will log everything to the standard syslog.
13
15
  #
14
16
  class CommonLogger < Base
15
-
17
+
16
18
  SEVERITIES = {
17
19
  :emerg => Syslog::LOG_EMERG,
18
20
  :alert => Syslog::LOG_ALERT,
@@ -55,7 +57,7 @@ module Slogger
55
57
  def initialize(app_name, severity, facility)
56
58
  super app_name, severity, facility, SEVERITIES
57
59
  end
58
-
60
+
59
61
  def log(severity, message = nil, &block)
60
62
  if block_given? and message != nil
61
63
  super(severity, message, &block)
@@ -63,11 +65,17 @@ module Slogger
63
65
  super(severity, (message || (block_given? && block.call) || @app_name), &nil)
64
66
  end
65
67
  end
66
-
67
- def add(severity, message = nil, &block)
68
- log(BRIDGE_SEVERITIES[severity], message, &block)
68
+
69
+ def add(severity, message = nil, progname = nil, &block)
70
+ (BRIDGE_SEVERITIES.keys - [:unknow]).each do |key|
71
+ if ::Logger.const_get(key.to_s.upcase) == severity
72
+ return log(BRIDGE_SEVERITIES[key], message, &block)
73
+ end
74
+ end
75
+
76
+ log(BRIDGE_SEVERITIES[:unkown], message, &block)
69
77
  end
70
-
78
+
71
79
  BRIDGE_SEVERITIES.each_key do |severity|
72
80
  define_method severity do |message = nil, &block|
73
81
  log BRIDGE_SEVERITIES[severity], message, &block
@@ -2,7 +2,7 @@ module Slogger
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 7
5
+ PATCH = 8
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -18,4 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
 
20
20
  s.add_development_dependency "rspec", "~> 2.6.0.rc2"
21
+ s.add_development_dependency "rake", "~> 0.9"
21
22
  end
@@ -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"
@@ -56,14 +56,14 @@ describe Slogger::CommonLogger do
56
56
  describe "logging" do
57
57
  describe "when is in WARN severity" do
58
58
  subject { Slogger::CommonLogger.new "test_app", :warn, :local0 }
59
-
59
+
60
60
  it { should respond_to(:add) }
61
-
61
+
62
62
  it "should log ERROR messsages with the add method" do
63
63
  Syslog.should_receive(:err).with('%s','ERROR message').and_return(Syslog)
64
- subject.add(:error, 'ERROR message')
64
+ subject.add(::Logger::ERROR, 'ERROR message')
65
65
  end
66
-
66
+
67
67
  it "should log UNKNOW messages" do
68
68
  Syslog.should_receive(:emerg).with('%s',anything).and_return(Syslog)
69
69
 
@@ -81,15 +81,14 @@ describe Slogger::CommonLogger do
81
81
 
82
82
  subject.error "ERROR message"
83
83
  end
84
-
84
+
85
85
  it "should log WARN messsages with the add method to the WARNING severity" do
86
86
  Syslog.should_receive(:warning).with('%s','WARN message').and_return(Syslog)
87
- subject.add(:warn, 'WARN message')
87
+ subject.add(::Logger::WARN, 'WARN message')
88
88
  end
89
-
90
- it "should log WARN messages to the WARNING severity" do
91
- Syslog.should_receive(:warning).with('%s',anything).and_return(Syslog)
92
89
 
90
+ it "should log WARN messages to the WARNING severity" do
91
+ Syslog.should_receive(:warning).with('%s',anything).and_return(Syslog)
93
92
  subject.warn "WARN message"
94
93
  end
95
94
 
@@ -109,24 +108,21 @@ describe Slogger::CommonLogger do
109
108
  end
110
109
  end
111
110
  end
112
-
111
+
113
112
  describe "when no message is passed to the log method" do
114
113
  it "should use the block to form the message" do
115
114
  subject.severity = :info
116
-
115
+
117
116
  messenger = mock('messenger')
118
117
  messenger.should_receive(:message).and_return('this is a message %{name}')
119
-
120
118
  Syslog.should_receive(:info).with('%s','this is a message logger').and_return(Syslog)
121
-
122
119
  subject.info { messenger.message % {:name => 'logger'} }
123
120
  end
124
121
  end
125
-
122
+
126
123
  describe "when a block is passed to log method" do
127
124
  it "should add spent time to the message" do
128
125
  Syslog.should_receive(:info).with('%s',/\[time: [0-9.]+\] a block wrapped by log/)
129
-
130
126
  subject.info "a block wrapped by log" do
131
127
  sleep(1)
132
128
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: slogger
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.7
5
+ version: 0.0.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - Leandro Silva
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-23 00:00:00 -03:00
13
+ date: 2012-04-23 00:00:00 -03:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -24,6 +24,17 @@ dependencies:
24
24
  version: 2.6.0.rc2
25
25
  type: :development
26
26
  version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: "0.9"
36
+ type: :development
37
+ version_requirements: *id002
27
38
  description: Slogger is a Ruby library to help work with standard Ruby Syslog library. Yeah! Just it.
28
39
  email:
29
40
  - leandrodoze@gmail.com