takihiro-simple_syslog_logger 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/MIT-LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ Copyright (c) 2009 Hiroaki Takisawa
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+
data/README ADDED
File without changes
@@ -0,0 +1,74 @@
1
+ require 'syslog'
2
+ require 'active_support'
3
+
4
+ class SimpleSyslogLogger
5
+
6
+ VERSION = '0.0.4'
7
+
8
+ def initialize(ident='', options=nil, facility=nil)
9
+ @syslog = Syslog.open(ident, options, facility)
10
+ @logger_map = {
11
+ :fatal => Syslog::LOG_ALERT,
12
+ :error => Syslog::LOG_ERR,
13
+ :warn => Syslog::LOG_WARNING,
14
+ :info => Syslog::LOG_INFO,
15
+ :debug => Syslog::LOG_DEBUG,
16
+ :unknown => Syslog::LOG_DEBUG,
17
+ }
18
+
19
+ self.level = @logger_map[:debug]
20
+ update_logger_map
21
+ end
22
+
23
+ attr_reader :level
24
+
25
+ def add(severity, message = nil, progname = nil, &block)
26
+ message = (message || (block && block.call) || progname).to_s
27
+ @syslog.log(severity, message)
28
+ end
29
+
30
+ def level=(level)
31
+ @level = level
32
+ @logger_map.each do |severity, syslog_severity|
33
+ instance_eval <<-SRC
34
+ def #{severity}?
35
+ #{syslog_severity <= @level ? 'true' : 'false'}
36
+ end
37
+ SRC
38
+ end
39
+ end
40
+
41
+ def update_logger_map(map={})
42
+ @logger_map.update(map)
43
+ @logger_map.each do |severity, syslog_severity|
44
+ instance_eval <<-SRC
45
+ def #{severity}(message = nil, progname = nil, &block)
46
+ #{syslog_severity <= @level ?
47
+ "add(#{syslog_severity}, message, progname, &block)" :
48
+ 'true'}
49
+ end
50
+ SRC
51
+ end
52
+ end
53
+
54
+ cattr_accessor :silencer
55
+ self.silencer = true
56
+
57
+ def silence(temporary_level = Syslog::LOG_ERR)
58
+ self.add(Syslog::LOG_DEBUG,
59
+ "#{self.class}#silence exist because only compatibility.")
60
+ begin
61
+ old_logger_level = @level
62
+ self.level = temporary_level
63
+ yield self
64
+ ensure
65
+ self.level = old_logger_level
66
+ end
67
+ end
68
+
69
+ def close
70
+ @syslog.close
71
+ @syslog = nil
72
+ end
73
+
74
+ end
@@ -0,0 +1,117 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'simple_syslog_logger'
4
+
5
+ describe SimpleSyslogLogger do
6
+
7
+ it 'should have version constant' do
8
+ SimpleSyslogLogger::VERSION.should match(/\d+\.\d+\.\d+/)
9
+ end
10
+
11
+ describe 'initialize' do
12
+
13
+ before :each do
14
+ @ident = 'simple_syslog_logger'
15
+ @options = Syslog::LOG_PID | Syslog::LOG_CONS
16
+ @facility = Syslog::LOG_USER
17
+ end
18
+
19
+ it 'should call Syslog.open with args passed initialize' do
20
+ Syslog.should_receive(:open).with(@ident, @options, @facility)
21
+ SimpleSyslogLogger.new(@ident, @options, @facility)
22
+ end
23
+
24
+ end
25
+
26
+ describe 'level' do
27
+
28
+ before :all do
29
+ @logger = SimpleSyslogLogger.new
30
+ end
31
+
32
+ after :all do
33
+ @logger.close
34
+ end
35
+
36
+ it 'should get current level' do
37
+ @logger.should respond_to(:level)
38
+ end
39
+
40
+ it 'should default level is debug' do
41
+ @logger.level == Syslog::LOG_DEBUG
42
+ end
43
+
44
+ end
45
+
46
+ describe 'level methods' do
47
+
48
+ before :each do
49
+ Syslog.stub!(:open => stub('syslog'))
50
+ @logger = SimpleSyslogLogger.new
51
+ end
52
+
53
+ [:fatal, :error, :warn, :info, :debug, :unknown].each do |severity|
54
+
55
+ it "should have ##{severity}" do
56
+ @logger.should respond_to(severity)
57
+ end
58
+
59
+ it "should have ##{severity}?" do
60
+ @logger.should respond_to("#{severity}?")
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+ describe 'silencer' do
68
+
69
+ before :each do
70
+ Syslog.stub!(:open => stub('syslog', :log => true))
71
+ @logger = SimpleSyslogLogger.new
72
+ end
73
+
74
+ it 'should have silencer methods' do
75
+ SimpleSyslogLogger.should respond_to(:silencer)
76
+ SimpleSyslogLogger.should respond_to(:silencer=)
77
+
78
+ @logger.should respond_to(:silencer)
79
+ @logger.should respond_to(:silencer=)
80
+
81
+ @logger.should respond_to(:silence)
82
+ end
83
+
84
+ it 'should use temporary level only in silence block' do
85
+ @logger.level = Syslog::Constants::LOG_DEBUG
86
+ @logger.level.should == Syslog::Constants::LOG_DEBUG
87
+
88
+ @logger.silence(Syslog::Constants::LOG_ERR) do |tmp_logger|
89
+ tmp_logger.level.should == Syslog::Constants::LOG_ERR
90
+ end
91
+
92
+ @logger.level.should == Syslog::Constants::LOG_DEBUG
93
+ end
94
+
95
+ it 'should send message which specify silence is meaningless in SimpleSyslogLogger' do
96
+ @logger.should_receive(:add).with(Syslog::LOG_DEBUG, an_instance_of(String))
97
+ @logger.silence(Syslog::Constants::LOG_ERR) {|tmp_logger| }
98
+ end
99
+
100
+ end
101
+
102
+ describe 'close' do
103
+
104
+ before :each do
105
+ @syslog_mock = mock('syslog')
106
+ Syslog.stub!(:open => @syslog_mock)
107
+ @logger = SimpleSyslogLogger.new
108
+ end
109
+
110
+ it 'should close Syslog object' do
111
+ @syslog_mock.should_receive(:close)
112
+ @logger.close
113
+ end
114
+
115
+ end
116
+
117
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: takihiro-simple_syslog_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Hiroaki Takisawa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-15 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: <activesupport>
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.0
24
+ version:
25
+ description: Simple logger output to syslogd for rails
26
+ email: takky818@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - MIT-LICENSE
35
+ - README
36
+ - lib/simple_syslog_logger.rb
37
+ - spec/simple_syslog_logger_spec.rb
38
+ has_rdoc: false
39
+ homepage: http://github.com/takihiro/simple_syslog_logger
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.2.0
61
+ signing_key:
62
+ specification_version: 2
63
+ summary: Simple logger output to syslogd for rails
64
+ test_files: []
65
+