syslogger 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +39 -12
- data/Rakefile +6 -27
- data/lib/syslogger.rb +36 -9
- data/spec/syslogger_spec.rb +62 -3
- metadata +49 -24
- data/.document +0 -5
- data/.gitignore +0 -21
- data/VERSION +0 -1
- data/syslogger.gemspec +0 -54
data/README.rdoc
CHANGED
@@ -1,17 +1,44 @@
|
|
1
1
|
= syslogger
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
A drop-in replacement for the standard Logger Ruby library, that logs to the syslog instead of a log file.
|
4
|
+
Contrary to the SyslogLogger library, you can specify the facility and the syslog options.
|
5
|
+
|
6
|
+
== Installation
|
7
|
+
$ gem install syslogger
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
require 'syslogger'
|
11
|
+
|
12
|
+
# Will send all messages to the local0 facility, adding the process id in the message
|
13
|
+
logger = Syslogger.new("app_name", Syslog::LOG_PID, Syslog::LOG_LOCAL0)
|
14
|
+
|
15
|
+
# Send messages that are at least of the Logger::INFO level
|
16
|
+
logger.level = Logger::INFO # use Logger levels
|
17
|
+
|
18
|
+
logger.debug "will not appear"
|
19
|
+
logger.info "will appear"
|
20
|
+
logger.warn "will appear"
|
21
|
+
|
22
|
+
== Development
|
23
|
+
* Install +bundler+:
|
24
|
+
|
25
|
+
$ gem install bundler
|
26
|
+
|
27
|
+
* Install development dependencies:
|
28
|
+
|
29
|
+
$ bundle install
|
30
|
+
|
31
|
+
* Run tests:
|
32
|
+
|
33
|
+
$ bundle exec rake
|
34
|
+
|
35
|
+
* Package (do not forget to increment <tt>Syslogger:VERSION</tt>):
|
36
|
+
|
37
|
+
$ gem build syslogger.gemspec
|
38
|
+
|
39
|
+
== Contributions
|
40
|
+
* crhym3
|
14
41
|
|
15
42
|
== Copyright
|
16
43
|
|
17
|
-
Copyright (c) 2010 Cyril. See LICENSE for details.
|
44
|
+
Copyright (c) 2010 Cyril, INRIA Rennes-Bretagne Atlantique. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,24 +1,8 @@
|
|
1
|
-
require '
|
2
|
-
require 'rake'
|
1
|
+
require 'spec/rake/spectask'
|
2
|
+
require 'rake/rdoctask'
|
3
3
|
|
4
|
-
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "syslogger"
|
8
|
-
gem.summary = %Q{Dead simple Ruby Syslog logger}
|
9
|
-
gem.description = %Q{Same as SyslogLogger, but without the ridiculous number of dependencies and with the possibility to specify the syslog facility}
|
10
|
-
gem.email = "cyril.rohr@gmail.com"
|
11
|
-
gem.homepage = "http://github.com/crohr/syslogger"
|
12
|
-
gem.authors = ["Cyril Rohr"]
|
13
|
-
gem.add_development_dependency "rspec", ">= 0"
|
14
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
-
end
|
16
|
-
Jeweler::GemcutterTasks.new
|
17
|
-
rescue LoadError
|
18
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
-
end
|
4
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
|
20
5
|
|
21
|
-
require 'spec/rake/spectask'
|
22
6
|
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
7
|
spec.libs << 'lib' << 'spec'
|
24
8
|
spec.spec_files = FileList['spec/**/*_spec.rb']
|
@@ -30,16 +14,11 @@ Spec::Rake::SpecTask.new(:rcov) do |spec|
|
|
30
14
|
spec.rcov = true
|
31
15
|
end
|
32
16
|
|
33
|
-
task :test => :check_dependencies
|
34
|
-
|
35
|
-
task :default => :spec
|
36
|
-
|
37
|
-
require 'rake/rdoctask'
|
38
17
|
Rake::RDocTask.new do |rdoc|
|
39
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
-
|
41
18
|
rdoc.rdoc_dir = 'rdoc'
|
42
|
-
rdoc.title = "syslogger #{
|
19
|
+
rdoc.title = "syslogger #{Syslogger::VERSION}"
|
43
20
|
rdoc.rdoc_files.include('README*')
|
44
21
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
22
|
end
|
23
|
+
|
24
|
+
task :default => :spec
|
data/lib/syslogger.rb
CHANGED
@@ -2,8 +2,11 @@ require 'syslog'
|
|
2
2
|
require 'logger'
|
3
3
|
|
4
4
|
class Syslogger
|
5
|
+
|
6
|
+
VERSION = "1.2.1"
|
7
|
+
|
5
8
|
attr_reader :level, :ident, :options, :facility
|
6
|
-
|
9
|
+
|
7
10
|
MAPPING = {
|
8
11
|
Logger::DEBUG => Syslog::LOG_DEBUG,
|
9
12
|
Logger::INFO => Syslog::LOG_INFO,
|
@@ -12,13 +15,23 @@ class Syslogger
|
|
12
15
|
Logger::FATAL => Syslog::LOG_ERR,
|
13
16
|
Logger::UNKNOWN => Syslog::LOG_ALERT
|
14
17
|
}
|
18
|
+
|
15
19
|
#
|
16
20
|
# Initializes default options for the logger
|
17
|
-
# <tt>ident</tt>:: the name of your program [default=$0]
|
18
|
-
# <tt>options</tt>::
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
21
|
+
# <tt>ident</tt>:: the name of your program [default=$0].
|
22
|
+
# <tt>options</tt>:: syslog options [default=<tt>Syslog::LOG_PID | Syslog::LOG_CONS</tt>].
|
23
|
+
# Correct values are:
|
24
|
+
# LOG_CONS : writes the message on the console if an error occurs when sending the message;
|
25
|
+
# LOG_NDELAY : no delay before sending the message;
|
26
|
+
# LOG_PERROR : messages will also be written on STDERR;
|
27
|
+
# LOG_PID : adds the process number to the message (just after the program name)
|
28
|
+
# <tt>facility</tt>:: the syslog facility [default=nil] Correct values include:
|
29
|
+
# Syslog::LOG_DAEMON
|
30
|
+
# Syslog::LOG_USER
|
31
|
+
# Syslog::LOG_SYSLOG
|
32
|
+
# Syslog::LOG_LOCAL2
|
33
|
+
# Syslog::LOG_NEWS
|
34
|
+
# etc.
|
22
35
|
#
|
23
36
|
# Usage:
|
24
37
|
# logger = Syslogger.new("my_app", Syslog::LOG_PID | Syslog::LOG_CONS, Syslog::LOG_LOCAL0)
|
@@ -37,21 +50,35 @@ class Syslogger
|
|
37
50
|
define_method logger_method.to_sym do |message|
|
38
51
|
add(Logger.const_get(logger_method.upcase), message)
|
39
52
|
end
|
53
|
+
|
54
|
+
unless logger_method == 'unknown'
|
55
|
+
define_method "#{logger_method}?".to_sym do
|
56
|
+
@level <= Logger.const_get(logger_method.upcase)
|
57
|
+
end
|
58
|
+
end
|
40
59
|
end
|
41
60
|
|
61
|
+
# Logs a message at the Logger::INFO level.
|
42
62
|
def <<(msg)
|
43
63
|
add(Logger::INFO, msg)
|
44
64
|
end
|
45
65
|
|
66
|
+
# Low level method to add a message.
|
67
|
+
# +severity+:: the level of the message. One of Logger::DEBUG, Logger::INFO, Logger::WARN, Logger::ERROR, Logger::FATAL, Logger::UNKNOWN
|
68
|
+
# +message+:: the message string. If nil, the method will call the block and use the result as the message string.
|
69
|
+
# +progname+:: optionally, a overwrite the program name that appears in the log message.
|
46
70
|
def add(severity, message = nil, progname = nil, &block)
|
47
71
|
progname ||= @ident
|
48
72
|
Syslog.open(progname, @options, @facility) { |s|
|
49
73
|
s.mask = Syslog::LOG_UPTO(MAPPING[@level])
|
50
|
-
s.log(MAPPING[severity], (message || block.call))
|
74
|
+
s.log(MAPPING[severity], (message || block.call).to_s)
|
51
75
|
}
|
52
76
|
end
|
53
77
|
|
54
|
-
|
55
|
-
|
78
|
+
# Sets the minimum level for messages to be written in the log.
|
79
|
+
# +level+:: one of <tt>Logger::DEBUG</tt>, <tt>Logger::INFO</tt>, <tt>Logger::WARN</tt>, <tt>Logger::ERROR</tt>, <tt>Logger::FATAL</tt>, <tt>Logger::UNKNOWN</tt>
|
80
|
+
def level=(level)
|
81
|
+
@level = level
|
56
82
|
end
|
83
|
+
|
57
84
|
end
|
data/spec/syslogger_spec.rb
CHANGED
@@ -51,6 +51,65 @@ describe "Syslogger" do
|
|
51
51
|
syslog.should_receive(:log).with(Syslog::LOG_INFO, "message")
|
52
52
|
@logger.add(Logger::INFO, "message", "progname") { "my message" }
|
53
53
|
end
|
54
|
-
end
|
55
|
-
|
56
|
-
|
54
|
+
end # describe "add"
|
55
|
+
|
56
|
+
describe ":level? methods" do
|
57
|
+
before(:each) do
|
58
|
+
@logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
|
59
|
+
end
|
60
|
+
|
61
|
+
%w{debug info warn error fatal}.each do |logger_method|
|
62
|
+
it "should respond to the #{logger_method}? method" do
|
63
|
+
@logger.should respond_to "#{logger_method}?".to_sym
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should not have unknown? method" do
|
68
|
+
@logger.should_not respond_to :unknown?
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should return true for all methods" do
|
72
|
+
@logger.level = Logger::DEBUG
|
73
|
+
%w{debug info warn error fatal}.each do |logger_method|
|
74
|
+
@logger.send("#{logger_method}?").should be_true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should return true for all except debug?" do
|
79
|
+
@logger.level = Logger::INFO
|
80
|
+
%w{info warn error fatal}.each do |logger_method|
|
81
|
+
@logger.send("#{logger_method}?").should be_true
|
82
|
+
end
|
83
|
+
@logger.debug?.should be_false
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should return true for warn?, error? and fatal? when WARN" do
|
87
|
+
@logger.level = Logger::WARN
|
88
|
+
%w{warn error fatal}.each do |logger_method|
|
89
|
+
@logger.send("#{logger_method}?").should be_true
|
90
|
+
end
|
91
|
+
%w{debug info}.each do |logger_method|
|
92
|
+
@logger.send("#{logger_method}?").should be_false
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should return true for error? and fatal? when ERROR" do
|
97
|
+
@logger.level = Logger::ERROR
|
98
|
+
%w{error fatal}.each do |logger_method|
|
99
|
+
@logger.send("#{logger_method}?").should be_true
|
100
|
+
end
|
101
|
+
%w{warn debug info}.each do |logger_method|
|
102
|
+
@logger.send("#{logger_method}?").should be_false
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should return true only for fatal? when FATAL" do
|
107
|
+
@logger.level = Logger::FATAL
|
108
|
+
@logger.fatal?.should be_true
|
109
|
+
%w{error warn debug info}.each do |logger_method|
|
110
|
+
@logger.send("#{logger_method}?").should be_false
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end # describe ":level? methods"
|
114
|
+
|
115
|
+
end # describe "Syslogger"
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syslogger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 2
|
8
|
+
- 1
|
9
|
+
version: 1.2.1
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Cyril Rohr
|
@@ -9,39 +14,53 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2011-01-05 00:00:00 +01:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
21
|
+
name: rake
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 8
|
31
|
+
version: "0.8"
|
17
32
|
type: :development
|
18
|
-
|
19
|
-
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
20
39
|
requirements:
|
21
|
-
- -
|
40
|
+
- - ~>
|
22
41
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 3
|
45
|
+
version: "1.3"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
25
48
|
description: Same as SyslogLogger, but without the ridiculous number of dependencies and with the possibility to specify the syslog facility
|
26
|
-
email:
|
49
|
+
email:
|
50
|
+
- cyril.rohr@gmail.com
|
27
51
|
executables: []
|
28
52
|
|
29
53
|
extensions: []
|
30
54
|
|
31
|
-
extra_rdoc_files:
|
32
|
-
|
33
|
-
- README.rdoc
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
34
57
|
files:
|
35
|
-
- .document
|
36
|
-
- .gitignore
|
37
|
-
- LICENSE
|
38
|
-
- README.rdoc
|
39
|
-
- Rakefile
|
40
|
-
- VERSION
|
41
58
|
- lib/syslogger.rb
|
42
59
|
- spec/spec_helper.rb
|
43
60
|
- spec/syslogger_spec.rb
|
44
|
-
-
|
61
|
+
- Rakefile
|
62
|
+
- LICENSE
|
63
|
+
- README.rdoc
|
45
64
|
has_rdoc: true
|
46
65
|
homepage: http://github.com/crohr/syslogger
|
47
66
|
licenses: []
|
@@ -52,21 +71,27 @@ rdoc_options:
|
|
52
71
|
require_paths:
|
53
72
|
- lib
|
54
73
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
55
75
|
requirements:
|
56
76
|
- - ">="
|
57
77
|
- !ruby/object:Gem::Version
|
58
|
-
|
59
|
-
|
78
|
+
segments:
|
79
|
+
- 1
|
80
|
+
- 8
|
81
|
+
version: "1.8"
|
60
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
61
84
|
requirements:
|
62
85
|
- - ">="
|
63
86
|
- !ruby/object:Gem::Version
|
64
|
-
|
65
|
-
|
87
|
+
segments:
|
88
|
+
- 1
|
89
|
+
- 3
|
90
|
+
version: "1.3"
|
66
91
|
requirements: []
|
67
92
|
|
68
93
|
rubyforge_project:
|
69
|
-
rubygems_version: 1.3.
|
94
|
+
rubygems_version: 1.3.7
|
70
95
|
signing_key:
|
71
96
|
specification_version: 3
|
72
97
|
summary: Dead simple Ruby Syslog logger
|
data/.document
DELETED
data/.gitignore
DELETED
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.2.0
|
data/syslogger.gemspec
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{syslogger}
|
8
|
-
s.version = "1.2.0"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Cyril Rohr"]
|
12
|
-
s.date = %q{2010-03-10}
|
13
|
-
s.description = %q{Same as SyslogLogger, but without the ridiculous number of dependencies and with the possibility to specify the syslog facility}
|
14
|
-
s.email = %q{cyril.rohr@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"lib/syslogger.rb",
|
27
|
-
"spec/spec_helper.rb",
|
28
|
-
"spec/syslogger_spec.rb",
|
29
|
-
"syslogger.gemspec"
|
30
|
-
]
|
31
|
-
s.homepage = %q{http://github.com/crohr/syslogger}
|
32
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
-
s.require_paths = ["lib"]
|
34
|
-
s.rubygems_version = %q{1.3.5}
|
35
|
-
s.summary = %q{Dead simple Ruby Syslog logger}
|
36
|
-
s.test_files = [
|
37
|
-
"spec/spec_helper.rb",
|
38
|
-
"spec/syslogger_spec.rb"
|
39
|
-
]
|
40
|
-
|
41
|
-
if s.respond_to? :specification_version then
|
42
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
-
s.specification_version = 3
|
44
|
-
|
45
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
-
s.add_development_dependency(%q<rspec>, [">= 0"])
|
47
|
-
else
|
48
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
49
|
-
end
|
50
|
-
else
|
51
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|