diff --git a/ChangeLog b/ChangeLog index b9a6606..40b91fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Tue Jan 5 21:45:12 2016 Richard Schneeman + + * lib/logger.rb add method Logger#destination + Tue Jan 5 21:44:37 2016 SHIBATA Hiroshi * ChangeLog: fix wrong class name. diff --git a/lib/logger.rb b/lib/logger.rb index 2246673..af2ab2f 100644 --- a/lib/logger.rb +++ b/lib/logger.rb @@ -271,6 +271,9 @@ def level=(severity) end end + # Returns the Logger::LogDevice responsible for logging messages. + attr_reader :logdev + # Program name to include in log messages. attr_accessor :progname @@ -625,10 +628,35 @@ def previous_period_end(now, shift_age) class LogDevice include Period + # The destination object that will receive the log message. attr_reader :dev attr_reader :filename include MonitorMixin + # + # :call-seq: + # Logger::Logdev.new(STDOUT) + # Logger::Logdev.new('test.log') + # Logger::Logdev.new('test.log', shift_age: 'weekly') + # Logger::Logdev.new('test.log', shift_age: 7, shift_size: 1048576) + # + # === Args + # + # +log+:: + # The log destination. This is a filename (String) or IO object (typically + # +STDOUT+, +STDERR+, or an open file). + # +opt+:: + # A hash of options + # - +shift_age+ + # Number of old log files to keep, *or* frequency of rotation (+daily+, + # +weekly+ or +monthly+). + # - +shift_size+:: + # Maximum logfile size (only applies when +shift_age+ is a number). + # + # === Description + # + # Create an instance. + # def initialize(log = nil, opt = {}) @dev = @filename = @shift_age = @shift_size = nil mon_initialize diff --git a/test/logger/test_logger.rb b/test/logger/test_logger.rb index 836d3b3..c7531ba 100644 --- a/test/logger/test_logger.rb +++ b/test/logger/test_logger.rb @@ -292,4 +292,10 @@ def test_lshift r.close assert_equal("msg2\n\n", msg) end + + def test_logdev_and_destination + r, w = IO.pipe + logger = Logger.new(w) + assert_equal(w, logger.logdev.dev) + end end