Skip to content

Commit

Permalink
make sure setting FIleHandler's rotatable = false works
Browse files Browse the repository at this point in the history
(reported as a comment for the proposed work-around #82)
  • Loading branch information
kares committed Oct 17, 2012
1 parent 930fa9c commit 5fb7e0a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/trinidad/logging.rb
Expand Up @@ -133,7 +133,7 @@ class FileHandler < Java::OrgApacheJuli::FileHandler # :nodoc

def initialize(directory, prefix, suffix)
super(directory, prefix, suffix)
self._date = '' # to openWriter on first #publish(record)
self._date = nil # to openWriter on first #publish(record)
end

def openWriter
Expand Down
56 changes: 56 additions & 0 deletions spec/trinidad/logging_spec.rb
Expand Up @@ -347,6 +347,62 @@ def create_web_app_context(context_dir, web_app)
end

end

describe 'FileHandler' do

FileHandler = Trinidad::Logging::FileHandler

let(:prefix) { 'testing' }
let(:suffix) { '.log' }
let(:log_dir) { "#{MOCK_WEB_APP_DIR}/log" }
let(:log_file) { "#{log_dir}/#{prefix}#{suffix}" }

before { FileUtils.touch log_file }
after { FileUtils.rm log_file if File.exist?(log_file) }

it 'logs when rotatable' do
file_handler = FileHandler.new(log_dir, prefix, suffix)
file_handler.rotatable = true # {prefix}{date}{suffix}

log_content = File.read(log_file)
log_content.should_not =~ /sample log entry/

file_handler.publish new_log_record('sample log entry')

log_content = File.read(log_file)
log_content.should =~ /sample log entry/
end

it 'logs when non-rotatable' do
file_handler = FileHandler.new(log_dir, prefix, suffix)
file_handler.rotatable = false # {prefix}{suffix}

log_content = File.read(log_file)
log_content.should_not =~ /another log entry/

file_handler.publish new_log_record('another log entry')

log_content = File.read(log_file)
log_content.should =~ /another log entry/
end

private

def new_log_record(options = {})
if options.is_a?(String)
message = options; options = {}
else
message = options[:message] || '42'
end
time = options[:time]
level = JUL::Level::WARNING
record = JUL::LogRecord.new level, message
record.millis = time.to_java.time if time
record
end

end

end

describe Trinidad::Logging::DefaultFormatter do
Expand Down

0 comments on commit 5fb7e0a

Please sign in to comment.