lumberjack_syslog_device 1.1.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05cda0528c884ab6d20bc8248c33a4ceaea7e03d7290597a0f38a416792298dd
4
- data.tar.gz: 77d51847f6bedd3c998084b6d7346351f3757cb7981f8b97f06b76a053ca6c13
3
+ metadata.gz: 54c251e482e25bc736ad9947d10faee5afe7ea0df526df3ba7aaf80cb2487258
4
+ data.tar.gz: 1a190f22ebeb58d6b93388184b01270c8348f00444e3d94b122239c89791c9da
5
5
  SHA512:
6
- metadata.gz: 531c7966e066dd4618058306c096553cad8fd6ce36e0e40794bcaffad6ec1bee8456cf3178c456ea6b99a896a066f98a5af1406fb577a5b4123286bd2c0f92a0
7
- data.tar.gz: 848b6bc544c0e437648e1f7b73d337f8b83790ab264cc8f8f667367a1be3c3c6d12973fc13a4834781b9976826759d80f5ea5bf9d43245ec17f9b6068c02c14b
6
+ metadata.gz: 0d0091c9a2887b37f471fe65ce665fca5047d399c116ccf29305d401b1888c9094cd0c09bc98f4682043241aed7df2da0b1434b3d8e7959453bcb503b4a23ef0
7
+ data.tar.gz: 8dcb7a000c0c391fe1d92a07e7e0bf021fdd3120ddccdde277f5a33ff902bdb86f38a895b6437001ce61d039a9a42a8a7cbc772a86c53e58d7a7600a9b400a6f
@@ -3,13 +3,12 @@ name: Continuous Integration
3
3
  on:
4
4
  push:
5
5
  branches:
6
- - master
6
+ - main
7
7
  - actions-*
8
- tags:
9
- - v*
10
8
  pull_request:
11
9
  branches-ignore:
12
10
  - actions-*
11
+ workflow_dispatch:
13
12
 
14
13
  env:
15
14
  BUNDLE_CLEAN: "true"
@@ -26,13 +25,11 @@ jobs:
26
25
  include:
27
26
  - ruby: "ruby"
28
27
  standardrb: true
28
+ yard: true
29
29
  - ruby: "3.0"
30
30
  - ruby: "2.7"
31
- - ruby: "2.6"
32
- - ruby: "2.5"
33
- - ruby: "2.4"
34
31
  steps:
35
- - uses: actions/checkout@v2
32
+ - uses: actions/checkout@v4
36
33
  - name: Set up Ruby
37
34
  uses: ruby/setup-ruby@v1
38
35
  with:
@@ -45,3 +42,6 @@ jobs:
45
42
  - name: standardrb
46
43
  if: matrix.standardrb
47
44
  run: bundle exec standardrb
45
+ - name: yard
46
+ if: matrix.yard == true
47
+ run: bundle exec yard --fail-on-warning
data/.standard.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # I really just have issues with the automatic "semantic blocks"
2
2
 
3
- ruby_version: 2.4
3
+ ruby_version: 2.7
4
4
 
5
5
  format: progress
6
6
 
data/CHANGE_LOG.md CHANGED
@@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## 2.0.0
8
+
9
+ ### Added
10
+
11
+ - Lumberjack 2 support.
12
+
13
+ ### Changed
14
+
15
+ - Updated default template to `{{message}} {{attributes}}`. Unit of work is no longer supported in Lumberjack 2.
16
+ - Updated attribute formatting to use tag formatting specified in the `:tag_format` option rather than hardcoding the format.
17
+
18
+ ### Removed
19
+
20
+ - Support for Ruby < 2.7.
21
+
7
22
  ## 1.1.1
8
23
 
9
24
  ### Changed
@@ -14,7 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14
29
 
15
30
  ### Added
16
31
 
17
- - Add support for lumberjack 2.0 tags.
32
+ - Add support for lumberjack 1.1 tags.
18
33
 
19
34
  ## 1.0.0
20
35
 
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Lumberjack Syslog Device
2
2
 
3
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
4
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
5
+ [![Gem Version](https://badge.fury.io/rb/lumberjack_syslog_device.svg)](https://badge.fury.io/rb/lumberjack_syslog_device)
6
6
 
7
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
8
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 2.0.0
@@ -0,0 +1,136 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "syslog"
4
+ require "lumberjack"
5
+
6
+ # Lumberjack is a simple, powerful, and very fast logging utility that can be a drop
7
+ # in replacement for Logger or ActiveSupport::BufferedLogger.
8
+ module Lumberjack
9
+ # This Lumberjack device logs output to syslog. There can only be one connection to syslog
10
+ # open at a time. If you use syslog elsewhere in your application, you'll need to pass
11
+ # :close_connection => true to the constructor. Otherwise, the connection will be kept
12
+ # open between +write+ calls.
13
+ class SyslogDevice < Device
14
+ VERSION = ::File.read(::File.join(__dir__, "..", "..", "VERSION")).strip.freeze
15
+
16
+ # Mapping of Lumberjack severity levels to syslog priority levels
17
+ SEVERITY_MAP = {
18
+ Severity::TRACE => Syslog::LOG_DEBUG,
19
+ Severity::DEBUG => Syslog::LOG_DEBUG,
20
+ Severity::INFO => Syslog::LOG_INFO,
21
+ Severity::WARN => Syslog::LOG_WARNING,
22
+ Severity::ERROR => Syslog::LOG_ERR,
23
+ Severity::FATAL => Syslog::LOG_CRIT,
24
+ Severity::UNKNOWN => Syslog::LOG_ALERT
25
+ }
26
+
27
+ # Literal percent character
28
+ PERCENT = "%"
29
+ # Escaped percent character for syslog format strings
30
+ ESCAPED_PERCENT = "%%"
31
+
32
+ # Default template for formatting log messages
33
+ DEFAULT_TEMPLATE = "{{message}} {{attributes}}"
34
+ # Default format for rendering log entry attributes
35
+ DEFAULT_ATTRIBUTE_FORMAT = "[%s:%s]"
36
+
37
+ DeviceRegistry.add(:syslog, self)
38
+
39
+ @@lock = Mutex.new
40
+
41
+ # Create a new SyslogDevice. The options control how messages are written to syslog.
42
+ #
43
+ # The template can be specified using the :template option. This can
44
+ # either be a Proc or a string that will compile into a Template object.
45
+ # If the template is a Proc, it should accept an LogEntry as its only argument and output a string.
46
+ # If the template is a template string, it will be used to create a Template.
47
+ # The default template is +{{message}} {{attributes}}+.
48
+ #
49
+ # The :close_connection option can be used to specify that the connection to syslog should be
50
+ # closed after every +write+ call. This will slow down performance, but will allow you to use syslog
51
+ # elsewhere in your application.
52
+ #
53
+ # The :options option will pass through options to syslog. The default is
54
+ # Syslog::LOG_PID | Syslog::LOG_CONS. Available values for the bit map are:
55
+ # * Syslog::LOG_CONS - Write directly to system console if there is an error while sending to system logger.
56
+ # * Syslog::LOG_NDELAY - Open the connection immediately (normally, the connection is opened when the first message is logged).
57
+ # * Syslog::LOG_NOWAIT - Don't wait for child processes that may have been created while logging the message.
58
+ # * Syslog::LOG_ODELAY - The converse of LOG_NDELAY; opening of the connection is delayed.
59
+ # * Syslog::LOG_PERROR - Print to stderr as well.
60
+ # * Syslog::LOG_PID - Include PID with each message.
61
+ #
62
+ # The :facility option will pass through a facility to syslog. Available values are
63
+ # * Syslog::LOG_AUTH
64
+ # * Syslog::LOG_AUTHPRIV
65
+ # * Syslog::LOG_CRON
66
+ # * Syslog::LOG_DAEMON
67
+ # * Syslog::LOG_FTP
68
+ # * Syslog::LOG_KERN
69
+ # * Syslog::LOG_LOCAL0 through Syslog::LOG_LOCAL7
70
+ # * Syslog::LOG_LPR
71
+ # * Syslog::LOG_MAIL
72
+ # * Syslog::LOG_NEWS
73
+ # * Syslog::LOG_SYSLOG
74
+ # * Syslog::LOG_USER (default)
75
+ # * Syslog::LOG_UUCP
76
+ def initialize(options = {})
77
+ @template = options[:template] || DEFAULT_TEMPLATE
78
+ attribute_format = options[:attribute_format] || DEFAULT_ATTRIBUTE_FORMAT
79
+ @template = Template.new(@template, attribute_format: attribute_format) if @template.is_a?(String)
80
+
81
+ @syslog_options = options[:options] || (Syslog::LOG_PID | Syslog::LOG_CONS)
82
+ @syslog_facility = options[:facility]
83
+ @close_connection = options[:close_connection]
84
+ @syslog_identity = nil
85
+ end
86
+
87
+ # Write a log entry to syslog.
88
+ #
89
+ # @param entry [Lumberjack::LogEntry] the log entry to write
90
+ # @return [void]
91
+ def write(entry)
92
+ message = @template.call(entry).to_s.chomp.gsub(PERCENT, ESCAPED_PERCENT)
93
+ @@lock.synchronize do
94
+ syslog = open_syslog(entry.progname)
95
+ begin
96
+ syslog.log(SEVERITY_MAP[entry.severity], message)
97
+ ensure
98
+ syslog.close if @close_connection
99
+ end
100
+ end
101
+ end
102
+
103
+ # Close the syslog connection.
104
+ #
105
+ # @return [void]
106
+ def close
107
+ flush
108
+ @lock.synchronize do
109
+ @syslog.close if @syslog&.opened?
110
+ end
111
+ end
112
+
113
+ private
114
+
115
+ # Open syslog with ident set to progname. If it is already open with a different
116
+ # ident, close it and reopen it.
117
+ def open_syslog(progname) # :nodoc:
118
+ syslog_impl = syslog_implementation
119
+ if syslog_impl.opened?
120
+ if (progname.nil? || syslog_impl.ident == progname.to_s) && @syslog_facility == syslog_impl.facility && @syslog_options == syslog_impl.options
121
+ return syslog_impl
122
+ else
123
+ syslog_impl.close
124
+ end
125
+ end
126
+ syslog = syslog_impl.open(progname.to_s, @syslog_options, @syslog_facility)
127
+ syslog.mask = Syslog::LOG_UPTO(Syslog::LOG_DEBUG)
128
+ syslog
129
+ end
130
+
131
+ # Provided for testing purposes
132
+ def syslog_implementation # :nodoc:
133
+ Syslog
134
+ end
135
+ end
136
+ end
@@ -1,128 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "syslog"
4
- require "lumberjack"
5
-
6
- module Lumberjack
7
- # This Lumberjack device logs output to syslog. There can only be one connection to syslog
8
- # open at a time. If you use syslog elsewhere in your application, you'll need to pass
9
- # :close_connection => true to the constructor. Otherwise, the connection will be kept
10
- # open between +write+ calls.
11
- class SyslogDevice < Device
12
- SEVERITY_MAP = {
13
- Severity::DEBUG => Syslog::LOG_DEBUG,
14
- Severity::INFO => Syslog::LOG_INFO,
15
- Severity::WARN => Syslog::LOG_WARNING,
16
- Severity::ERROR => Syslog::LOG_ERR,
17
- Severity::FATAL => Syslog::LOG_CRIT,
18
- Severity::UNKNOWN => Syslog::LOG_ALERT
19
- }
20
-
21
- PERCENT = "%"
22
- ESCAPED_PERCENT = "%%"
23
-
24
- @@lock = Mutex.new
25
-
26
- # Create a new SyslogDevice. The options control how messages are written to syslog.
27
- #
28
- # The template can be specified using the :template option. This can
29
- # either be a Proc or a string that will compile into a Template object.
30
- # If the template is a Proc, it should accept an LogEntry as its only argument and output a string.
31
- # If the template is a template string, it will be used to create a Template.
32
- # The default template is `:message (#:unit_of_work_id) :tags`.
33
- #
34
- # The :close_connection option can be used to specify that the connection to syslog should be
35
- # closed after every +write+ call. This will slow down performance, but will allow you to use syslog
36
- # elsewhere in your application.
37
- #
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.
46
- #
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
61
- def initialize(options = {})
62
- @template = options[:template] || default_template
63
- @template = Template.new(@template) if @template.is_a?(String)
64
- @syslog_options = options[:options] || (Syslog::LOG_PID | Syslog::LOG_CONS)
65
- @syslog_facility = options[:facility]
66
- @close_connection = options[:close_connection]
67
- @syslog_identity = nil
68
- end
69
-
70
- def write(entry)
71
- message = @template.call(entry).to_s.gsub(PERCENT, ESCAPED_PERCENT)
72
- @@lock.synchronize do
73
- syslog = open_syslog(entry.progname)
74
- begin
75
- syslog.log(SEVERITY_MAP[entry.severity], message)
76
- ensure
77
- syslog.close if @close_connection
78
- end
79
- end
80
- end
81
-
82
- def close
83
- flush
84
- @lock.synchronize do
85
- @syslog.close if @syslog&.opened?
86
- end
87
- end
88
-
89
- private
90
-
91
- # Open syslog with ident set to progname. If it is already open with a different
92
- # ident, close it and reopen it.
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
100
- end
101
- end
102
- syslog = syslog_impl.open(progname.to_s, @syslog_options, @syslog_facility)
103
- syslog.mask = Syslog::LOG_UPTO(Syslog::LOG_DEBUG)
104
- syslog
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
127
- end
128
- end
3
+ require_relative "lumberjack/syslog_device"
@@ -8,6 +8,12 @@ Gem::Specification.new do |spec|
8
8
  spec.homepage = "https://github.com/bdurand/lumberjack_syslog_device"
9
9
  spec.license = "MIT"
10
10
 
11
+ spec.metadata = {
12
+ "homepage_uri" => spec.homepage,
13
+ "source_code_uri" => spec.homepage,
14
+ "changelog_uri" => "#{spec.homepage}/blob/main/CHANGE_LOG.md"
15
+ }
16
+
11
17
  # Specify which files should be added to the gem when it is released.
12
18
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
13
19
  ignore_files = %w[
@@ -26,9 +32,10 @@ Gem::Specification.new do |spec|
26
32
 
27
33
  spec.require_paths = ["lib"]
28
34
 
29
- spec.required_ruby_version = ">=2.4"
35
+ spec.required_ruby_version = ">=2.7"
30
36
 
31
- spec.add_dependency "lumberjack", ">=1.1"
37
+ spec.add_dependency "lumberjack", ">=2.0"
38
+ spec.add_dependency "syslog"
32
39
 
33
40
  spec.add_development_dependency "bundler"
34
41
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lumberjack_syslog_device
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-11-12 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: lumberjack
@@ -16,14 +15,28 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '1.1'
18
+ version: '2.0'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: '1.1'
25
+ version: '2.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: syslog
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
27
40
  - !ruby/object:Gem::Dependency
28
41
  name: bundler
29
42
  requirement: !ruby/object:Gem::Requirement
@@ -38,7 +51,6 @@ dependencies:
38
51
  - - ">="
39
52
  - !ruby/object:Gem::Version
40
53
  version: '0'
41
- description:
42
54
  email:
43
55
  - bbdurand@gmail.com
44
56
  executables: []
@@ -47,19 +59,21 @@ extra_rdoc_files: []
47
59
  files:
48
60
  - ".github/dependabot.yml"
49
61
  - ".github/workflows/continuous_integration.yml"
50
- - ".github/workflows/regression_test.yml"
51
62
  - ".standard.yml"
52
63
  - CHANGE_LOG.md
53
- - MIT_LICENSE
64
+ - MIT_LICENSE.txt
54
65
  - README.md
55
66
  - VERSION
67
+ - lib/lumberjack/syslog_device.rb
56
68
  - lib/lumberjack_syslog_device.rb
57
69
  - lumberjack_syslog_device.gemspec
58
70
  homepage: https://github.com/bdurand/lumberjack_syslog_device
59
71
  licenses:
60
72
  - MIT
61
- metadata: {}
62
- post_install_message:
73
+ metadata:
74
+ homepage_uri: https://github.com/bdurand/lumberjack_syslog_device
75
+ source_code_uri: https://github.com/bdurand/lumberjack_syslog_device
76
+ changelog_uri: https://github.com/bdurand/lumberjack_syslog_device/blob/main/CHANGE_LOG.md
63
77
  rdoc_options: []
64
78
  require_paths:
65
79
  - lib
@@ -67,15 +81,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
81
  requirements:
68
82
  - - ">="
69
83
  - !ruby/object:Gem::Version
70
- version: '2.4'
84
+ version: '2.7'
71
85
  required_rubygems_version: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0'
76
90
  requirements: []
77
- rubygems_version: 3.4.12
78
- signing_key:
91
+ rubygems_version: 3.6.9
79
92
  specification_version: 4
80
93
  summary: A logging device for the lumberjack gem that writes log entries to syslog.
81
94
  test_files: []
@@ -1,29 +0,0 @@
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
File without changes