syslogger 1.6.5 → 1.6.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 10037fda0f96cf2e4073a7b721083696f1b30404
4
- data.tar.gz: e483814598921fe12e703c5b519abe904121b290
2
+ SHA256:
3
+ metadata.gz: f36b2f4ea6682e821787ea055e08b01368b4568544bc41a71dd93bde6ed0390b
4
+ data.tar.gz: b951b4952c20d20882b161675785cbcb2430b1c9d229d01d56f3c9c4152d7fc9
5
5
  SHA512:
6
- metadata.gz: 4eff79de93b2c28c2ec407d6d4675f815698894f0b4f2ceb79e9a7f0d96e54655310f96ccfa69244f3c742daa55e242491a09499a9f41827b40db969672d5be3
7
- data.tar.gz: 66deff30ebd629b8d0251981b0c8f4530c72764bb0c56bdfdc97ba5ca403993626e098f106717020dbdc1abe0287dd3b53d3507bd33c75a36483a69035748872
6
+ metadata.gz: 2567599956b7b79965b7617e1bbb2caecbed9c482bf7d3792e25247133bb4179ac31fc88109d03223172677734080a169bdd869ba232765a2022a538e4dcb8b6
7
+ data.tar.gz: 262ef1518804b333cb846a40b2607f7c5389276dbb10a0dc9bb6e19dc9c7819aa67f6a821d36b69abc9d886f2b2066fda66572b2f790cdd40f43872d29f4e99d
@@ -0,0 +1,58 @@
1
+ ---
2
+ name: CI
3
+
4
+ on:
5
+ - push
6
+ - pull_request
7
+
8
+ jobs:
9
+ rspec:
10
+ runs-on: ubuntu-20.04
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ ruby:
15
+ - '3.0'
16
+ - '2.7'
17
+ - '2.6'
18
+ - '2.5'
19
+ rails:
20
+ - rails_5.2.4
21
+ - rails_6.0.3
22
+ - rails_6.1.0
23
+ exclude:
24
+ - ruby: '3.0'
25
+ rails: rails_5.2.4
26
+
27
+ steps:
28
+ - name: Checkout
29
+ uses: actions/checkout@v2
30
+
31
+ - name: Setup Ruby
32
+ uses: ruby/setup-ruby@v1
33
+ with:
34
+ ruby-version: ${{ matrix.ruby }}
35
+
36
+ - name: Setup Ruby cache
37
+ uses: actions/cache@v2
38
+ with:
39
+ path: "${GITHUB_WORKSPACE}/vendor/bundle"
40
+ key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-${{ hashFiles('**/Gemfile.lock') }}
41
+ restore-keys: |
42
+ ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-
43
+
44
+ - name: Bundle
45
+ env:
46
+ RAILS_VERSION: ${{ matrix.rails }}
47
+ run: |
48
+ export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/${RAILS_VERSION}.gemfile"
49
+ gem install bundler
50
+ bundle config path "${GITHUB_WORKSPACE}/vendor/bundle"
51
+ bundle install --jobs 4 --retry 3
52
+
53
+ - name: RSpec
54
+ env:
55
+ RAILS_VERSION: ${{ matrix.rails }}
56
+ run: |
57
+ export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/${RAILS_VERSION}.gemfile"
58
+ bundle exec rake
data/.gitignore CHANGED
@@ -1,26 +1,17 @@
1
- ## MAC OS
2
- .DS_Store
1
+ # Ignore bundler config.
2
+ /.bundle
3
3
 
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
4
+ # Ignore Gemfile.lock
5
+ /Gemfile.lock
6
+ /gemfiles/*.lock
7
+ /gemfiles/.bundle
7
8
 
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
9
+ # Ignore test files
10
+ /coverage
11
+ /tmp
12
12
 
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
- Gemfile.lock
21
-
22
- ## PROJECT::SPECIFIC
23
-
24
- ## RVM
25
- .rvmrc
13
+ # RVM files
14
+ /.ruby-version
26
15
 
16
+ # Gem files
17
+ /*.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ Exclude:
3
+ - bin/*
4
+ - gemfiles/*
5
+ - spec/**/*
6
+
7
+ Metrics/LineLength:
8
+ Enabled: false
data/Appraisals ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ RAILS_VERSIONS = %w[
4
+ 5.2.4
5
+ 6.0.3
6
+ 6.1.0
7
+ ].freeze
8
+
9
+ RAILS_VERSIONS.each do |version|
10
+ appraise "rails_#{version}" do
11
+ gem 'activejob', version
12
+ end
13
+ end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.6.6
4
+
5
+ * Drop support of Ruby 2.3
6
+ * Drop support of Ruby 2.4
7
+ * Add support of Ruby 2.6
8
+ * Add support of Ruby 2.7
9
+ * Add support of Ruby 3.0
10
+ * Drop support of Rails 5.1
11
+ * Add support of Rails 6.0
12
+ * Add support of Rails 6.1
13
+ * Add binstubs to ease development
14
+ * Migrate from Travis to Github Actions
15
+
3
16
  ## 1.6.5
4
17
 
5
18
  * Merge [Fixnum type is deprecated](https://github.com/crohr/syslogger/pull/42) (thanks thesmart)
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/Guardfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ guard :rspec, cmd: 'bundle exec rspec' do
4
+ require 'guard/rspec/dsl'
5
+ dsl = Guard::RSpec::Dsl.new(self)
6
+
7
+ # RSpec files
8
+ rspec = dsl.rspec
9
+ watch(rspec.spec_helper) { rspec.spec_dir }
10
+ watch(rspec.spec_support) { rspec.spec_dir }
11
+ watch(rspec.spec_files)
12
+
13
+ # Ruby files
14
+ ruby = dsl.ruby
15
+ dsl.watch_spec_files_for(ruby.lib_files)
16
+ end
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![GitHub release](https://img.shields.io/github/release/crohr/syslogger.svg)](https://github.com/crohr/syslogger/releases/latest)
5
5
  [![Gem](https://img.shields.io/gem/v/syslogger.svg)](https://rubygems.org/gems/syslogger)
6
6
  [![Gem](https://img.shields.io/gem/dtv/syslogger.svg)](https://rubygems.org/gems/syslogger)
7
- [![Build Status](https://travis-ci.org/crohr/syslogger.svg?branch=master)](https://travis-ci.org/crohr/syslogger)
7
+ [![CI](https://github.com/crohr/syslogger/workflows/CI/badge.svg)](https://github.com/crohr/syslogger/actions)
8
8
 
9
9
  A drop-in replacement for the standard Logger Ruby library, that logs to the syslog instead of a log file.
10
10
  Contrary to the SyslogLogger library, you can specify the facility and the syslog options.
data/Rakefile CHANGED
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
1
4
  require 'rspec/core/rake_task'
2
5
  require 'rdoc/task'
3
6
 
data/bin/_guard-core ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application '_guard-core' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("guard", "_guard-core")
data/bin/appraisal ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'appraisal' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("appraisal", "appraisal")
data/bin/guard ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'guard' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("guard", "guard")
data/bin/rake ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/rubocop ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rubocop", "rubocop")
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activejob", "5.2.4"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activejob", "6.0.3"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activejob", "6.1.0"
6
+
7
+ gemspec path: "../"
data/lib/syslogger.rb CHANGED
@@ -1,13 +1,14 @@
1
+ require 'forwardable'
1
2
  require 'syslog'
2
3
  require 'logger'
3
- require 'thread'
4
4
 
5
5
  class Syslogger
6
+ extend Forwardable
6
7
 
7
8
  MUTEX = Mutex.new
8
9
 
9
- attr_reader :level, :ident, :options, :facility, :max_octets
10
- attr_accessor :formatter
10
+ attr_reader :level, :options, :facility
11
+ attr_accessor :ident, :formatter, :max_octets
11
12
 
12
13
  MAPPING = {
13
14
  Logger::DEBUG => Syslog::LOG_DEBUG,
@@ -18,16 +19,23 @@ class Syslogger
18
19
  Logger::UNKNOWN => Syslog::LOG_ALERT
19
20
  }.freeze
20
21
 
21
- #
22
+ LEVELS = %w[debug info warn error fatal unknown].freeze
23
+
22
24
  # Initializes default options for the logger
25
+ #
23
26
  # <tt>ident</tt>:: the name of your program [default=$0].
27
+ #
24
28
  # <tt>options</tt>:: syslog options [default=<tt>Syslog::LOG_PID | Syslog::LOG_CONS</tt>].
29
+ #
25
30
  # Correct values are:
26
31
  # LOG_CONS : writes the message on the console if an error occurs when sending the message;
27
32
  # LOG_NDELAY : no delay before sending the message;
28
33
  # LOG_PERROR : messages will also be written on STDERR;
29
34
  # LOG_PID : adds the process number to the message (just after the program name)
30
- # <tt>facility</tt>:: the syslog facility [default=nil] Correct values include:
35
+ #
36
+ # <tt>facility</tt>:: the syslog facility [default=nil]
37
+ #
38
+ # Correct values include:
31
39
  # Syslog::LOG_DAEMON
32
40
  # Syslog::LOG_USER
33
41
  # Syslog::LOG_SYSLOG
@@ -42,45 +50,37 @@ class Syslogger
42
50
  # logger.debug "debug message"
43
51
  # logger.info "my_subapp" { "Some lazily computed message" }
44
52
  #
45
- def initialize(ident = $0, options = Syslog::LOG_PID | Syslog::LOG_CONS, facility = nil)
53
+ def initialize(ident = $PROGRAM_NAME, options = Syslog::LOG_PID | Syslog::LOG_CONS, facility = nil)
46
54
  @ident = ident
47
55
  @options = options || (Syslog::LOG_PID | Syslog::LOG_CONS)
48
56
  @facility = facility
49
57
  @level = Logger::INFO
50
- @formatter = proc do |_, _, _, msg|
51
- msg
52
- end
58
+ @formatter = SimpleFormatter.new
53
59
  end
54
60
 
55
- %w{debug info warn error fatal unknown}.each do |logger_method|
61
+ LEVELS.each do |logger_method|
56
62
  # Accepting *args as message could be nil.
57
63
  # Default params not supported in ruby 1.8.7
58
64
  define_method logger_method.to_sym do |*args, &block|
59
65
  severity = Logger.const_get(logger_method.upcase)
60
- return true if @level > severity
66
+ return true if level > severity
67
+
61
68
  add(severity, nil, args.first, &block)
62
69
  end
63
70
 
64
- unless logger_method == 'unknown'
65
- define_method "#{logger_method}?".to_sym do
66
- @level <= Logger.const_get(logger_method.upcase)
67
- end
71
+ next if logger_method == 'unknown'.freeze
72
+
73
+ define_method "#{logger_method}?".to_sym do
74
+ level <= Logger.const_get(logger_method.upcase)
68
75
  end
69
76
  end
70
77
 
71
- # Log a message at the Logger::INFO level. Useful for use with Rack::CommonLogger
78
+ # Log a message at the Logger::INFO level.
72
79
  def write(msg)
73
80
  add(Logger::INFO, msg)
74
81
  end
75
-
76
- # Logs a message at the Logger::INFO level.
77
- def <<(msg)
78
- add(Logger::INFO, msg)
79
- end
80
-
81
- def puts(msg)
82
- add(Logger::INFO, msg)
83
- end
82
+ alias << write
83
+ alias puts write
84
84
 
85
85
  # Low level method to add a message.
86
86
  # +severity+:: the level of the message. One of Logger::DEBUG, Logger::INFO, Logger::WARN, Logger::ERROR, Logger::FATAL, Logger::UNKNOWN
@@ -93,7 +93,7 @@ class Syslogger
93
93
  message, progname = progname, nil
94
94
  end
95
95
  progname ||= @ident
96
- mask = Syslog::LOG_UPTO(MAPPING[@level])
96
+ mask = Syslog::LOG_UPTO(MAPPING[level])
97
97
  communication = message || block && block.call
98
98
  formatted_communication = clean(formatter.call(severity, Time.now, progname, communication))
99
99
 
@@ -101,47 +101,18 @@ class Syslogger
101
101
  syslog_add(progname, severity, mask, formatted_communication)
102
102
  end
103
103
 
104
- # Set the max octets of the messages written to the log
105
- def max_octets=(max_octets)
106
- @max_octets = max_octets
107
- end
108
-
109
104
  # Sets the minimum level for messages to be written in the log.
110
105
  # +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>
111
106
  def level=(level)
112
107
  @level = sanitize_level(level)
113
108
  end
114
109
 
115
- # Sets the ident string passed along to Syslog
116
- def ident=(ident)
117
- @ident = ident
118
- end
119
-
120
110
  # Tagging code borrowed from ActiveSupport gem
121
111
  def tagged(*tags)
122
- new_tags = push_tags(*tags)
123
- yield self
124
- ensure
125
- pop_tags(new_tags.size)
126
- end
127
-
128
- def push_tags(*tags)
129
- tags.flatten.reject { |i| i.respond_to?(:empty?) ? i.empty? : !i }.tap do |new_tags|
130
- current_tags.concat(new_tags).uniq!
131
- end
112
+ formatter.tagged(*tags) { yield self }
132
113
  end
133
114
 
134
- def pop_tags(size = 1)
135
- current_tags.pop size
136
- end
137
-
138
- def clear_tags!
139
- current_tags.clear
140
- end
141
-
142
- def current_tags
143
- Thread.current[:syslogger_tagged_logging_tags] ||= []
144
- end
115
+ def_delegators :formatter, :current_tags, :push_tags, :pop_tags, :clear_tags!
145
116
 
146
117
  protected
147
118
 
@@ -163,40 +134,76 @@ class Syslogger
163
134
  def clean(message)
164
135
  message = message.to_s.dup
165
136
  message.strip! # remove whitespace
166
- message.gsub!(/\n/, '\\n') # escape newlines
167
- message.gsub!(/%/, '%%') # syslog(3) freaks on % (printf)
168
- message.gsub!(/\e\[[^m]*m/, '') # remove useless ansi color codes
137
+ message.gsub!(/\n/, '\\n'.freeze) # escape newlines
138
+ message.gsub!(/%/, '%%'.freeze) # syslog(3) freaks on % (printf)
139
+ message.gsub!(/\e\[[^m]*m/, ''.freeze) # remove useless ansi color codes
169
140
  message
170
141
  end
171
142
 
172
143
  private
173
144
 
174
- def tags_text
175
- tags = current_tags
176
- if tags.any?
177
- clean(tags.collect { |tag| "[#{tag}] " }.join) << ' '
178
- end
179
- end
180
-
181
145
  def syslog_add(progname, severity, mask, formatted_communication)
182
146
  MUTEX.synchronize do
183
147
  Syslog.open(progname, @options, @facility) do |s|
184
148
  s.mask = mask
185
- if self.max_octets
186
- buffer = "#{tags_text}"
149
+ if max_octets
150
+ buffer = ''
187
151
  formatted_communication.bytes do |byte|
188
152
  buffer.concat(byte)
189
153
  # if the last byte we added is potentially part of an escape, we'll go ahead and add another byte
190
- if buffer.bytesize >= self.max_octets && !['%'.ord,'\\'.ord].include?(byte)
154
+ if buffer.bytesize >= max_octets && !['%'.ord, '\\'.ord].include?(byte)
191
155
  s.log(MAPPING[severity], buffer)
192
156
  buffer = ''
193
157
  end
194
158
  end
195
159
  s.log(MAPPING[severity], buffer) unless buffer.empty?
196
160
  else
197
- s.log(MAPPING[severity], "#{tags_text}#{formatted_communication}")
161
+ s.log(MAPPING[severity], formatted_communication)
198
162
  end
199
163
  end
200
164
  end
201
165
  end
166
+
167
+ # Borrowed from ActiveSupport.
168
+ # See: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/tagged_logging.rb
169
+ class SimpleFormatter < Logger::Formatter
170
+ # This method is invoked when a log event occurs.
171
+ def call(_severity, _timestamp, _progname, msg)
172
+ "#{tags_text}#{msg}"
173
+ end
174
+
175
+ def tagged(*tags)
176
+ new_tags = push_tags(*tags)
177
+ yield self
178
+ ensure
179
+ pop_tags(new_tags.size)
180
+ end
181
+
182
+ def push_tags(*tags)
183
+ tags.flatten.reject { |i| i.respond_to?(:empty?) ? i.empty? : !i }.tap do |new_tags|
184
+ current_tags.concat(new_tags).uniq!
185
+ end
186
+ end
187
+
188
+ def pop_tags(size = 1)
189
+ current_tags.pop size
190
+ end
191
+
192
+ def clear_tags!
193
+ current_tags.clear
194
+ end
195
+
196
+ # Fix: https://github.com/crohr/syslogger/issues/29
197
+ # See: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/tagged_logging.rb#L47
198
+ def current_tags
199
+ # We use our object ID here to avoid conflicting with other instances
200
+ thread_key = @thread_key ||= "syslogger_tagged_logging_tags:#{object_id}".freeze
201
+ Thread.current[thread_key] ||= []
202
+ end
203
+
204
+ def tags_text
205
+ tags = current_tags
206
+ tags.collect { |tag| "[#{tag}] " }.join if tags.any?
207
+ end
208
+ end
202
209
  end
@@ -1,3 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Syslogger
2
- VERSION = '1.6.5'.freeze
4
+
5
+ def self.gem_version
6
+ Gem::Version.new VERSION::STRING
7
+ end
8
+
9
+ module VERSION
10
+ MAJOR = 1
11
+ MINOR = 6
12
+ TINY = 6
13
+ PRE = nil
14
+
15
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
16
+ end
3
17
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'simplecov'
2
2
  require 'rspec'
3
+ require 'active_job'
3
4
 
4
5
  # Start Simplecov
5
6
  SimpleCov.start
@@ -17,5 +18,36 @@ RSpec.configure do |config|
17
18
  end
18
19
  end
19
20
 
21
+ # Module helper for unit tests
22
+ module JobBuffer
23
+ class << self
24
+ def clear
25
+ values.clear
26
+ end
27
+
28
+ def add(value)
29
+ values << value
30
+ end
31
+
32
+ def values
33
+ @values ||= []
34
+ end
35
+
36
+ def last_value
37
+ values.last
38
+ end
39
+ end
40
+ end
41
+
42
+ # Class helper for unit tests
43
+ class HelloJob < ActiveJob::Base
44
+ def perform(greeter = "David")
45
+ JobBuffer.add("#{greeter} says hello")
46
+ end
47
+ end
48
+
49
+ # Configure I18n otherwise it throws errors in syslog
50
+ I18n.available_locales = [:en]
51
+
20
52
  # Load lib
21
53
  require 'syslogger'
@@ -64,15 +64,19 @@ describe Syslogger do
64
64
  end
65
65
 
66
66
  it 'should clean formatted message' do
67
+ formatter = Class.new(Syslogger::SimpleFormatter) do
68
+ def call(severity, timestamp, progname, msg)
69
+ msg.split(//).join('%')
70
+ end
71
+ end
72
+
67
73
  allow(Syslog).to receive(:open).and_yield(fake_syslog)
68
74
  expect(fake_syslog).to receive(:log).with(Syslog::LOG_INFO, "m%%e%%s%%s%%a%%g%%e")
69
75
 
70
76
  original_formatter = logger.formatter
71
77
 
72
78
  begin
73
- logger.formatter = proc do |severity, datetime, progname, msg|
74
- msg.split(//).join('%')
75
- end
79
+ logger.formatter = formatter.new
76
80
  logger.add(Logger::INFO, 'message')
77
81
  ensure
78
82
  logger.formatter = original_formatter
@@ -118,11 +122,14 @@ describe Syslogger do
118
122
  end
119
123
 
120
124
  it 'should apply the log formatter to the message' do
125
+ formatter = Class.new(Syslogger::SimpleFormatter) do
126
+ def call(severity, timestamp, progname, msg)
127
+ "test #{msg}!"
128
+ end
129
+ end
121
130
  allow(Syslog).to receive(:open).and_yield(fake_syslog)
122
131
  expect(fake_syslog).to receive(:log).with(Syslog::LOG_INFO, 'test message!')
123
- logger.formatter = proc do |severity, datetime, progname, msg|
124
- "test #{msg}!"
125
- end
132
+ logger.formatter = formatter.new
126
133
  logger.add(Logger::INFO, 'message')
127
134
  end
128
135
  end
@@ -295,6 +302,19 @@ describe Syslogger do
295
302
  end
296
303
  end
297
304
 
305
+ # Fix https://github.com/crohr/syslogger/issues/29
306
+ describe '#formatter' do
307
+ let(:logger) { Syslogger.new('my_app', Syslog::LOG_PID, Syslog::LOG_USER) }
308
+
309
+ it 'should not raise error' do
310
+ ActiveJob::Base.logger = logger
311
+ expect(logger).to receive(:info).at_least(1).times.with(nil)
312
+ expect {
313
+ HelloJob.perform_later "Cristian"
314
+ }.to_not raise_error
315
+ end
316
+ end
317
+
298
318
  describe '#push_tags' do
299
319
  let(:logger) { Syslogger.new('my_app', Syslog::LOG_PID, Syslog::LOG_USER) }
300
320
  after(:each) { logger.clear_tags! }
data/syslogger.gemspec CHANGED
@@ -1,10 +1,10 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path('../lib', __FILE__)
3
- require 'syslogger/version'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/syslogger/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'syslogger'
7
- s.version = Syslogger::VERSION
7
+ s.version = Syslogger::VERSION::STRING
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ['Cyril Rohr']
10
10
  s.email = ['cyril.rohr@gmail.com']
@@ -12,16 +12,21 @@ Gem::Specification.new do |s|
12
12
  s.summary = 'Dead simple Ruby Syslog logger'
13
13
  s.description = 'Same as SyslogLogger, but without the ridiculous number of dependencies and with the possibility to specify the syslog facility'
14
14
  s.license = 'MIT'
15
+ s.metadata = {
16
+ 'homepage_uri' => 'https://github.com/crohr/syslogger',
17
+ 'changelog_uri' => 'https://github.com/crohr/syslogger/blob/master/CHANGELOG.md',
18
+ 'source_code_uri' => 'https://github.com/crohr/syslogger',
19
+ 'bug_tracker_uri' => 'https://github.com/crohr/syslogger/issues'
20
+ }
21
+
22
+ s.files = `git ls-files`.split("\n")
15
23
 
24
+ s.add_development_dependency 'activejob'
25
+ s.add_development_dependency 'appraisal'
26
+ s.add_development_dependency 'guard-rspec'
16
27
  s.add_development_dependency 'rake'
17
- s.add_development_dependency 'rspec'
18
28
  s.add_development_dependency 'rdoc'
29
+ s.add_development_dependency 'rspec'
30
+ s.add_development_dependency 'rubocop'
19
31
  s.add_development_dependency 'simplecov'
20
-
21
- s.files = `git ls-files`.split("\n")
22
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
- s.require_paths = ['lib']
25
-
26
- s.rdoc_options = ['--charset=UTF-8']
27
32
  end
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syslogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.5
4
+ version: 1.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Rohr
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-16 00:00:00.000000000 Z
11
+ date: 2021-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activejob
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
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
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
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'
13
55
  - !ruby/object:Gem::Dependency
14
56
  name: rake
15
57
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +66,20 @@ dependencies:
24
66
  - - ">="
25
67
  - !ruby/object:Gem::Version
26
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
27
83
  - !ruby/object:Gem::Dependency
28
84
  name: rspec
29
85
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +95,7 @@ dependencies:
39
95
  - !ruby/object:Gem::Version
40
96
  version: '0'
41
97
  - !ruby/object:Gem::Dependency
42
- name: rdoc
98
+ name: rubocop
43
99
  requirement: !ruby/object:Gem::Requirement
44
100
  requirements:
45
101
  - - ">="
@@ -74,13 +130,25 @@ executables: []
74
130
  extensions: []
75
131
  extra_rdoc_files: []
76
132
  files:
133
+ - ".github/workflows/ci.yml"
77
134
  - ".gitignore"
78
- - ".travis.yml"
135
+ - ".rubocop.yml"
136
+ - Appraisals
79
137
  - CHANGELOG.md
80
138
  - Gemfile
139
+ - Guardfile
81
140
  - LICENSE
82
141
  - README.md
83
142
  - Rakefile
143
+ - bin/_guard-core
144
+ - bin/appraisal
145
+ - bin/guard
146
+ - bin/rake
147
+ - bin/rspec
148
+ - bin/rubocop
149
+ - gemfiles/rails_5.2.4.gemfile
150
+ - gemfiles/rails_6.0.3.gemfile
151
+ - gemfiles/rails_6.1.0.gemfile
84
152
  - lib/syslogger.rb
85
153
  - lib/syslogger/version.rb
86
154
  - spec/spec_helper.rb
@@ -89,10 +157,13 @@ files:
89
157
  homepage: http://github.com/crohr/syslogger
90
158
  licenses:
91
159
  - MIT
92
- metadata: {}
93
- post_install_message:
94
- rdoc_options:
95
- - "--charset=UTF-8"
160
+ metadata:
161
+ homepage_uri: https://github.com/crohr/syslogger
162
+ changelog_uri: https://github.com/crohr/syslogger/blob/master/CHANGELOG.md
163
+ source_code_uri: https://github.com/crohr/syslogger
164
+ bug_tracker_uri: https://github.com/crohr/syslogger/issues
165
+ post_install_message:
166
+ rdoc_options: []
96
167
  require_paths:
97
168
  - lib
98
169
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -106,11 +177,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
177
  - !ruby/object:Gem::Version
107
178
  version: '0'
108
179
  requirements: []
109
- rubyforge_project:
110
- rubygems_version: 2.6.11
111
- signing_key:
180
+ rubygems_version: 3.2.7
181
+ signing_key:
112
182
  specification_version: 4
113
183
  summary: Dead simple Ruby Syslog logger
114
- test_files:
115
- - spec/spec_helper.rb
116
- - spec/syslogger_spec.rb
184
+ test_files: []
data/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- dist: trusty
2
- language: ruby
3
- sudo: false
4
- cache: bundler
5
- rvm:
6
- - 2.4.2
7
- - 2.3.5
8
- - 2.2.8
9
- - jruby-9.1.9.0