lumberjack_syslog_device 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 05cda0528c884ab6d20bc8248c33a4ceaea7e03d7290597a0f38a416792298dd
4
+ data.tar.gz: 77d51847f6bedd3c998084b6d7346351f3757cb7981f8b97f06b76a053ca6c13
5
+ SHA512:
6
+ metadata.gz: 531c7966e066dd4618058306c096553cad8fd6ce36e0e40794bcaffad6ec1bee8456cf3178c456ea6b99a896a066f98a5af1406fb577a5b4123286bd2c0f92a0
7
+ data.tar.gz: 848b6bc544c0e437648e1f7b73d337f8b83790ab264cc8f8f667367a1be3c3c6d12973fc13a4834781b9976826759d80f5ea5bf9d43245ec17f9b6068c02c14b
@@ -0,0 +1,12 @@
1
+ # Dependabot update strategy
2
+ version: 2
3
+ updates:
4
+ - package-ecosystem: bundler
5
+ directory: "/"
6
+ schedule:
7
+ interval: weekly
8
+ allow:
9
+ # Automatically keep all runtime dependencies updated
10
+ - dependency-name: "*"
11
+ dependency-type: "production"
12
+ versioning-strategy: lockfile-only
@@ -0,0 +1,47 @@
1
+ name: Continuous Integration
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ - actions-*
8
+ tags:
9
+ - v*
10
+ pull_request:
11
+ branches-ignore:
12
+ - actions-*
13
+
14
+ env:
15
+ BUNDLE_CLEAN: "true"
16
+ BUNDLE_PATH: vendor/bundle
17
+ BUNDLE_JOBS: 3
18
+ BUNDLE_RETRY: 3
19
+
20
+ jobs:
21
+ build:
22
+ name: ${{ matrix.ruby }} build
23
+ runs-on: ubuntu-latest
24
+ strategy:
25
+ matrix:
26
+ include:
27
+ - ruby: "ruby"
28
+ standardrb: true
29
+ - ruby: "3.0"
30
+ - ruby: "2.7"
31
+ - ruby: "2.6"
32
+ - ruby: "2.5"
33
+ - ruby: "2.4"
34
+ steps:
35
+ - uses: actions/checkout@v2
36
+ - name: Set up Ruby
37
+ uses: ruby/setup-ruby@v1
38
+ with:
39
+ ruby-version: ${{ matrix.ruby}}
40
+ - name: Install gems
41
+ run: |
42
+ bundle install
43
+ - name: Run Tests
44
+ run: bundle exec rake
45
+ - name: standardrb
46
+ if: matrix.standardrb
47
+ run: bundle exec standardrb
@@ -0,0 +1,29 @@
1
+ name: Regression Test
2
+ on:
3
+ workflow_dispatch:
4
+ schedule:
5
+ - cron: "0 15 * * 1"
6
+ env:
7
+ BUNDLE_CLEAN: "true"
8
+ BUNDLE_PATH: vendor/bundle
9
+ BUNDLE_JOBS: 3
10
+ BUNDLE_RETRY: 3
11
+ jobs:
12
+ specs:
13
+ name: Run specs
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ fail-fast: false
17
+ steps:
18
+ - name: Checkout
19
+ uses: actions/checkout@v4
20
+ - name: Set up Ruby ${{ matrix.ruby }}
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ruby
24
+ - name: Install bundler
25
+ run: |
26
+ bundle update
27
+ - name: Run specs
28
+ run: |
29
+ bundle exec rake spec
data/.standard.yml ADDED
@@ -0,0 +1,10 @@
1
+ # I really just have issues with the automatic "semantic blocks"
2
+
3
+ ruby_version: 2.4
4
+
5
+ format: progress
6
+
7
+ ignore:
8
+ - 'spec/**/*':
9
+ - Lint/UselessAssignment
10
+ - Lint/Void
data/CHANGE_LOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## 1.1.1
8
+
9
+ ### Changed
10
+
11
+ - Always cast values to strings before logging to syslog (thanks @eremeyev).
12
+
13
+ ## 1.1.0
14
+
15
+ ### Added
16
+
17
+ - Add support for lumberjack 2.0 tags.
18
+
19
+ ## 1.0.0
20
+
21
+ ### Added
22
+
23
+ - Initial release.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Lumberjack Syslog Device
2
+
3
+ [![Continuous Integration](https://github.com/bdurand/lumberjack_syslog_device/actions/workflows/continuous_integration.yml/badge.svg)](https://github.com/bdurand/lumberjack_syslog_device/actions/workflows/continuous_integration.yml)
4
+ [![Regression Test](https://github.com/bdurand/lumberjack_syslog_device/actions/workflows/regression_test.yml/badge.svg)](https://github.com/bdurand/lumberjack_syslog_device/actions/workflows/regression_test.yml)
5
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
6
+
7
+ 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.
8
+
9
+ ## Usage
10
+
11
+ ```ruby
12
+ require 'lumberjack_syslog_device'
13
+
14
+ device = Lumberjack::SyslogDevice.new
15
+ logger = Lumberjack::Logger.new(device)
16
+ logger.info("Write me to syslog!")
17
+ ```
18
+
19
+ See the docs in the Lumberjack::SyslogDevice file for more details.
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ ```ruby
26
+ gem 'lumberjack_syslog_device'
27
+ ```
28
+
29
+ And then execute:
30
+ ```bash
31
+ $ bundle
32
+ ```
33
+
34
+ Or install it yourself as:
35
+ ```bash
36
+ $ gem install lumberjack_syslog_device
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ Open a pull request on GitHub.
42
+
43
+ Please use the [standardrb](https://github.com/testdouble/standard) syntax and lint your code with `standardrb --fix` before submitting.
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.1
@@ -1,10 +1,12 @@
1
- require 'syslog'
2
- require 'lumberjack'
1
+ # frozen_string_literal: true
2
+
3
+ require "syslog"
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
- # <tt>:close_connection => true</tt> to the constructor. Otherwise, the connection will be kept
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,59 +17,58 @@ module Lumberjack
15
17
  Severity::FATAL => Syslog::LOG_CRIT,
16
18
  Severity::UNKNOWN => Syslog::LOG_ALERT
17
19
  }
18
-
19
- PERCENT = '%'
20
- ESCAPED_PERCENT = '%%'
21
-
20
+
21
+ PERCENT = "%"
22
+ ESCAPED_PERCENT = "%%"
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 <tt>:template</tt> option. This can
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 <tt>":message (#:unit_of_work_id)"</tt>.
32
+ # The default template is `:message (#:unit_of_work_id) :tags`.
32
33
  #
33
- # The <tt>:close_connection</tt> option can be used to specify that the connection to syslog should be
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 <tt>:options</tt> option will pass through options to syslog. The default is
38
- # <tt>Syslog::LOG_PID | Syslog::LOG_CONS</tt>. Available values for the bit map are:
39
- # * <tt>Syslog::LOG_CONS</tt> - Write directly to system console if there is an error while sending to system logger.
40
- # * <tt>Syslog::LOG_NDELAY</tt> - Open the connection immediately (normally, the connection is opened when the first message is logged).
41
- # * <tt>Syslog::LOG_NOWAIT</tt> - Don't wait for child processes that may have been created while logging the message.
42
- # * <tt>Syslog::LOG_ODELAY</tt> - The converse of LOG_NDELAY; opening of the connection is delayed.
43
- # * <tt>Syslog::LOG_PERROR</tt> - Print to stderr as well.
44
- # * <tt>Syslog::LOG_PID</tt> - Include PID with each message.
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 <tt>:facility</tt> option will pass through a facility to syslog. Available values are
47
- # * <tt>Syslog::LOG_AUTH</tt>
48
- # * <tt>Syslog::LOG_AUTHPRIV</tt>
49
- # * <tt>Syslog::LOG_CRON</tt>
50
- # * <tt>Syslog::LOG_DAEMON</tt>
51
- # * <tt>Syslog::LOG_FTP</tt>
52
- # * <tt>Syslog::LOG_KERN</tt>
53
- # * <tt>Syslog::LOG_LOCAL0</tt> through <tt>Syslog::LOG_LOCAL7</tt>
54
- # * <tt>Syslog::LOG_LPR</tt>
55
- # * <tt>Syslog::LOG_MAIL</tt>
56
- # * <tt>Syslog::LOG_NEWS</tt>
57
- # * <tt>Syslog::LOG_SYSLOG</tt>
58
- # * <tt>Syslog::LOG_USER</tt> (default)
59
- # * <tt>Syslog::LOG_UUCP</tt>
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] || lambda{|entry| entry.unit_of_work_id ? "#{entry.message} (##{entry.unit_of_work_id})" : entry.message}
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
- message = @template.call(entry).gsub(PERCENT, ESCAPED_PERCENT)
71
+ message = @template.call(entry).to_s.gsub(PERCENT, ESCAPED_PERCENT)
71
72
  @@lock.synchronize do
72
73
  syslog = open_syslog(entry.progname)
73
74
  begin
@@ -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
- @syslog.close if @syslog && @syslog.opened?
85
+ @syslog.close if @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
- def open_syslog(progname) #:nodoc:
93
- if Syslog.opened?
94
- if (progname.nil? || Syslog.ident == progname) && @syslog_facility == Syslog.facility && @syslog_options == Syslog.options
95
- return Syslog
93
+ def open_syslog(progname) # :nodoc:
94
+ syslog_impl = syslog_implementation
95
+ if syslog_impl.opened?
96
+ if (progname.nil? || syslog_impl.ident == progname.to_s) && @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 = Syslog.open(progname, @syslog_options, @syslog_facility)
102
+ syslog = syslog_impl.open(progname.to_s, @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,34 @@
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.required_ruby_version = ">=2.4"
30
+
31
+ spec.add_dependency "lumberjack", ">=1.1"
32
+
33
+ spec.add_development_dependency "bundler"
34
+ end
metadata CHANGED
@@ -1,90 +1,81 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: lumberjack_syslog_device
3
- version: !ruby/object:Gem::Version
4
- hash: 23
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.1
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Brian Durand
14
- autorequire:
8
+ autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-02-11 00:00:00 -06:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
11
+ date: 2023-11-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
22
14
  name: lumberjack
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
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
- version_requirements: *id001
36
- description: A logging device for the lumberjack gem that writes log entries to syslog.
37
- email:
38
- - bdurand@embellishedvisions.com
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - bbdurand@gmail.com
39
44
  executables: []
40
-
41
45
  extensions: []
42
-
43
- extra_rdoc_files:
44
- - README.rdoc
45
- files:
46
- - README.rdoc
47
- - VERSION
48
- - Rakefile
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".github/dependabot.yml"
49
+ - ".github/workflows/continuous_integration.yml"
50
+ - ".github/workflows/regression_test.yml"
51
+ - ".standard.yml"
52
+ - CHANGE_LOG.md
49
53
  - MIT_LICENSE
54
+ - README.md
55
+ - VERSION
50
56
  - lib/lumberjack_syslog_device.rb
51
- - spec/lumberjack_syslog_device_spec.rb
52
- - spec/spec_helper.rb
53
- has_rdoc: true
54
- homepage: http://github.com/bdurand/lumberjack_mongo_device
55
- licenses: []
56
-
57
- post_install_message:
58
- rdoc_options:
59
- - --charset=UTF-8
60
- - --main
61
- - README.rdoc
62
- require_paths:
57
+ - lumberjack_syslog_device.gemspec
58
+ homepage: https://github.com/bdurand/lumberjack_syslog_device
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
63
65
  - lib
64
- required_ruby_version: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
67
68
  - - ">="
68
- - !ruby/object:Gem::Version
69
- hash: 3
70
- segments:
71
- - 0
72
- version: "0"
73
- required_rubygems_version: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
69
+ - !ruby/object:Gem::Version
70
+ version: '2.4'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
76
73
  - - ">="
77
- - !ruby/object:Gem::Version
78
- hash: 3
79
- segments:
80
- - 0
81
- version: "0"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
82
76
  requirements: []
83
-
84
- rubyforge_project:
85
- rubygems_version: 1.5.0
86
- signing_key:
87
- specification_version: 3
77
+ rubygems_version: 3.4.12
78
+ signing_key:
79
+ specification_version: 4
88
80
  summary: A logging device for the lumberjack gem that writes log entries to syslog.
89
81
  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