Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the logdev #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
19 changes: 15 additions & 4 deletions lib/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ def fatal!; self.level = FATAL; end
# new entries are appended.
# - An IO stream (typically +$stdout+, +$stderr+. or an open file):
# entries are to be written to the given stream.
# - An instance of Logger::LogDevice, such as the #logdev of another Logger.
# - +nil+ or +File::NULL+: no entries are to be written.
#
# Examples:
Expand Down Expand Up @@ -586,13 +587,23 @@ def initialize(logdev, shift_age = 0, shift_size = 1048576, level: DEBUG,
@logdev = nil
@level_override = {}
if logdev && logdev != File::NULL
@logdev = LogDevice.new(logdev, shift_age: shift_age,
shift_size: shift_size,
shift_period_suffix: shift_period_suffix,
binmode: binmode)
if logdev.is_a?(LogDevice)
@logdev = logdev
else
@logdev = LogDevice.new(logdev, shift_age: shift_age,
shift_size: shift_size,
shift_period_suffix: shift_period_suffix,
binmode: binmode)
end
end
end

# The underlying log device.
#
# This is the first argument passed to the constructor, wrapped in a
# Logger::LogDevice, along with the binmode flag and rotation options.
attr_reader :logdev

# Sets the logger's output stream:
#
# - If +logdev+ is +nil+, reopens the current output stream.
Expand Down
10 changes: 10 additions & 0 deletions test/logger/test_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ def test_initialize
assert_nil(logger.datetime_format)
end

def test_logdev
logger = Logger.new(STDERR)
assert_instance_of(Logger::LogDevice, logger.logdev)

logdev = Logger::LogDevice.new(STDERR)
logger = Logger.new(logdev)
assert_instance_of(Logger::LogDevice, logger.logdev)
assert_equal(STDERR, logger.logdev.dev)
end

def test_initialize_with_level
# default
logger = Logger.new(STDERR)
Expand Down