From 58065b87018a9d1ed972b8c856004bf75728da02 Mon Sep 17 00:00:00 2001 From: Rafael Mendonça França Date: Tue, 4 Jun 2019 18:07:26 -0400 Subject: [ruby/logger] Add option to set the binary mode of the log device Without binmode strings with incompatible encoding can't be written in the file. This is very common in applications that log user provided parameters. We need to allow changing the binnary mode because right now it is impossible to use the built-in log rotation feature when you provide a File object to the LogDevice, and if you provide a filename you can't have binmode. https://github.com/ruby/logger/commit/9114b3ac7e --- lib/logger.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib/logger.rb') diff --git a/lib/logger.rb b/lib/logger.rb index 4794911a69..ddd80176df 100644 --- a/lib/logger.rb +++ b/lib/logger.rb @@ -365,6 +365,8 @@ class Logger # Logging formatter. Default values is an instance of Logger::Formatter. # +datetime_format+:: # Date and time format. Default value is '%Y-%m-%d %H:%M:%S'. + # +binmode+:: + # Use binany mode on the log device. Defaul value is false. # +shift_period_suffix+:: # The log file suffix format for +daily+, +weekly+ or +monthly+ rotation. # Default is '%Y%m%d'. @@ -375,7 +377,7 @@ class Logger # def initialize(logdev, shift_age = 0, shift_size = 1048576, level: DEBUG, progname: nil, formatter: nil, datetime_format: nil, - shift_period_suffix: '%Y%m%d') + binmode: false, shift_period_suffix: '%Y%m%d') self.level = level self.progname = progname @default_formatter = Formatter.new @@ -383,9 +385,10 @@ class Logger self.formatter = formatter @logdev = nil if logdev - @logdev = LogDevice.new(logdev, :shift_age => shift_age, - :shift_size => shift_size, - :shift_period_suffix => shift_period_suffix) + @logdev = LogDevice.new(logdev, shift_age: shift_age, + shift_size: shift_size, + shift_period_suffix: shift_period_suffix, + binmode: binmode) end end -- cgit v1.2.3