sys_logger 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'http://rubygems.org'
2
+
3
+
4
+ group :development do
5
+ gem 'rdoc', '~> 3.12'
6
+ gem 'bundler', '~> 1.0.0'
7
+ gem 'jeweler', '~> 1.8.3'
8
+ gem 'rspec', '~> 2.8.0'
9
+ gem 'simplecov'
10
+ end
@@ -0,0 +1,31 @@
1
+ Copyright (c) 2012, Synergy Marketing, Inc.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions
6
+ are met:
7
+
8
+ Redistributions of source code must retain the above copyright notice,
9
+ this list of conditions and the following disclaimer.
10
+
11
+ Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+
15
+ Neither the name of the Synergy Marketing, Inc. nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
+ COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26
+ OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27
+ AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
29
+ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
30
+ DAMAGE.
31
+
@@ -0,0 +1,64 @@
1
+ = sys_logger
2
+
3
+ Loggerクラスと互換性を持ったSyslogモジュールラッパ。
4
+ 各インスタンス毎に任意のfacilityを設定することが出来ます。
5
+
6
+ == インストール
7
+
8
+ === bundlerを利用する場合
9
+
10
+ Gemfileに以下の記述を追加して、bundle install を実行してください。
11
+
12
+ gem 'sys_logger'
13
+
14
+ === bundlerを利用しない場合
15
+
16
+ 以下のコマンドを実行してください。
17
+
18
+ gem install sys_logger
19
+
20
+ == 使用例
21
+
22
+ === 基本的な利用方法
23
+
24
+ 設定をしない場合facilityはSyslog.openメソッドSyslogがオープンされた際に指定された値となります。
25
+
26
+ logger = SysLogger.new
27
+ logger.info('INFO MESSAGE!!')
28
+
29
+ === facilityを設定する
30
+
31
+ ロガーインスタンスに対してfacilityを設定することができます。
32
+
33
+ local1_logger = SysLogger.new
34
+ local1_logger.facility = SysLogger::LOG_LOCAL1
35
+ local1_logger.info('INFO MESSAGE!!')
36
+
37
+ mail_logger = SysLogger.new
38
+ mail_logger.facility = SysLogger::LOG_MAIL
39
+ mail_logger.info('MAIL MESSAGE!!')
40
+
41
+ === プログラム名を設定する
42
+
43
+ ログメッセージと一緒に記録するプログラム名を任意に設定することができます。
44
+ この値は、Syslog.identとは関係なく、ログメッセージの前に「: 」区切りで記録されます。
45
+
46
+ logger = SysLogger.new
47
+ logger.progname = "logger.rb"
48
+ logger.info('INFO MESSAGE!!') # 例:) Jan 1 01:01:01 irb[1000]: logger.rb: INFO MESSAGE!!
49
+
50
+ === syslogの設定をする
51
+
52
+ Syslogモジュールに存在するメソッドは、SysLoggerでも同じように呼び出すことが出来ます。
53
+ 内部的にはSyslogモジュールに移譲しているだけなので、どちらで呼び出しても同じです。
54
+
55
+ 例)ident, facility, optionsを設定する場合
56
+
57
+ # 以下の2つは同じ結果となる
58
+ SysLogger.reopen('foo', SysLogger::LOG_MAIL, SysLogger::LOG_PERROR || SysLogger::LOG_PID)
59
+ Syslog.reopen('foo', Syslog::LOG_MAIL, Syslog::LOG_PERROR || Syslog::LOG_PID)
60
+
61
+
62
+ == Copyright
63
+
64
+ Copyright (c) 2012 Synergy Marketing, Inc. See LICENSE for details.
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ gem.name = 'sys_logger'
17
+ gem.homepage = 'http://github.com/techscore/sys_logger'
18
+ gem.license = 'BSD'
19
+ gem.summary = 'Loggerクラスと互換性を持ったSyslogモジュールラッパ.'
20
+ gem.description = 'Syslogモジュールラッパ.'
21
+ gem.email = 'info-techscore@synergy101.jp'
22
+ gem.authors = ['yuki teraoka']
23
+ # dependencies defined in Gemfile
24
+ end
25
+ Jeweler::RubygemsDotOrgTasks.new
26
+
27
+ require 'rspec/core'
28
+ require 'rspec/core/rake_task'
29
+ RSpec::Core::RakeTask.new(:spec) do |spec|
30
+ spec.pattern = FileList['spec/**/*_spec.rb']
31
+ end
32
+
33
+ task :simplecov do
34
+ ENV['COVERAGE'] = 'true'
35
+ Rake::Task['spec'].execute
36
+ end
37
+
38
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
39
+ spec.pattern = 'spec/**/*_spec.rb'
40
+ spec.rcov = true
41
+ end
42
+
43
+ task :default => :spec
44
+
45
+ # RDoc::Parser.binary? はマルチバイト文字を含むファイルを誤判定する場合があるので NKF.guess で判定するように置き換える.
46
+ require 'nkf'
47
+ require 'rdoc/task'
48
+ class << RDoc::Parser
49
+ def binary?(file)
50
+ NKF.guess(File.read(file)) == NKF::BINARY
51
+ end
52
+ end
53
+
54
+ require 'rdoc/task'
55
+ Rake::RDocTask.new do |rdoc|
56
+ version = File.exist?('VERSION') ? File.read('VERSION') : ''
57
+
58
+ rdoc.rdoc_dir = 'rdoc'
59
+ rdoc.title = "synergy101 #{version}"
60
+ rdoc.rdoc_files.include('README*')
61
+ rdoc.rdoc_files.include('lib/**/*.rb')
62
+ end
63
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,178 @@
1
+ # coding: utf-8
2
+ require 'syslog'
3
+ require 'logger'
4
+
5
+ class SysLogger
6
+ VERSION = '1.0.0'
7
+
8
+ include Syslog::Constants
9
+ include Logger::Severity
10
+
11
+ SEVERITY_MAP = {
12
+ DEBUG => Syslog::LOG_DEBUG,
13
+ INFO => Syslog::LOG_INFO,
14
+ WARN => Syslog::LOG_WARNING,
15
+ ERROR => Syslog::LOG_ERR,
16
+ FATAL => Syslog::LOG_CRIT,
17
+ UNKNOWN => Syslog::LOG_ALERT,
18
+ }
19
+
20
+ class << self
21
+ # Syslogモジュールに移譲するメソッドを作成する
22
+ Syslog.singleton_methods(false).reject{|method| method.to_s == "inspect"}.each do |method|
23
+ define_method(method) {|*args| Syslog.send(method, *args)}
24
+ end
25
+ end
26
+
27
+ attr_accessor :progname, :facility, :level
28
+ alias sev_threshold level
29
+ alias sev_threshold= level=
30
+
31
+
32
+ # ロガーインスタンスを生成します
33
+ #
34
+ # ==== 引数
35
+ # progname: ログに出力するプログラム名
36
+ # facility: ファシリティ
37
+ # level : ログレベル(SysLogger::DEBUG, SysLogger::INFO, SysLogger::WARN, SysLogger::ERROR, SysLogger::FATAL, SysLogger::UNKNOWN)
38
+ def initialize(progname = nil, facility = nil, level = SysLogger::DEBUG)
39
+ @progname, @facility, @level = progname, facility, level
40
+ Syslog.open unless Syslog.opened?
41
+ end
42
+
43
+ # ログを出力します。
44
+ # severityはUNKNOWN扱いになります。
45
+ #
46
+ # ==== 引数
47
+ # message: ログに出力するメッセージ
48
+ #
49
+ # ==== 戻り値
50
+ # self
51
+ #
52
+ def <<(message)
53
+ add(UNKNOWN, message)
54
+ self
55
+ end
56
+
57
+ # メッセージをログに記録します。
58
+ # ブロックを与えた場合はブロックを評価した返り値をメッセージとしてログに記録します。 ユーザがこのメソッドを直接使うことはあまりありません。
59
+ #
60
+ # ==== 引数
61
+ # severity: ログレベル。SysLogger クラスで定義されている定数を指定します。 この値がレシーバーに設定されているレベルよりも低い場合、 メッセージは記録されません。
62
+ # message: ログに出力するメッセージを文字列か例外オブジェクトを指定します。 省略すると nil が用いられます。
63
+ # progname: ログメッセージと一緒に記録するプログラム名を指定します。 省略すると nil が使用されますが、実際には内部で保持されている値が使用されます。
64
+ #
65
+ # ==== 戻り値
66
+ # true
67
+ #
68
+ def add(severity, message = nil, progname = nil)
69
+ severity ||= UNKNOWN
70
+ return true if severity < level
71
+ progname ||= @progname
72
+ if message.nil?
73
+ if block_given?
74
+ message = yield
75
+ else
76
+ message = progname
77
+ progname = @progname
78
+ end
79
+ end
80
+ priority = SEVERITY_MAP[severity]
81
+ priority |= facility if @facility
82
+ progname = progname.to_s
83
+ if progname.empty?
84
+ Syslog.log(priority, '%s', message.to_s)
85
+ else
86
+ Syslog.log(priority, '%s: %s', progname, message.to_s)
87
+ end
88
+ true
89
+ end
90
+ alias log add
91
+
92
+ # 現在の Logger オブジェクトが DEBUG 以上のログレベルのメッセージを記録するなら 真を返します。
93
+ def debug?; @level <= DEBUG; end
94
+ # 現在の Logger オブジェクトが INFO 以上のログレベルのメッセージを記録するなら 真を返します。
95
+ def info?; @level <= INFO ; end
96
+ # 現在の Logger オブジェクトが WARN 以上のログレベルのメッセージを記録するなら 真を返します。
97
+ def warn?; @level <= WARN ; end
98
+ # 現在の Logger オブジェクトが ERROR 以上のログレベルのメッセージを記録するなら 真を返します。
99
+ def error?; @level <= ERROR; end
100
+ # 現在の Logger オブジェクトが FATAL 以上のログレベルのメッセージを記録するなら 真を返します。
101
+ def fatal?; @level <= FATAL; end
102
+
103
+ # DEBUG 情報を出力します。
104
+ #
105
+ # ==== 詳細
106
+ # ブロックを与えなかった場合は、progname をメッセージとしてログを出力します。
107
+ # ブロックを与えた場合は、ブロックを評価した結果をメッセージとして ログを出力します。
108
+ # 引数とブロックを同時に与えた場合は、progname をプログラム名、ブロックを評価した 結果をメッセージとしてログを出力します。
109
+ #
110
+ # ==== 引数
111
+ # progname: ブロックを与えない場合は、メッセージとして文字列または例外オブジェクトを指定します。 ブロックを与えた場合は、プログラム名を文字列として与えます。
112
+ def debug(progname = nil, &block) ; add(DEBUG , nil, progname, &block);end
113
+
114
+ # INFO 情報を出力します。
115
+ #
116
+ # ==== 詳細
117
+ # ブロックを与えなかった場合は、progname をメッセージとしてログを出力します。
118
+ # ブロックを与えた場合は、ブロックを評価した結果をメッセージとして ログを出力します。
119
+ # 引数とブロックを同時に与えた場合は、progname をプログラム名、ブロックを評価した 結果をメッセージとしてログを出力します。
120
+ #
121
+ # ==== 引数
122
+ # progname: ブロックを与えない場合は、メッセージとして文字列または例外オブジェクトを指定します。 ブロックを与えた場合は、プログラム名を文字列として与えます。
123
+ def info(progname = nil, &block) ; add(INFO , nil, progname, &block);end
124
+
125
+ # WARN 情報を出力します。
126
+ #
127
+ # ==== 詳細
128
+ # ブロックを与えなかった場合は、progname をメッセージとしてログを出力します。
129
+ # ブロックを与えた場合は、ブロックを評価した結果をメッセージとして ログを出力します。
130
+ # 引数とブロックを同時に与えた場合は、progname をプログラム名、ブロックを評価した 結果をメッセージとしてログを出力します。
131
+ #
132
+ # ==== 引数
133
+ # progname: ブロックを与えない場合は、メッセージとして文字列または例外オブジェクトを指定します。 ブロックを与えた場合は、プログラム名を文字列として与えます。
134
+ def warn(progname = nil, &block) ; add(WARN , nil, progname, &block);end
135
+
136
+ # ERROR 情報を出力します。
137
+ #
138
+ # ==== 詳細
139
+ # ブロックを与えなかった場合は、progname をメッセージとしてログを出力します。
140
+ # ブロックを与えた場合は、ブロックを評価した結果をメッセージとして ログを出力します。
141
+ # 引数とブロックを同時に与えた場合は、progname をプログラム名、ブロックを評価した 結果をメッセージとしてログを出力します。
142
+ #
143
+ # ==== 引数
144
+ # progname: ブロックを与えない場合は、メッセージとして文字列または例外オブジェクトを指定します。 ブロックを与えた場合は、プログラム名を文字列として与えます。
145
+ def error(progname = nil, &block) ; add(ERROR , nil, progname, &block);end
146
+
147
+ # FATAL 情報を出力します。
148
+ #
149
+ # ==== 詳細
150
+ # ブロックを与えなかった場合は、progname をメッセージとしてログを出力します。
151
+ # ブロックを与えた場合は、ブロックを評価した結果をメッセージとして ログを出力します。
152
+ # 引数とブロックを同時に与えた場合は、progname をプログラム名、ブロックを評価した 結果をメッセージとしてログを出力します。
153
+ #
154
+ # ==== 引数
155
+ # progname: ブロックを与えない場合は、メッセージとして文字列または例外オブジェクトを指定します。 ブロックを与えた場合は、プログラム名を文字列として与えます。
156
+ def fatal(progname = nil, &block) ; add(FATAL , nil, progname, &block);end
157
+
158
+ # UNKNOWN 情報を出力します。
159
+ #
160
+ # ==== 詳細
161
+ # ブロックを与えなかった場合は、progname をメッセージとしてログを出力します。
162
+ # ブロックを与えた場合は、ブロックを評価した結果をメッセージとして ログを出力します。
163
+ # 引数とブロックを同時に与えた場合は、progname をプログラム名、ブロックを評価した 結果をメッセージとしてログを出力します。
164
+ #
165
+ # ==== 引数
166
+ # progname: ブロックを与えない場合は、メッセージとして文字列または例外オブジェクトを指定します。 ブロックを与えた場合は、プログラム名を文字列として与えます。
167
+ def unknown(progname = nil, &block); add(UNKNOWN, nil, progname, &block);end
168
+
169
+ # 与えられたブロック内で一時的にログレベルを変更します。
170
+ # ブロック引数には、ログレベルが変更されたロガーが渡されます。
171
+ #
172
+ # ==== 引数
173
+ # temporary_level: 一時的なログレベル
174
+ #
175
+ def silence(temporary_level = ERROR)
176
+ yield self.class.new(@progname && @progname.dup, @facility, temporary_level)
177
+ end
178
+ end
@@ -0,0 +1,76 @@
1
+ # coding: utf-8
2
+ if ENV['COVERAGE']
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_filter '/spec/'
6
+ add_filter '/vendor/'
7
+ end
8
+ end
9
+
10
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
11
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
12
+ require 'rspec'
13
+ require 'sys_logger'
14
+
15
+ OrgSyslog = Syslog
16
+ module SyslogMock
17
+ include Syslog::Constants
18
+
19
+ class LogLine
20
+ attr_reader :priority, :message
21
+
22
+ def self.create(priority, format, *args)
23
+ new(priority, format%args)
24
+ end
25
+
26
+ def initialize(priority, message)
27
+ @priority, @message = priority, message
28
+ end
29
+
30
+ def facility
31
+ ~0b111 & @priority
32
+ end
33
+
34
+ def severity
35
+ SysLogger::SEVERITY_MAP.invert[level]
36
+ end
37
+
38
+ def level
39
+ 0b111 & @priority
40
+ end
41
+
42
+ def to_s
43
+ @message
44
+ end
45
+ end
46
+
47
+ module_function
48
+
49
+ def lines
50
+ @@log_lines ||= []
51
+ end
52
+
53
+ def last_line
54
+ lines.last
55
+ end
56
+
57
+ def clear_lines
58
+ lines.clear
59
+ end
60
+
61
+ def log(priority, format, *args)
62
+ lines << LogLine.create(priority, format, *args)
63
+ end
64
+
65
+ def method_missing(name,*args, &block)
66
+ OrgSyslog.send(name, *args, &block)
67
+ end
68
+ end
69
+
70
+ begin
71
+ org_verbose = $VERBOSE
72
+ $VERBOSE = nil
73
+ Syslog = SyslogMock
74
+ ensure
75
+ $VERBOSE = org_verbose
76
+ end
@@ -0,0 +1,157 @@
1
+ # coding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ describe SysLogger do
5
+ before do
6
+ Syslog.clear_lines
7
+ @logger1 = SysLogger.new
8
+ @logger2 = SysLogger.new
9
+ end
10
+
11
+ context "output logs" do
12
+ it "debug" do
13
+ @logger1.debug('DEBUG MESSAGE!%~{}#@')
14
+ Syslog. last_line.message.should == 'DEBUG MESSAGE!%~{}#@'
15
+ Syslog.last_line.level.should == Syslog::LOG_DEBUG
16
+ end
17
+
18
+ it "info" do
19
+ @logger1.info('INFO MESSAGE!%~{}#@')
20
+ Syslog. last_line.message.should == 'INFO MESSAGE!%~{}#@'
21
+ Syslog.last_line.level.should == Syslog::LOG_INFO
22
+ end
23
+
24
+ it "warn" do
25
+ @logger1.warn('WARN MESSAGE!%~{}#@')
26
+ Syslog. last_line.message.should == 'WARN MESSAGE!%~{}#@'
27
+ Syslog.last_line.level.should == Syslog::LOG_WARNING
28
+ end
29
+
30
+ it "error" do
31
+ @logger1.error('ERROR MESSAGE!%~{}#@')
32
+ Syslog. last_line.message.should == 'ERROR MESSAGE!%~{}#@'
33
+ Syslog.last_line.level.should == Syslog::LOG_ERR
34
+ end
35
+
36
+ it "fatal" do
37
+ @logger1.fatal('FATAL MESSAGE!%~{}#@')
38
+ Syslog. last_line.message.should == 'FATAL MESSAGE!%~{}#@'
39
+ Syslog.last_line.level.should == Syslog::LOG_CRIT
40
+ end
41
+
42
+ it "unknown" do
43
+ @logger1.unknown('UNKNOWN MESSAGE!%~{}#@')
44
+ Syslog. last_line.message.should == 'UNKNOWN MESSAGE!%~{}#@'
45
+ Syslog.last_line.level.should == Syslog::LOG_ALERT
46
+ end
47
+
48
+ it "<<" do
49
+ @logger1 << 'call << method!!'
50
+ Syslog. last_line.message.should == 'call << method!!'
51
+ Syslog.last_line.level.should == Syslog::LOG_ALERT
52
+ end
53
+ end
54
+
55
+ it "facility" do
56
+ facilities = %w(AUTH AUTHPRIV CRON DAEMON FTP KERN LPR MAIL NEWS SYSLOG USER UUCP LOCAL0 LOCAL1 LOCAL2 LOCAL3 LOCAL4 LOCAL5 LOCAL6 LOCAL7)
57
+ loggers = {}
58
+ facilities.each do |str|
59
+ facility = OrgSyslog.const_get("LOG_#{str}")
60
+ loggers[facility] = SysLogger.new(nil, facility)
61
+ end
62
+ loggers.each do |facility, logger|
63
+ logger.info("facility: #{facility} log!")
64
+ Syslog.last_line.facility.should == facility
65
+ end
66
+ end
67
+
68
+ context "progname" do
69
+ before do
70
+ @logger1 = SysLogger.new('test1')
71
+ @logger2 = SysLogger.new('test2')
72
+ end
73
+
74
+ it do
75
+ @logger1.info("log message!!")
76
+ Syslog.last_line.message.should == "test1: log message!!"
77
+
78
+ @logger2.info("log message!!")
79
+ Syslog.last_line.message.should == "test2: log message!!"
80
+
81
+ @logger1.progname = "test3"
82
+ @logger1.info("log message!!")
83
+ Syslog.last_line.message.should == "test3: log message!!"
84
+
85
+ @logger1.info("test4") {"log message!!"}
86
+ Syslog.last_line.message.should == "test4: log message!!"
87
+ end
88
+ end
89
+
90
+ context "log level" do
91
+ before do
92
+ @severities = %w(debug info warn error fatal unknown)
93
+ end
94
+
95
+ it "debug" do
96
+ @logger1.level = SysLogger::DEBUG
97
+ @severities.each {|sv| @logger1.send(sv, "#{sv.upcase} MESSAGE!") }
98
+ Syslog.lines.size.should == 6
99
+ Syslog.lines.map(&:severity).all?{|sv| sv >= SysLogger::DEBUG}.should be_true
100
+ end
101
+
102
+ it "info" do
103
+ @logger1.level = SysLogger::INFO
104
+ @severities.each {|sv| @logger1.send(sv, "#{sv.upcase} MESSAGE!") }
105
+ Syslog.lines.size.should == 5
106
+ Syslog.lines.map(&:severity).all?{|sv| sv >= SysLogger::INFO}.should be_true
107
+ end
108
+
109
+ it "warn" do
110
+ @logger1.level = SysLogger::WARN
111
+ @severities.each {|sv| @logger1.send(sv, "#{sv.upcase} MESSAGE!") }
112
+ Syslog.lines.size.should == 4
113
+ Syslog.lines.map(&:severity).all?{|sv| sv >= SysLogger::WARN}.should be_true
114
+ end
115
+
116
+ it "error" do
117
+ @logger1.level = SysLogger::ERROR
118
+ @severities.each {|sv| @logger1.send(sv, "#{sv.upcase} MESSAGE!") }
119
+ Syslog.lines.size.should == 3
120
+ Syslog.lines.map(&:severity).all?{|sv| sv >= SysLogger::ERROR}.should be_true
121
+ end
122
+
123
+ it "fatal" do
124
+ @logger1.level = SysLogger::FATAL
125
+ @severities.each {|sv| @logger1.send(sv, "#{sv.upcase} MESSAGE!") }
126
+ Syslog.lines.size.should == 2
127
+ Syslog.lines.map(&:severity).all?{|sv| sv >= SysLogger::FATAL}.should be_true
128
+ end
129
+
130
+ it "unknown" do
131
+ @logger1.level = SysLogger::UNKNOWN
132
+ @severities.each {|sv| @logger1.send(sv, "#{sv.upcase} MESSAGE!") }
133
+ Syslog.lines.size.should == 1
134
+ Syslog.last_line.severity.should == SysLogger::UNKNOWN
135
+ end
136
+ end
137
+
138
+ it "silence" do
139
+ @logger1.level = SysLogger::DEBUG
140
+ @logger1.error('error message!')
141
+ Syslog.lines.count.should == 1
142
+ Syslog.clear_lines
143
+ @logger1.silence(SysLogger::ERROR) do |logger|
144
+ @logger1.error('error message!')
145
+ Syslog.lines.count.should == 1
146
+ Syslog.clear_lines
147
+
148
+ logger.warn('warn message!')
149
+ Syslog.lines.should be_empty
150
+
151
+ logger.error('error message!')
152
+ Syslog.lines.count.should == 1
153
+ Syslog.clear_lines
154
+ end
155
+ end
156
+
157
+ end
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "sys_logger"
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["yuki teraoka"]
12
+ s.date = "2012-10-05"
13
+ s.description = "Syslog\u{30e2}\u{30b8}\u{30e5}\u{30fc}\u{30eb}\u{30e9}\u{30c3}\u{30d1}."
14
+ s.email = "info-techscore@synergy101.jp"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "Gemfile",
21
+ "LICENSE.txt",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/sys_logger.rb",
26
+ "spec/spec_helper.rb",
27
+ "spec/sys_logger_spec.rb",
28
+ "sys_logger.gemspec"
29
+ ]
30
+ s.homepage = "http://github.com/techscore/sys_logger"
31
+ s.licenses = ["BSD"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = "1.8.10"
34
+ s.summary = "Logger\u{30af}\u{30e9}\u{30b9}\u{3068}\u{4e92}\u{63db}\u{6027}\u{3092}\u{6301}\u{3063}\u{305f}Syslog\u{30e2}\u{30b8}\u{30e5}\u{30fc}\u{30eb}\u{30e9}\u{30c3}\u{30d1}."
35
+
36
+ if s.respond_to? :specification_version then
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
41
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
42
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
43
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
44
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
45
+ else
46
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
47
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
48
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
49
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
50
+ s.add_dependency(%q<simplecov>, [">= 0"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
54
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
55
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
56
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
57
+ s.add_dependency(%q<simplecov>, [">= 0"])
58
+ end
59
+ end
60
+
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sys_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - yuki teraoka
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: &8289220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.12'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *8289220
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &8288620 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *8288620
36
+ - !ruby/object:Gem::Dependency
37
+ name: jeweler
38
+ requirement: &8287920 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.8.3
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *8287920
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &8287000 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.8.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *8287000
58
+ - !ruby/object:Gem::Dependency
59
+ name: simplecov
60
+ requirement: &8286220 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *8286220
69
+ description: Syslogモジュールラッパ.
70
+ email: info-techscore@synergy101.jp
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files:
74
+ - LICENSE.txt
75
+ - README.rdoc
76
+ files:
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.rdoc
80
+ - Rakefile
81
+ - VERSION
82
+ - lib/sys_logger.rb
83
+ - spec/spec_helper.rb
84
+ - spec/sys_logger_spec.rb
85
+ - sys_logger.gemspec
86
+ homepage: http://github.com/techscore/sys_logger
87
+ licenses:
88
+ - BSD
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ segments:
100
+ - 0
101
+ hash: 1516162120690752456
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 1.8.10
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Loggerクラスと互換性を持ったSyslogモジュールラッパ.
114
+ test_files: []