lumberjack_syslog_device 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGE_LOG.md +3 -0
- data/README.md +18 -0
- data/VERSION +1 -1
- data/lib/lumberjack_syslog_device.rb +64 -40
- data/lumberjack_syslog_device.gemspec +33 -0
- metadata +71 -70
- data/README.rdoc +0 -13
- data/Rakefile +0 -56
- data/spec/lumberjack_syslog_device_spec.rb +0 -119
- data/spec/spec_helper.rb +0 -52
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fb001f870d1cfccdc29ec125be18dcff064b2d78e2731205db30704a9d2170c2
|
4
|
+
data.tar.gz: b9a73d61ec0ef1be9dd31cb35b36d405d265a8de5a2692480a3f98faef270c23
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 15851b8b81b2480ca0735173b9f9e2fa1b4d05147d6b4d64979c06a984df8adfd965fe384e4b8073c4b219bb6973948ada88a2aaae3a3647b8ed175ba683c4b7
|
7
|
+
data.tar.gz: 537be3b73a57c3d62abbcb31442c9d88242fa44e884b4b73739e8f72edb0272a383fa9ed0110bfda74a931f705367ca7bae97be137b460345ec33cda011923bd
|
data/CHANGE_LOG.md
ADDED
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Lumberjack Syslog Device
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/bdurand/lumberjack_syslog_device.svg?branch=master)](https://travis-ci.org/bdurand/lumberjack_syslog_device)
|
4
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/61785ec7e33012f55d65/maintainability)](https://codeclimate.com/github/bdurand/lumberjack_syslog_device/maintainability)
|
5
|
+
|
6
|
+
This gem provides a logging device for the [lumberjack](https://github.com/bdurand/lumberjack) gem that will log to syslog, the centralized system logging facility. See http://en.wikipedia.org/wiki/Syslog for more information on syslog.
|
7
|
+
|
8
|
+
## Example Usage
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
require 'lumberjack_syslog_device'
|
12
|
+
|
13
|
+
device = Lumberjack::SyslogDevice.new
|
14
|
+
logger = Lumberjack::Logger.new(device)
|
15
|
+
logger.info("Write me to syslog!")
|
16
|
+
```
|
17
|
+
|
18
|
+
See SyslogDevice for more details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'syslog'
|
2
4
|
require 'lumberjack'
|
3
5
|
|
4
6
|
module Lumberjack
|
5
7
|
# This Lumberjack device logs output to syslog. There can only be one connection to syslog
|
6
8
|
# open at a time. If you use syslog elsewhere in your application, you'll need to pass
|
7
|
-
#
|
9
|
+
# :close_connection => true to the constructor. Otherwise, the connection will be kept
|
8
10
|
# open between +write+ calls.
|
9
11
|
class SyslogDevice < Device
|
10
12
|
SEVERITY_MAP = {
|
@@ -15,57 +17,56 @@ module Lumberjack
|
|
15
17
|
Severity::FATAL => Syslog::LOG_CRIT,
|
16
18
|
Severity::UNKNOWN => Syslog::LOG_ALERT
|
17
19
|
}
|
18
|
-
|
20
|
+
|
19
21
|
PERCENT = '%'
|
20
22
|
ESCAPED_PERCENT = '%%'
|
21
|
-
|
23
|
+
|
22
24
|
@@lock = Mutex.new
|
23
|
-
|
24
|
-
|
25
|
+
|
25
26
|
# Create a new SyslogDevice. The options control how messages are written to syslog.
|
26
27
|
#
|
27
|
-
# The template can be specified using the
|
28
|
+
# The template can be specified using the :template option. This can
|
28
29
|
# either be a Proc or a string that will compile into a Template object.
|
29
30
|
# If the template is a Proc, it should accept an LogEntry as its only argument and output a string.
|
30
31
|
# If the template is a template string, it will be used to create a Template.
|
31
|
-
# The default template is
|
32
|
+
# The default template is `:message (#:unit_of_work_id) :tags`.
|
32
33
|
#
|
33
|
-
# The
|
34
|
+
# The :close_connection option can be used to specify that the connection to syslog should be
|
34
35
|
# closed after every +write+ call. This will slow down performance, but will allow you to use syslog
|
35
36
|
# elsewhere in your application.
|
36
37
|
#
|
37
|
-
# The
|
38
|
-
#
|
39
|
-
# *
|
40
|
-
# *
|
41
|
-
# *
|
42
|
-
# *
|
43
|
-
# *
|
44
|
-
# *
|
38
|
+
# The :options option will pass through options to syslog. The default is
|
39
|
+
# Syslog::LOG_PID | Syslog::LOG_CONS. Available values for the bit map are:
|
40
|
+
# * Syslog::LOG_CONS - Write directly to system console if there is an error while sending to system logger.
|
41
|
+
# * Syslog::LOG_NDELAY - Open the connection immediately (normally, the connection is opened when the first message is logged).
|
42
|
+
# * Syslog::LOG_NOWAIT - Don't wait for child processes that may have been created while logging the message.
|
43
|
+
# * Syslog::LOG_ODELAY - The converse of LOG_NDELAY; opening of the connection is delayed.
|
44
|
+
# * Syslog::LOG_PERROR - Print to stderr as well.
|
45
|
+
# * Syslog::LOG_PID - Include PID with each message.
|
45
46
|
#
|
46
|
-
# The
|
47
|
-
# *
|
48
|
-
# *
|
49
|
-
# *
|
50
|
-
# *
|
51
|
-
# *
|
52
|
-
# *
|
53
|
-
# *
|
54
|
-
# *
|
55
|
-
# *
|
56
|
-
# *
|
57
|
-
# *
|
58
|
-
# *
|
59
|
-
# *
|
47
|
+
# The :facility option will pass through a facility to syslog. Available values are
|
48
|
+
# * Syslog::LOG_AUTH
|
49
|
+
# * Syslog::LOG_AUTHPRIV
|
50
|
+
# * Syslog::LOG_CRON
|
51
|
+
# * Syslog::LOG_DAEMON
|
52
|
+
# * Syslog::LOG_FTP
|
53
|
+
# * Syslog::LOG_KERN
|
54
|
+
# * Syslog::LOG_LOCAL0 through Syslog::LOG_LOCAL7
|
55
|
+
# * Syslog::LOG_LPR
|
56
|
+
# * Syslog::LOG_MAIL
|
57
|
+
# * Syslog::LOG_NEWS
|
58
|
+
# * Syslog::LOG_SYSLOG
|
59
|
+
# * Syslog::LOG_USER (default)
|
60
|
+
# * Syslog::LOG_UUCP
|
60
61
|
def initialize(options = {})
|
61
|
-
@template = options[:template] ||
|
62
|
+
@template = options[:template] || default_template
|
62
63
|
@template = Template.new(@template) if @template.is_a?(String)
|
63
64
|
@syslog_options = options[:options] || (Syslog::LOG_PID | Syslog::LOG_CONS)
|
64
65
|
@syslog_facility = options[:facility]
|
65
66
|
@close_connection = options[:close_connection]
|
66
67
|
@syslog_identity = nil
|
67
68
|
end
|
68
|
-
|
69
|
+
|
69
70
|
def write(entry)
|
70
71
|
message = @template.call(entry).gsub(PERCENT, ESCAPED_PERCENT)
|
71
72
|
@@lock.synchronize do
|
@@ -77,28 +78,51 @@ module Lumberjack
|
|
77
78
|
end
|
78
79
|
end
|
79
80
|
end
|
80
|
-
|
81
|
+
|
81
82
|
def close
|
82
83
|
flush
|
83
84
|
@lock.synchronize do
|
84
85
|
@syslog.close if @syslog && @syslog.opened?
|
85
86
|
end
|
86
87
|
end
|
87
|
-
|
88
|
+
|
88
89
|
private
|
89
|
-
|
90
|
+
|
90
91
|
# Open syslog with ident set to progname. If it is already open with a different
|
91
92
|
# ident, close it and reopen it.
|
92
93
|
def open_syslog(progname) #:nodoc:
|
93
|
-
|
94
|
-
|
95
|
-
|
94
|
+
syslog_impl = syslog_implementation
|
95
|
+
if syslog_impl.opened?
|
96
|
+
if (progname.nil? || syslog_impl.ident == progname) && @syslog_facility == syslog_impl.facility && @syslog_options == syslog_impl.options
|
97
|
+
return syslog_impl
|
98
|
+
else
|
99
|
+
syslog_impl.close
|
96
100
|
end
|
97
|
-
Syslog.close
|
98
101
|
end
|
99
|
-
syslog =
|
102
|
+
syslog = syslog_impl.open(progname, @syslog_options, @syslog_facility)
|
100
103
|
syslog.mask = Syslog::LOG_UPTO(Syslog::LOG_DEBUG)
|
101
104
|
syslog
|
102
105
|
end
|
106
|
+
|
107
|
+
# Provided for testing purposes
|
108
|
+
def syslog_implementation #:nodoc:
|
109
|
+
Syslog
|
110
|
+
end
|
111
|
+
|
112
|
+
def default_template
|
113
|
+
lambda do |entry|
|
114
|
+
tags = entry.tags
|
115
|
+
if tags && !tags.empty?
|
116
|
+
message = String.new(entry.message)
|
117
|
+
message << " (#{entry.unit_of_work_id})" if entry.unit_of_work_id
|
118
|
+
tags.each do |name, value|
|
119
|
+
message << " [#{name}:#{value.inspect}]" unless name == Lumberjack::LogEntry::UNIT_OF_WORK_ID
|
120
|
+
end
|
121
|
+
message
|
122
|
+
else
|
123
|
+
entry.message
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
103
127
|
end
|
104
128
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'lumberjack_syslog_device'
|
3
|
+
spec.version = File.read(File.expand_path("../VERSION", __FILE__)).strip
|
4
|
+
spec.authors = ['Brian Durand']
|
5
|
+
spec.email = ['bbdurand@gmail.com']
|
6
|
+
|
7
|
+
spec.summary = "A logging device for the lumberjack gem that writes log entries to syslog."
|
8
|
+
spec.homepage = "https://github.com/bdurand/lumberjack_syslog_device"
|
9
|
+
spec.license = "MIT"
|
10
|
+
|
11
|
+
# Specify which files should be added to the gem when it is released.
|
12
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
13
|
+
ignore_files = %w(
|
14
|
+
.gitignore
|
15
|
+
.travis.yml
|
16
|
+
Appraisals
|
17
|
+
Gemfile
|
18
|
+
Gemfile.lock
|
19
|
+
Rakefile
|
20
|
+
gemfiles/
|
21
|
+
spec/
|
22
|
+
)
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject{ |f| ignore_files.any?{ |path| f.start_with?(path) } }
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
|
29
|
+
spec.add_dependency "lumberjack", ">=1.1"
|
30
|
+
|
31
|
+
spec.add_development_dependency("rspec", ["~> 3.0"])
|
32
|
+
spec.add_development_dependency "rake"
|
33
|
+
end
|
metadata
CHANGED
@@ -1,90 +1,91 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: lumberjack_syslog_device
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 0
|
10
|
-
version: 1.0.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Brian Durand
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2020-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
22
14
|
name: lumberjack
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 15
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 0
|
33
|
-
version: "1.0"
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
34
20
|
type: :runtime
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
-
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- bbdurand@gmail.com
|
39
58
|
executables: []
|
40
|
-
|
41
59
|
extensions: []
|
42
|
-
|
43
|
-
|
44
|
-
-
|
45
|
-
files:
|
46
|
-
- README.rdoc
|
47
|
-
- VERSION
|
48
|
-
- Rakefile
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- CHANGE_LOG.md
|
49
63
|
- MIT_LICENSE
|
64
|
+
- README.md
|
65
|
+
- VERSION
|
50
66
|
- lib/lumberjack_syslog_device.rb
|
51
|
-
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
67
|
+
- lumberjack_syslog_device.gemspec
|
68
|
+
homepage: https://github.com/bdurand/lumberjack_syslog_device
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
57
72
|
post_install_message:
|
58
|
-
rdoc_options:
|
59
|
-
|
60
|
-
- --main
|
61
|
-
- README.rdoc
|
62
|
-
require_paths:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
63
75
|
- lib
|
64
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
-
|
66
|
-
requirements:
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
67
78
|
- - ">="
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
version: "0"
|
73
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
|
-
requirements:
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
76
83
|
- - ">="
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
|
79
|
-
segments:
|
80
|
-
- 0
|
81
|
-
version: "0"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
82
86
|
requirements: []
|
83
|
-
|
84
|
-
rubyforge_project:
|
85
|
-
rubygems_version: 1.5.0
|
87
|
+
rubygems_version: 3.0.3
|
86
88
|
signing_key:
|
87
|
-
specification_version:
|
89
|
+
specification_version: 4
|
88
90
|
summary: A logging device for the lumberjack gem that writes log entries to syslog.
|
89
91
|
test_files: []
|
90
|
-
|
data/README.rdoc
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
Lumberjack Syslog Device
|
2
|
-
|
3
|
-
This gem provides a logging device for the lumberjack gem that will log to syslog, the centralized system logging facility. See http://en.wikipedia.org/wiki/Syslog for more information on syslog.
|
4
|
-
|
5
|
-
== Example Usage
|
6
|
-
|
7
|
-
require 'lumberjack_syslog_device'
|
8
|
-
|
9
|
-
device = Lumberjack::SyslogDevice.new
|
10
|
-
logger = Lumberjack::Logger.new(device)
|
11
|
-
logger.info("Write me to syslog!")
|
12
|
-
|
13
|
-
See SyslogDevice for more details.
|
data/Rakefile
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
require 'rake/gempackagetask'
|
4
|
-
require 'rake/rdoctask'
|
5
|
-
|
6
|
-
desc 'Default: run unit tests.'
|
7
|
-
task :default => :test
|
8
|
-
|
9
|
-
desc 'RVM likes to call it tests'
|
10
|
-
task :tests => :test
|
11
|
-
|
12
|
-
begin
|
13
|
-
require 'rspec'
|
14
|
-
require 'rspec/core/rake_task'
|
15
|
-
desc 'Run the unit tests'
|
16
|
-
RSpec::Core::RakeTask.new(:test)
|
17
|
-
rescue LoadError
|
18
|
-
task :test do
|
19
|
-
STDERR.puts "You must have rspec 2.0 installed to run the tests"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
desc 'Generate rdoc.'
|
24
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
25
|
-
rdoc.rdoc_dir = 'rdoc'
|
26
|
-
rdoc.options << '--title' << 'Lumberjack Syslog Device' << '--line-numbers' << '--inline-source' << '--main' << 'README.rdoc'
|
27
|
-
rdoc.rdoc_files.include('README.rdoc')
|
28
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
29
|
-
end
|
30
|
-
|
31
|
-
namespace :rbx do
|
32
|
-
desc "Cleanup *.rbc files in lib directory"
|
33
|
-
task :delete_rbc_files do
|
34
|
-
FileList["lib/**/*.rbc"].each do |rbc_file|
|
35
|
-
File.delete(rbc_file)
|
36
|
-
end
|
37
|
-
nil
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
spec_file = File.expand_path('../lumberjack_syslog_device.gemspec', __FILE__)
|
42
|
-
if File.exist?(spec_file)
|
43
|
-
spec = eval(File.read(spec_file))
|
44
|
-
|
45
|
-
Rake::GemPackageTask.new(spec) do |p|
|
46
|
-
p.gem_spec = spec
|
47
|
-
end
|
48
|
-
Rake.application["package"].prerequisites.unshift("rbx:delete_rbc_files")
|
49
|
-
|
50
|
-
desc "Release to rubygems.org"
|
51
|
-
task :release => :package do
|
52
|
-
require 'rake/gemcutter'
|
53
|
-
Rake::Gemcutter::Tasks.new(spec).define
|
54
|
-
Rake::Task['gem:push'].invoke
|
55
|
-
end
|
56
|
-
end
|
@@ -1,119 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Lumberjack::SyslogDevice do
|
4
|
-
|
5
|
-
let(:time){ Time.parse("2011-02-01T18:32:31Z") }
|
6
|
-
let(:entry){ Lumberjack::LogEntry.new(time, Lumberjack::Severity::WARN, "message 1", "lumberjack_syslog_device_spec", 12345, "ABCD") }
|
7
|
-
|
8
|
-
context "open connecton" do
|
9
|
-
it "should be able to specify syslog options" do
|
10
|
-
syslog = MockSyslog.new
|
11
|
-
device = Lumberjack::SyslogDevice.new(:options => Syslog::LOG_CONS)
|
12
|
-
Syslog.should_receive(:open).with(entry.progname, Syslog::LOG_CONS, nil).and_return(syslog)
|
13
|
-
device.write(entry)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should be able to specify a syslog facility" do
|
17
|
-
syslog = MockSyslog.new
|
18
|
-
device = Lumberjack::SyslogDevice.new(:facility => Syslog::LOG_FTP)
|
19
|
-
Syslog.should_receive(:open).with(entry.progname, (Syslog::LOG_PID | Syslog::LOG_CONS), Syslog::LOG_FTP).and_return(syslog)
|
20
|
-
device.write(entry)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should log all messages since the logger will filter them by severity" do
|
24
|
-
syslog = MockSyslog.new
|
25
|
-
device = Lumberjack::SyslogDevice.new
|
26
|
-
Syslog.should_receive(:open).with(entry.progname, (Syslog::LOG_PID | Syslog::LOG_CONS), nil).and_return(syslog)
|
27
|
-
device.write(entry)
|
28
|
-
syslog.mask.should == Syslog::LOG_UPTO(Syslog::LOG_DEBUG)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context "logging" do
|
33
|
-
it "should log entries to syslog" do
|
34
|
-
entry.unit_of_work_id = nil
|
35
|
-
device = Lumberjack::SyslogDevice.new
|
36
|
-
messages = read_syslog do
|
37
|
-
device.write(entry)
|
38
|
-
end
|
39
|
-
messages.first.should include("message 1")
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should log output to syslog with the unit of work id if it exists" do
|
43
|
-
device = Lumberjack::SyslogDevice.new
|
44
|
-
messages = read_syslog do
|
45
|
-
device.write(entry)
|
46
|
-
end
|
47
|
-
messages.first.should include("message 1 (#ABCD)")
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should be able to specify a string template" do
|
51
|
-
device = Lumberjack::SyslogDevice.new(:template => ":unit_of_work_id - :message")
|
52
|
-
messages = read_syslog do
|
53
|
-
device.write(entry)
|
54
|
-
end
|
55
|
-
messages.first.should include("ABCD - message 1")
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should be able to specify a proc template" do
|
59
|
-
device = Lumberjack::SyslogDevice.new(:template => lambda{|e| e.message.upcase})
|
60
|
-
messages = read_syslog do
|
61
|
-
device.write(entry)
|
62
|
-
end
|
63
|
-
messages.first.should include("MESSAGE 1")
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should properly handle percent signs in the syslog message" do
|
67
|
-
device = Lumberjack::SyslogDevice.new
|
68
|
-
entry.message = "message 100%"
|
69
|
-
messages = read_syslog do
|
70
|
-
device.write(entry)
|
71
|
-
end
|
72
|
-
messages.first.should include("message 100% (#ABCD)")
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should convert lumberjack severities to syslog severities" do
|
76
|
-
syslog = MockSyslog.new
|
77
|
-
device = Lumberjack::SyslogDevice.new
|
78
|
-
Syslog.stub!(:open).and_return(syslog)
|
79
|
-
syslog.should_receive(:log).with(Syslog::LOG_DEBUG, "debug")
|
80
|
-
syslog.should_receive(:log).with(Syslog::LOG_INFO, "info")
|
81
|
-
syslog.should_receive(:log).with(Syslog::LOG_WARNING, "warn")
|
82
|
-
syslog.should_receive(:log).with(Syslog::LOG_ERR, "error")
|
83
|
-
syslog.should_receive(:log).with(Syslog::LOG_CRIT, "fatal")
|
84
|
-
device.write(Lumberjack::LogEntry.new(Time.now, Lumberjack::Severity::DEBUG, "debug", "lumberjack_syslog_device_spec", 12345, nil))
|
85
|
-
device.write(Lumberjack::LogEntry.new(Time.now, Lumberjack::Severity::INFO, "info", "lumberjack_syslog_device_spec", 12345, nil))
|
86
|
-
device.write(Lumberjack::LogEntry.new(Time.now, Lumberjack::Severity::WARN, "warn", "lumberjack_syslog_device_spec", 12345, nil))
|
87
|
-
device.write(Lumberjack::LogEntry.new(Time.now, Lumberjack::Severity::ERROR, "error", "lumberjack_syslog_device_spec", 12345, nil))
|
88
|
-
device.write(Lumberjack::LogEntry.new(Time.now, Lumberjack::Severity::FATAL, "fatal", "lumberjack_syslog_device_spec", 12345, nil))
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should log messages with the syslog ident set to the progname" do
|
92
|
-
device = Lumberjack::SyslogDevice.new
|
93
|
-
messages = read_syslog("lumberjack_syslog_device") do
|
94
|
-
device.write(entry)
|
95
|
-
entry.progname = "spec_for_lumberjack_syslog_device"
|
96
|
-
entry.message = "new message"
|
97
|
-
device.write(entry)
|
98
|
-
end
|
99
|
-
messages.first.should include("lumberjack_syslog_device_spec")
|
100
|
-
messages.last.should include("spec_for_lumberjack_syslog_device")
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should keep open the syslog connection by default" do
|
104
|
-
device = Lumberjack::SyslogDevice.new
|
105
|
-
messages = read_syslog do
|
106
|
-
device.write(entry)
|
107
|
-
Syslog.should be_opened
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should close the syslog connection if :close_connection is true" do
|
112
|
-
device = Lumberjack::SyslogDevice.new(:close_connection => true)
|
113
|
-
messages = read_syslog do
|
114
|
-
device.write(entry)
|
115
|
-
Syslog.should_not be_opened
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require File.expand_path("../../lib/lumberjack_syslog_device.rb", __FILE__)
|
2
|
-
|
3
|
-
SYSLOG_FILE = ENV["SYSLOG_FILE"] || "/var/log/system.log"
|
4
|
-
|
5
|
-
# Round about way of reading syslog by following it using the command line and looking in the output.
|
6
|
-
def read_syslog(progname = "lumberjack_syslog_device_spec")
|
7
|
-
message_id = rand(0xFFFFFFFFFFFFFFFF)
|
8
|
-
Syslog.open("lumberjack_syslog_device_spec") do |syslog|
|
9
|
-
syslog.mask = Syslog::LOG_UPTO(Syslog::LOG_DEBUG)
|
10
|
-
syslog.warning("************** start #{message_id}")
|
11
|
-
end
|
12
|
-
|
13
|
-
yield
|
14
|
-
|
15
|
-
Syslog.close if Syslog.opened?
|
16
|
-
Syslog.open("lumberjack_syslog_device_spec") do |syslog|
|
17
|
-
syslog.mask = Syslog::LOG_UPTO(Syslog::LOG_DEBUG)
|
18
|
-
syslog.warning("************** end #{message_id}")
|
19
|
-
end
|
20
|
-
|
21
|
-
# Loop over the syslog file until the start and end markers are found
|
22
|
-
8.times do
|
23
|
-
retval = nil
|
24
|
-
lines = `tail -500 #{SYSLOG_FILE}`.split("\n")
|
25
|
-
lines.each do |line|
|
26
|
-
if line.include?("start #{message_id}")
|
27
|
-
retval = []
|
28
|
-
elsif line.include?("end #{message_id}")
|
29
|
-
return retval
|
30
|
-
else
|
31
|
-
retval << line if retval && line.include?(progname)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
break if retval
|
35
|
-
sleep(0.25)
|
36
|
-
end
|
37
|
-
raise "could not find message logged to #{SYSLOG_FILE}"
|
38
|
-
end
|
39
|
-
|
40
|
-
class MockSyslog
|
41
|
-
attr_accessor :mask
|
42
|
-
attr_reader :ident, :options, :facility
|
43
|
-
|
44
|
-
def open(ident, options, facility)
|
45
|
-
@ident = ident
|
46
|
-
@options = options
|
47
|
-
@facility = facility
|
48
|
-
end
|
49
|
-
|
50
|
-
def log(*args)
|
51
|
-
end
|
52
|
-
end
|