scashin133-syslogger 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Cyril Rohr, INRIA Rennes-Bretagne Atlantique
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ = syslogger
2
+
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
+ == Fork
23
+
24
+ This fork was made to create a drop in replacement for ruby's Logger.
25
+
26
+ == Copyright
27
+
28
+ Copyright (c) 2010 Cyril, INRIA Rennes-Bretagne Atlantique. See LICENSE for details.
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "scashin133-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 = "scashin133@gmail.com"
11
+ gem.homepage = "http://github.com/scashin133/syslogger"
12
+ gem.authors = ["Cyril Rohr","Sean Cashin"]
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
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :test => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "syslogger #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.3.2
@@ -0,0 +1,78 @@
1
+ require 'syslog'
2
+ require 'logger'
3
+
4
+ class Syslogger
5
+ attr_reader :level, :ident, :options, :facility
6
+
7
+ MAPPING = {
8
+ Logger::DEBUG => Syslog::LOG_DEBUG,
9
+ Logger::INFO => Syslog::LOG_INFO,
10
+ Logger::WARN => Syslog::LOG_NOTICE,
11
+ Logger::ERROR => Syslog::LOG_WARNING,
12
+ Logger::FATAL => Syslog::LOG_ERR,
13
+ Logger::UNKNOWN => Syslog::LOG_ALERT
14
+ }
15
+
16
+ #
17
+ # Initializes default options for the logger
18
+ # <tt>ident</tt>:: the name of your program [default=$0].
19
+ # <tt>options</tt>:: syslog options [default=<tt>Syslog::LOG_PID | Syslog::LOG_CONS</tt>].
20
+ # Correct values are:
21
+ # LOG_CONS : writes the message on the console if an error occurs when sending the message;
22
+ # LOG_NDELAY : no delay before sending the message;
23
+ # LOG_PERROR : messages will also be written on STDERR;
24
+ # LOG_PID : adds the process number to the message (just after the program name)
25
+ # <tt>facility</tt>:: the syslog facility [default=nil] Correct values include:
26
+ # Syslog::LOG_DAEMON
27
+ # Syslog::LOG_USER
28
+ # Syslog::LOG_SYSLOG
29
+ # Syslog::LOG_LOCAL2
30
+ # Syslog::LOG_NEWS
31
+ # etc.
32
+ #
33
+ # Usage:
34
+ # logger = Syslogger.new("my_app", Syslog::LOG_PID | Syslog::LOG_CONS, Syslog::LOG_LOCAL0)
35
+ # logger.level = Logger::INFO # use Logger levels
36
+ # logger.warn "warning message"
37
+ # logger.debug "debug message"
38
+ #
39
+ def initialize(ident = $0, options = Syslog::LOG_PID | Syslog::LOG_CONS, facility = nil)
40
+ @ident = ident
41
+ @options = options || (Syslog::LOG_PID | Syslog::LOG_CONS)
42
+ @facility = facility
43
+ @level = Logger::INFO
44
+ end
45
+
46
+ %w{debug info warn error fatal unknown}.each do |logger_method|
47
+ define_method logger_method.to_sym do |message|
48
+ add(Logger.const_get(logger_method.upcase), message)
49
+ end
50
+ define_method "#{logger_method}?".to_sym do
51
+ @level <= Logger.const_get(logger_method.upcase)
52
+ end
53
+ end
54
+
55
+ # Logs a message at the Logger::INFO level.
56
+ def <<(msg)
57
+ add(Logger::INFO, msg)
58
+ end
59
+
60
+ # Low level method to add a message.
61
+ # +severity+:: the level of the message. One of Logger::DEBUG, Logger::INFO, Logger::WARN, Logger::ERROR, Logger::FATAL, Logger::UNKNOWN
62
+ # +message+:: the message string. If nil, the method will call the block and use the result as the message string.
63
+ # +progname+:: optionally, a overwrite the program name that appears in the log message.
64
+ def add(severity, message = nil, progname = nil, &block)
65
+ progname ||= @ident
66
+ Syslog.open(progname, @options, @facility) { |s|
67
+ s.mask = Syslog::LOG_UPTO(MAPPING[@level])
68
+ s.log(MAPPING[severity], (message || block.call).to_s)
69
+ }
70
+ end
71
+
72
+ # Sets the minimum level for messages to be written in the log.
73
+ # +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>
74
+ def level=(level)
75
+ @level = level
76
+ end
77
+
78
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'syslogger'
@@ -0,0 +1,62 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Syslogger" do
4
+ it "should log to the default syslog facility, with the default options" do
5
+ logger = Syslogger.new
6
+ Syslog.should_receive(:open).with($0, Syslog::LOG_PID | Syslog::LOG_CONS, nil).and_yield(syslog=mock("syslog", :mask= => true))
7
+ syslog.should_receive(:log).with(Syslog::LOG_NOTICE, "Some message")
8
+ logger.warn "Some message"
9
+ end
10
+
11
+ it "should log to the user facility, with specific options" do
12
+ logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
13
+ Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=mock("syslog", :mask= => true))
14
+ syslog.should_receive(:log).with(Syslog::LOG_NOTICE, "Some message")
15
+ logger.warn "Some message"
16
+ end
17
+
18
+ %w{debug info warn error fatal unknown}.each do |logger_method|
19
+ it "should respond to the #{logger_method.inspect} method" do
20
+ Syslogger.new.should respond_to logger_method.to_sym
21
+ end
22
+ end
23
+
24
+ %w{debug info warn error fatal unknown}.each do |logger_method|
25
+ it "should respond to the #{logger_method.inspect}? method" do
26
+ Syslogger.new.should respond_to "#{logger_method}?".to_sym
27
+ end
28
+ end
29
+
30
+ it "should respond to <<" do
31
+ logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
32
+ logger.should respond_to(:<<)
33
+ Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=mock("syslog", :mask= => true))
34
+ syslog.should_receive(:log).with(Syslog::LOG_INFO, "yop")
35
+ logger << "yop"
36
+ end
37
+
38
+ describe "add" do
39
+ before do
40
+ @logger = Syslogger.new("my_app", Syslog::LOG_PID, Syslog::LOG_USER)
41
+ end
42
+ it "should respond to add" do
43
+ @logger.should respond_to(:add)
44
+ end
45
+ it "should correctly log" do
46
+ Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=mock("syslog", :mask= => true))
47
+ syslog.should_receive(:log).with(Syslog::LOG_INFO, "message")
48
+ @logger.add(Logger::INFO, "message")
49
+ end
50
+ it "should take the message from the block if :message is nil" do
51
+ Syslog.should_receive(:open).with("my_app", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=mock("syslog", :mask= => true))
52
+ syslog.should_receive(:log).with(Syslog::LOG_INFO, "my message")
53
+ @logger.add(Logger::INFO) { "my message" }
54
+ end
55
+ it "should use the given progname" do
56
+ Syslog.should_receive(:open).with("progname", Syslog::LOG_PID, Syslog::LOG_USER).and_yield(syslog=mock("syslog", :mask= => true))
57
+ syslog.should_receive(:log).with(Syslog::LOG_INFO, "message")
58
+ @logger.add(Logger::INFO, "message", "progname") { "my message" }
59
+ end
60
+ end
61
+ # TODO: test logger level
62
+ end
@@ -0,0 +1,54 @@
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.3.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Cyril Rohr", "Sean Cashin"]
12
+ s.date = %q{2010-08-17}
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{scashin133@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/scashin133/syslogger}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.7}
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::VERSION) >= 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
+
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scashin133-syslogger
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 3
9
+ - 2
10
+ version: 1.3.2
11
+ platform: ruby
12
+ authors:
13
+ - Cyril Rohr
14
+ - Sean Cashin
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-08-17 00:00:00 -07:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rspec
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :development
35
+ version_requirements: *id001
36
+ description: Same as SyslogLogger, but without the ridiculous number of dependencies and with the possibility to specify the syslog facility
37
+ email: scashin133@gmail.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - LICENSE
44
+ - README.rdoc
45
+ files:
46
+ - .document
47
+ - .gitignore
48
+ - LICENSE
49
+ - README.rdoc
50
+ - Rakefile
51
+ - VERSION
52
+ - lib/syslogger.rb
53
+ - spec/spec_helper.rb
54
+ - spec/syslogger_spec.rb
55
+ - syslogger.gemspec
56
+ has_rdoc: true
57
+ homepage: http://github.com/scashin133/syslogger
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --charset=UTF-8
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.3.7
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Dead simple Ruby Syslog logger
90
+ test_files:
91
+ - spec/spec_helper.rb
92
+ - spec/syslogger_spec.rb