Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions lib/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
require 'little-plugger'
require 'multi_json'

begin
require 'syslog'
HAVE_SYSLOG = true
rescue LoadError
HAVE_SYSLOG = false
end

#
#
module Logging
Expand Down
14 changes: 13 additions & 1 deletion lib/logging/appenders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,21 @@ def reset
end
# :startdoc:

# Accessor / Factory for the Syslog appender.
#
def self.syslog( *args )
fail ArgumentError, '::Logging::Appenders::Syslog needs a name as first argument.' if args.empty?
::Logging::Appenders::Syslog.new(*args)
end

extend self
@appenders = Hash.new

# Load Syslog only when requested. Windows does not have syslog, and
# Ruby 3.4.0 will remove it from the standard library. Requiring
# syslog on Ruby 3.3.0 will result in an warning if the gem is not
# explicitly installed.
autoload :Syslog, Logging.libpath('logging/appenders/syslog')
end # Appenders

require libpath('logging/appenders/buffering')
Expand All @@ -57,6 +70,5 @@ def reset
require libpath('logging/appenders/file')
require libpath('logging/appenders/rolling_file')
require libpath('logging/appenders/string_io')
require libpath('logging/appenders/syslog')
end # Logging

14 changes: 1 addition & 13 deletions lib/logging/appenders/syslog.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Along with this change, should this PR also include syslog in the gemspec file, as it will be removed from the default gems in Ruby 3.4.0 (currently outputs a console warning to that effect).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR intentionally avoids including syslog in the gemspec file to avoid having an extra dependency for users who do not need Logging::Appender::Syslog.
Users who need Logging::Appender::Syslog should explicitly state that they need syslog by adding it to the gemspec files of their applications to prepare for Ruby 3.4.0.

# only load this class if we have the syslog library
# Windows does not have syslog
#
if HAVE_SYSLOG
require 'syslog'

module Logging::Appenders

# Accessor / Factory for the Syslog appender.
#
def self.syslog( *args )
fail ArgumentError, '::Logging::Appenders::Syslog needs a name as first argument.' if args.empty?
::Logging::Appenders::Syslog.new(*args)
end

# This class provides an Appender that can write to the UNIX syslog
# daemon.
#
Expand Down Expand Up @@ -211,4 +200,3 @@ def syslog_level_num( level )

end # Syslog
end # Logging::Appenders
end # HAVE_SYSLOG
7 changes: 7 additions & 0 deletions test/appenders/test_syslog.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

require File.expand_path('../setup', File.dirname(__FILE__))

begin
require 'syslog'
HAVE_SYSLOG = true
rescue LoadError
HAVE_SYSLOG = false
end

if HAVE_SYSLOG

module TestLogging
Expand Down