slogger 0.0.3 → 0.0.4

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/.document ADDED
@@ -0,0 +1,4 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ pkg
3
+ .rvmrc
data/Gemfile CHANGED
@@ -1,9 +1,2 @@
1
- group :development do
2
- gem "rspec"
3
- gem "bundler", "~> 1.0.0"
4
- gem "jeweler", "~> 1.5.2"
5
- end
6
-
7
- group :test do
8
- gem "rspec"
9
- end
1
+ source :rubygems
2
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,25 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ slogger (0.0.4)
5
+
1
6
  GEM
7
+ remote: http://rubygems.org/
2
8
  specs:
3
9
  diff-lcs (1.1.2)
4
- git (1.2.5)
5
- jeweler (1.5.2)
6
- bundler (~> 1.0.0)
7
- git (>= 1.2.5)
8
- rake
9
- rake (0.8.7)
10
- rspec (2.5.0)
11
- rspec-core (~> 2.5.0)
12
- rspec-expectations (~> 2.5.0)
13
- rspec-mocks (~> 2.5.0)
14
- rspec-core (2.5.1)
15
- rspec-expectations (2.5.0)
10
+ rspec (2.6.0.rc2)
11
+ rspec-core (= 2.6.0.rc2)
12
+ rspec-expectations (= 2.6.0.rc2)
13
+ rspec-mocks (= 2.6.0.rc2)
14
+ rspec-core (2.6.0.rc2)
15
+ rspec-expectations (2.6.0.rc2)
16
16
  diff-lcs (~> 1.1.2)
17
- rspec-mocks (2.5.0)
17
+ rspec-mocks (2.6.0.rc2)
18
18
 
19
19
  PLATFORMS
20
20
  ruby
21
21
 
22
22
  DEPENDENCIES
23
- bundler (~> 1.0.0)
24
- jeweler (~> 1.5.2)
25
- rspec
23
+ rspec (~> 2.6.0.rc2)
24
+ slogger!
data/README.rdoc CHANGED
@@ -44,6 +44,17 @@ Sample: message log preceded by spent time
44
44
 
45
45
  # and after, look at the syslog file of your SO ;)
46
46
 
47
+ === Slogger::CommonLogger
48
+
49
+ A useful class which exposes the Ruby's standard Syslog with the same API that
50
+ Ruby's standard Logger to be used, for example, in Rails applications.
51
+
52
+ Just add the snippet below to the config/environments/developement.rb of an Rails
53
+ application and everything will be logged thru the Ruby's standard Syslog library:
54
+
55
+ config.log_level = :info
56
+ config.logger = Slogger::CommonLogger.new "rappils", config.log_level, :local0
57
+
47
58
  === Slogger::Rack::RequestLogger
48
59
 
49
60
  A Rack middleware to log incoming requests.
@@ -58,13 +69,61 @@ Sample:
58
69
  end
59
70
 
60
71
  # and after, look at the syslog file of your SO ;)
61
-
72
+
62
73
  == Future
63
74
 
64
75
  I don't know. I think in adding more stuff sometime in the future. Let's see.
65
76
 
66
77
  For now is it.
67
78
 
79
+ == Quick view on Syslog RFC 5424
80
+
81
+ If you want to get a look at RFC 5424, which I really recommend, you can go to:
82
+
83
+ http://tools.ietf.org/html/rfc5424
84
+
85
+ According to that:
86
+
87
+ # Message Severities
88
+ #
89
+ # - Emergency: system is unusable
90
+ # - Alert: action must be taken immediately
91
+ # - Critical: critical conditions
92
+ # - Error: error conditions
93
+ # - Warning: warning conditions
94
+ # - Notice: normal but significant condition
95
+ # - Informational: informational messages
96
+ # - Debug: debug-level messages
97
+
98
+ And...
99
+
100
+ # Message Facilities
101
+ #
102
+ # - kernel messages
103
+ # - user-level messages
104
+ # - mail system
105
+ # - system daemons
106
+ # - security/authorization messages
107
+ # - messages generated internally by syslogd
108
+ # - line printer subsystem
109
+ # - network news subsystem
110
+ # - UUCP subsystem
111
+ # - clock daemon
112
+ # - security/authorization messages
113
+ # - FTP daemon
114
+ # - NTP subsystem
115
+ # - log audit
116
+ # - log alert
117
+ # - clock daemon (note 2)
118
+ # - local use 0 (local0)
119
+ # - local use 1 (local1)
120
+ # - local use 2 (local2)
121
+ # - local use 3 (local3)
122
+ # - local use 4 (local4)
123
+ # - local use 5 (local5)
124
+ # - local use 6 (local6)
125
+ # - local use 7 (local7)
126
+
68
127
  == Copyright
69
128
 
70
129
  Copyright (c) 2011 Leandro Silva (CodeZone).
data/Rakefile CHANGED
@@ -1,50 +1,5 @@
1
- require 'rubygems'
2
1
  require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'rake'
2
+ Bundler::GemHelper.install_tasks
11
3
 
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "slogger"
16
- gem.homepage = "http://github.com/leandrosilva/slogger"
17
- gem.license = "MIT"
18
- gem.summary = %Q{Slogger is a Ruby library to help work with standard Ruby Syslog library.}
19
- gem.description = %Q{Slogger is a Ruby library to help work with standard Ruby Syslog library. Yeah! Just it.}
20
- gem.email = "leandrodoze@gmail.com"
21
- gem.authors = ["Leandro Silva"]
22
- gem.files = FileList["[A-Z]*", "{lib,sample,spec}/**/*"]
23
- # Include your dependencies below. Runtime dependencies are required when using your gem,
24
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
25
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
26
- # gem.add_development_dependency 'rspec', '> 1.2.3'
27
- end
28
- Jeweler::RubygemsDotOrgTasks.new
29
-
30
- require 'rspec/core'
31
4
  require 'rspec/core/rake_task'
32
- RSpec::Core::RakeTask.new(:spec) do |spec|
33
- spec.pattern = FileList['spec/**/*_spec.rb']
34
- end
35
-
36
- RSpec::Core::RakeTask.new(:rcov) do |spec|
37
- spec.pattern = 'spec/**/*_spec.rb'
38
- end
39
-
40
- task :default => :spec
41
-
42
- require 'rake/rdoctask'
43
- Rake::RDocTask.new do |rdoc|
44
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
-
46
- rdoc.rdoc_dir = 'rdoc'
47
- rdoc.title = "slogger #{version}"
48
- rdoc.rdoc_files.include('README*')
49
- rdoc.rdoc_files.include('lib/**/*.rb')
50
- end
5
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,133 @@
1
+ module Slogger
2
+ class Base
3
+
4
+ #
5
+ # Syslog Message Severities:
6
+ #
7
+ # - Emergency: system is unusable
8
+ # - Alert: action must be taken immediately
9
+ # - Critical: critical conditions
10
+ # - Error: error conditions
11
+ # - Warning: warning conditions
12
+ # - Notice: normal but significant condition
13
+ # - Informational: informational messages
14
+ # - Debug: debug-level messages
15
+ #
16
+ SYSLOG_SEVERITIES = {
17
+ :emerg => Syslog::LOG_EMERG,
18
+ :alert => Syslog::LOG_ALERT,
19
+ :crit => Syslog::LOG_CRIT,
20
+ :err => Syslog::LOG_ERR,
21
+ :warning => Syslog::LOG_WARNING,
22
+ :notice => Syslog::LOG_NOTICE,
23
+ :info => Syslog::LOG_INFO,
24
+ :debug => Syslog::LOG_DEBUG
25
+ }
26
+
27
+ #
28
+ # Syslog Message Facilities:
29
+ #
30
+ # - kernel messages
31
+ # - user-level messages
32
+ # - mail system
33
+ # - system daemons
34
+ # - security/authorization messages
35
+ # - messages generated internally by syslogd
36
+ # - line printer subsystem
37
+ # - network news subsystem
38
+ # - UUCP subsystem
39
+ # - clock daemon
40
+ # - security/authorization messages
41
+ # - FTP daemon
42
+ # - NTP subsystem
43
+ # - log audit
44
+ # - log alert
45
+ # - clock daemon (note 2)
46
+ # - local use 0 (local0)
47
+ # - local use 1 (local1)
48
+ # - local use 2 (local2)
49
+ # - local use 3 (local3)
50
+ # - local use 4 (local4)
51
+ # - local use 5 (local5)
52
+ # - local use 6 (local6)
53
+ # - local use 7 (local7)
54
+ #
55
+ SYSLOG_FACILITIES = {
56
+ :kernel => Syslog::LOG_KERN,
57
+ :user => Syslog::LOG_USER,
58
+ :mail => Syslog::LOG_MAIL,
59
+ :daemon => Syslog::LOG_DAEMON,
60
+ :auth => Syslog::LOG_AUTH,
61
+ :syslog => Syslog::LOG_SYSLOG,
62
+ :lpr => Syslog::LOG_LPR,
63
+ :news => Syslog::LOG_NEWS,
64
+ :uucp => Syslog::LOG_UUCP,
65
+ :cron => Syslog::LOG_CRON,
66
+ :authpriv => Syslog::LOG_AUTHPRIV,
67
+ :ftp => Syslog::LOG_FTP,
68
+ :local0 => Syslog::LOG_LOCAL0,
69
+ :local1 => Syslog::LOG_LOCAL1,
70
+ :local2 => Syslog::LOG_LOCAL2,
71
+ :local3 => Syslog::LOG_LOCAL3,
72
+ :local4 => Syslog::LOG_LOCAL4,
73
+ :local5 => Syslog::LOG_LOCAL5,
74
+ :local6 => Syslog::LOG_LOCAL6,
75
+ :local7 => Syslog::LOG_LOCAL7
76
+ }
77
+
78
+ attr_reader :app_name, :severity, :facility
79
+
80
+ #
81
+ # To build a Slogger::Base instance.
82
+ #
83
+ # +app_name+:: The appliaction name to be logged
84
+ # +severity+:: The log severity.
85
+ # +facility+:: A typical syslog facility
86
+ # +custom_severity_levels+:: To be used by children classes. It defaults to
87
+ # Slogger::Base::SYSLOG_SEVERITIES.
88
+ #
89
+ # Raises an ArgumentError if app_name, severity, or facility is nil.
90
+ #
91
+ def initialize(app_name, severity, facility, custom_severity_levels=SYSLOG_SEVERITIES)
92
+ raise_argument_error_to_required_parameter "app_name" unless app_name
93
+ raise_argument_error_to_required_parameter "severity" unless severity
94
+ raise_argument_error_to_required_parameter "facility" unless facility
95
+
96
+ raise_argument_error_to_invalid_parameter "severity", "SEVERITIES" unless custom_severity_levels[severity]
97
+ raise_argument_error_to_invalid_parameter "facility", "FACILITIES" unless SYSLOG_FACILITIES[facility]
98
+
99
+ @app_name = app_name
100
+ @severity = severity
101
+ @severity_as_int = custom_severity_levels[severity]
102
+ @facility = facility
103
+ @facility_as_int = SYSLOG_FACILITIES[facility]
104
+ @custom_severity_levels = custom_severity_levels
105
+ end
106
+
107
+ def severity=(value)
108
+ raise_argument_error_to_invalid_parameter "severity", "SEVERITIES" unless @custom_severity_levels[value]
109
+
110
+ @severity = value
111
+ @severity_as_int = @custom_severity_levels[severity]
112
+ end
113
+
114
+ def log(severity, message, &block)
115
+ return if SYSLOG_SEVERITIES[severity] > @severity_as_int
116
+
117
+ if block_given?
118
+ benchmark = Benchmark.measure &block
119
+ message = "[time: #{benchmark.real}] #{message}"
120
+ end
121
+
122
+ Syslog.open(@app_name, Syslog::LOG_PID, @facility_as_int) { |s| s.send severity, message }
123
+ end
124
+
125
+ def raise_argument_error_to_required_parameter(param)
126
+ raise ArgumentError, "The '#{param}' parameter is required."
127
+ end
128
+
129
+ def raise_argument_error_to_invalid_parameter(param, options)
130
+ raise ArgumentError, "The '#{param}' parameter is invalid. Inspect the #{options} constant to know the options."
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,65 @@
1
+ module Slogger
2
+ #
3
+ # It just exposes Ruby's Syslog with the same API of Ruby's standard Logger class. So
4
+ # you can use it in a Rails application, for instance.
5
+ #
6
+ # For example, add the snippet below to the config/environments/developement.rb of an
7
+ # Rails application:
8
+ #
9
+ # config.log_level = :info
10
+ # config.logger = Slogger::CommonLogger.new "rappils", config.log_level, :local0
11
+ #
12
+ # That's all. The Rails application will log everything to the standard syslog.
13
+ #
14
+ class CommonLogger < Base
15
+
16
+ SEVERITIES = {
17
+ :unknow => Syslog::LOG_EMERG,
18
+ :fatal => Syslog::LOG_ALERT,
19
+ :error => Syslog::LOG_ERR,
20
+ :warning => Syslog::LOG_WARNING,
21
+ :info => Syslog::LOG_INFO,
22
+ :debug => Syslog::LOG_DEBUG
23
+ }
24
+
25
+ #
26
+ # Bridge between standard Ruby Logger and Syslog
27
+ #
28
+ BRIDGE_SEVERITIES = {
29
+ :unknow => :emerg,
30
+ :fatal => :alert,
31
+ :error => :err,
32
+ :warning => :warning,
33
+ :info => :info,
34
+ :debug => :debug
35
+ }
36
+
37
+ #
38
+ # Just a little sugar
39
+ #
40
+ FACILITIES = ::Slogger::Base::SYSLOG_FACILITIES
41
+
42
+ #
43
+ # To build a Slogger::CommonLogger instance.
44
+ #
45
+ # +app_name+:: The appliaction name to be logged
46
+ # +severity+:: The log severity (according to standard Ruby Logger): :unknow, :fatal,
47
+ # :error, :warning, :info, or :debug. It can be changed at anytime.
48
+ # +facility+:: A typical syslog facility: :kernel, :user, :mail, :daemon, :auth,
49
+ # :syslog, :lpr, :news, :uucp, :cron, :authpriv, :ftp,
50
+ # :local0, :local1, :local2, :local3, :local4, :local5,
51
+ # :local6, or :local7
52
+ #
53
+ # Raises an ArgumentError if app_name, severity, or facility is nil.
54
+ #
55
+ def initialize(app_name, severity, facility)
56
+ super app_name, severity, facility, SEVERITIES
57
+ end
58
+
59
+ SEVERITIES.each_key do |severity|
60
+ define_method severity do |message, &block|
61
+ log BRIDGE_SEVERITIES[severity], message, &block
62
+ end
63
+ end
64
+ end
65
+ end
@@ -2,49 +2,27 @@ module Slogger
2
2
  #
3
3
  # The wrapper for standard Ruby Syslog library.
4
4
  #
5
- class Logger
6
- SEVERITY = {
7
- :crit => 0,
8
- :emerg => 1,
9
- :alert => 2,
10
- :err => 3,
11
- :warning => 4,
12
- :notice => 5,
13
- :info => 6,
14
- :debug => 7
15
- }
16
-
17
- FACILITY = {
18
- :user => Syslog::LOG_USER,
19
- :mail => Syslog::LOG_MAIL,
20
- :daemon => Syslog::LOG_DAEMON,
21
- :auth => Syslog::LOG_AUTH,
22
- :syslog => Syslog::LOG_SYSLOG,
23
- :lpr => Syslog::LOG_LPR,
24
- :news => Syslog::LOG_NEWS,
25
- :uucp => Syslog::LOG_UUCP,
26
- :cron => Syslog::LOG_CRON,
27
- :authpriv => Syslog::LOG_AUTHPRIV,
28
- :ftp => Syslog::LOG_FTP,
29
- :local0 => Syslog::LOG_LOCAL0,
30
- :local1 => Syslog::LOG_LOCAL1,
31
- :local2 => Syslog::LOG_LOCAL2,
32
- :local3 => Syslog::LOG_LOCAL3,
33
- :local4 => Syslog::LOG_LOCAL4,
34
- :local5 => Syslog::LOG_LOCAL5,
35
- :local6 => Syslog::LOG_LOCAL6,
36
- :local7 => Syslog::LOG_LOCAL7
37
- }
38
-
39
- attr_reader :app_name, :severity, :facility
5
+ # Sample:
6
+ #
7
+ # slogger = Slogger::Logger.new "sample_app", :info, :local0
8
+ # slogger.info "A good info"
9
+ # slogger.debug "A deep info (oops! it'll not be logged)"
10
+ #
11
+ class Logger < Base
40
12
 
13
+ #
14
+ # Just sugars
15
+ #
16
+ SEVERITIES = ::Slogger::Base::SYSLOG_SEVERITIES
17
+ FACILITIES = ::Slogger::Base::SYSLOG_FACILITIES
18
+
41
19
  #
42
20
  # To build a Slogger::Logger instance.
43
21
  #
44
22
  # +app_name+:: The appliaction name to be logged
45
- # +severity+:: The log severity: :crit, :emerg, :alert, :err, :warning, :notice,
23
+ # +severity+:: The log severity: :emerg, :alert, :crit, :err, :warning, :notice,
46
24
  # :info, or :debug. It can be changed at anytime.
47
- # +facility+:: A typical syslog facility: :user, :mail, :daemon, :auth,
25
+ # +facility+:: A typical syslog facility: :kernel, :user, :mail, :daemon, :auth,
48
26
  # :syslog, :lpr, :news, :uucp, :cron, :authpriv, :ftp,
49
27
  # :local0, :local1, :local2, :local3, :local4, :local5,
50
28
  # :local6, or :local7
@@ -52,57 +30,13 @@ module Slogger
52
30
  # Raises an ArgumentError if app_name, severity, or facility is nil.
53
31
  #
54
32
  def initialize(app_name, severity, facility)
55
- raise_argument_error_to_required_parameter "app_name" unless app_name
56
- raise_argument_error_to_required_parameter "severity" unless severity
57
- raise_argument_error_to_required_parameter "facility" unless facility
58
-
59
- raise_argument_error_to_invalid_parameter "severity", "SEVERITY" unless SEVERITY[severity]
60
- raise_argument_error_to_invalid_parameter "facility", "FACILITY" unless FACILITY[facility]
61
-
62
- @app_name = app_name
63
- @severity = severity
64
- @severity_as_int = SEVERITY[severity]
65
- @facility = facility
66
- @facility_as_int = FACILITY[facility]
33
+ super app_name, severity, facility
67
34
  end
68
35
 
69
- SEVERITY.each_key do |severity|
36
+ SEVERITIES.each_key do |severity|
70
37
  define_method severity do |message, &block|
71
- log(severity, message, &block)
38
+ log severity, message, &block
72
39
  end
73
40
  end
74
-
75
- def severity=(value)
76
- raise_argument_error_to_invalid_parameter "severity", "SEVERITY" unless SEVERITY[value]
77
-
78
- @severity = value
79
- @severity_as_int = SEVERITY[value]
80
- end
81
-
82
- private
83
-
84
- def log(severity, message, &block)
85
- return if SEVERITY[severity] > @severity_as_int
86
-
87
- if block_given?
88
- began_at = Time.now
89
-
90
- yield
91
-
92
- now = Time.now
93
- end_at = now - began_at
94
- message = "[#{end_at}s] #{message}"
95
- end
96
-
97
- Syslog.open(@app_name, Syslog::LOG_PID, @facility_as_int) { |s| s.send severity, message }
98
- end
99
-
100
- def raise_argument_error_to_required_parameter(param)
101
- raise ArgumentError, "The '#{param}' parameter is required."
102
- end
103
-
104
- def raise_argument_error_to_invalid_parameter(param, options)
105
- raise ArgumentError, "The '#{param}' parameter is invalid. Inspect the #{options} constant to know the options."
106
- end
107
41
  end
108
42
  end
@@ -0,0 +1,8 @@
1
+ module Slogger
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ PATCH = 4
6
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
+ end
8
+ end
data/lib/slogger.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  require "syslog"
2
+ require "benchmark"
2
3
 
4
+ require "slogger/base"
3
5
  require "slogger/logger"
6
+ require "slogger/common_logger"
4
7
  require "slogger/request_logger"
data/slogger.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "slogger/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "slogger"
7
+ s.version = Slogger::Version::STRING
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Leandro Silva"]
10
+ s.email = ["leandrodoze@gmail.com"]
11
+ s.homepage = "http://github.com/leandrosilva/slogger"
12
+ s.summary = %Q{Slogger is a Ruby library to help work with standard Ruby Syslog library.}
13
+ s.description = %Q{Slogger is a Ruby library to help work with standard Ruby Syslog library. Yeah! Just it.}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency "rspec", "~> 2.6.0.rc2"
21
+ end
@@ -0,0 +1,109 @@
1
+ require File.join(File.dirname(__FILE__), "..", "/spec_helper")
2
+
3
+ describe Slogger::CommonLogger do
4
+ subject { Slogger::CommonLogger.new "test_app", :debug, :local0 }
5
+
6
+ describe "valid state" do
7
+ it "should have an app_name attribute" do
8
+ subject.app_name.should == "test_app"
9
+ end
10
+
11
+ it "should have a severity attribute" do
12
+ subject.severity.should == :debug
13
+ end
14
+
15
+ it "should have a facility attribute" do
16
+ subject.facility.should == :local0
17
+ end
18
+ end
19
+
20
+ describe "invalid state" do
21
+ it "should raise ArgumentError if doesn't have app_name" do
22
+ lambda { Slogger::CommonLogger.new nil, :debug, :local0 }.should raise_error
23
+ end
24
+
25
+ it "should raise ArgumentError if doesn't have severity" do
26
+ lambda { Slogger::CommonLogger.new "test_app", nil, :local0 }.should raise_error
27
+ end
28
+
29
+ it "should raise ArgumentError if doesn't have facility" do
30
+ lambda { Slogger::CommonLogger.new "test_app", :debug, nil }.should raise_error
31
+ end
32
+
33
+ it "should raise ArgumentError if severity level is invalid" do
34
+ lambda { Slogger::CommonLogger.new "test_app", :junk, :local0 }.should raise_error
35
+ end
36
+
37
+ it "should raise ArgumentError if facility is invalid" do
38
+ lambda { Slogger::CommonLogger.new "test_app", :describe, :junk }.should raise_error
39
+ end
40
+ end
41
+
42
+ describe "severity setup" do
43
+ it "should be possible to change severity attribute" do
44
+ subject.severity.should be :debug
45
+ subject.severity = :warning
46
+ subject.severity.should be :warning
47
+ subject.severity = :info
48
+ subject.severity.should be :info
49
+ end
50
+
51
+ it "should raise ArgumentError if try to change severity attribute to a invalid one" do
52
+ lambda { subject.severity = :junk }.should raise_error
53
+ end
54
+ end
55
+
56
+ describe "logging" do
57
+ describe "when is in WARNING severity" do
58
+ subject { Slogger::CommonLogger.new "test_app", :warning, :local0 }
59
+
60
+ it "should log UNKNOW messages" do
61
+ Syslog.should_receive(:emerg).with(anything).and_return(Syslog)
62
+
63
+ subject.unknow "UNKNOW message"
64
+ end
65
+
66
+ it "should log FATAL messages" do
67
+ Syslog.should_receive(:alert).with(anything).and_return(Syslog)
68
+
69
+ subject.fatal "FATAL message"
70
+ end
71
+
72
+ it "should log ERROR messages" do
73
+ Syslog.should_receive(:err).with(anything).and_return(Syslog)
74
+
75
+ subject.error "ERROR message"
76
+ end
77
+
78
+ it "should log WARNING messages" do
79
+ Syslog.should_receive(:warning).with(anything).and_return(Syslog)
80
+
81
+ subject.warning "WARNING message"
82
+ end
83
+
84
+ it "shouldn't log INFO messages" do
85
+ Syslog.should_not_receive(:info).with(anything).and_return(Syslog)
86
+
87
+ subject.info "INFO message"
88
+ end
89
+
90
+ describe "but when severity is changed to INFO" do
91
+ it "should log INFO messages" do
92
+ subject.severity = :info
93
+
94
+ Syslog.should_receive(:info).with(anything).and_return(Syslog)
95
+
96
+ subject.info "INFO message"
97
+ end
98
+ end
99
+ end
100
+
101
+ describe "when a block is passed to log method" do
102
+ it "should add spent time to the message" do
103
+ subject.info "a block wrapped by log" do
104
+ sleep(2)
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -58,15 +58,13 @@ describe Slogger::Logger do
58
58
  subject { Slogger::Logger.new "test_app", :warning, :local0 }
59
59
 
60
60
  it "should log WARNING messages" do
61
- Syslog.stub!(:warning).with(anything).and_return(Syslog)
62
- Syslog.should_receive(:warning).and_return(Syslog)
61
+ Syslog.should_receive(:warning).with(anything).and_return(Syslog)
63
62
 
64
63
  subject.warning "WARNING message"
65
64
  end
66
65
 
67
66
  it "shouldn't log INFO messages" do
68
- Syslog.stub!(:info).with(anything).and_return(Syslog)
69
- Syslog.should_not_receive(:info).and_return(Syslog)
67
+ Syslog.should_not_receive(:info).with(anything).and_return(Syslog)
70
68
 
71
69
  subject.info "INFO message"
72
70
  end
@@ -75,8 +73,7 @@ describe Slogger::Logger do
75
73
  it "should log INFO messages" do
76
74
  subject.severity = :info
77
75
 
78
- Syslog.stub!(:info).with(anything).and_return(Syslog)
79
- Syslog.should_receive(:info).and_return(Syslog)
76
+ Syslog.should_receive(:info).with(anything).and_return(Syslog)
80
77
 
81
78
  subject.info "INFO message"
82
79
  end
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1 @@
1
- ENV['RACK_ENV'] = "test"
2
-
3
- require "rubygems"
4
- require "bundler"
5
-
6
- require File.join(File.dirname(__FILE__), "..", "lib", "slogger.rb")
7
-
8
- #
9
- # RSpec setup
10
- #
11
-
12
- require "rspec"
1
+ require "slogger"
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: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Leandro Silva
@@ -15,78 +15,57 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-21 00:00:00 -03:00
18
+ date: 2011-04-29 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: rspec
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
32
23
  prerelease: false
33
- type: :development
34
- requirement: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: bundler
37
- version_requirements: &id002 !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
38
25
  none: false
39
26
  requirements:
40
27
  - - ~>
41
28
  - !ruby/object:Gem::Version
42
- hash: 23
29
+ hash: 15424049
43
30
  segments:
44
- - 1
45
- - 0
31
+ - 2
32
+ - 6
46
33
  - 0
47
- version: 1.0.0
48
- prerelease: false
49
- type: :development
50
- requirement: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: jeweler
53
- version_requirements: &id003 !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
56
- - - ~>
57
- - !ruby/object:Gem::Version
58
- hash: 7
59
- segments:
60
- - 1
61
- - 5
34
+ - rc
62
35
  - 2
63
- version: 1.5.2
64
- prerelease: false
36
+ version: 2.6.0.rc2
65
37
  type: :development
66
- requirement: *id003
38
+ version_requirements: *id001
67
39
  description: Slogger is a Ruby library to help work with standard Ruby Syslog library. Yeah! Just it.
68
- email: leandrodoze@gmail.com
40
+ email:
41
+ - leandrodoze@gmail.com
69
42
  executables: []
70
43
 
71
44
  extensions: []
72
45
 
73
- extra_rdoc_files:
74
- - README.rdoc
46
+ extra_rdoc_files: []
47
+
75
48
  files:
49
+ - .document
50
+ - .gitignore
76
51
  - Gemfile
77
52
  - Gemfile.lock
78
53
  - README.rdoc
79
54
  - Rakefile
80
- - VERSION
81
55
  - lib/slogger.rb
56
+ - lib/slogger/base.rb
57
+ - lib/slogger/common_logger.rb
82
58
  - lib/slogger/logger.rb
83
59
  - lib/slogger/request_logger.rb
60
+ - lib/slogger/version.rb
61
+ - slogger.gemspec
62
+ - spec/slogger/common_logger_spec.rb
84
63
  - spec/slogger/logger_spec.rb
85
64
  - spec/spec_helper.rb
86
65
  has_rdoc: true
87
66
  homepage: http://github.com/leandrosilva/slogger
88
- licenses:
89
- - MIT
67
+ licenses: []
68
+
90
69
  post_install_message:
91
70
  rdoc_options: []
92
71
 
@@ -118,5 +97,6 @@ signing_key:
118
97
  specification_version: 3
119
98
  summary: Slogger is a Ruby library to help work with standard Ruby Syslog library.
120
99
  test_files:
100
+ - spec/slogger/common_logger_spec.rb
121
101
  - spec/slogger/logger_spec.rb
122
102
  - spec/spec_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.3