Skip to content
This repository has been archived by the owner on Dec 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from y-takahashi/feature_recursive_mkdir
Browse files Browse the repository at this point in the history
Add recursive mkdir to create_logfile.
  • Loading branch information
ma2gedev committed Aug 17, 2015
2 parents 52805a7 + 95f9d7c commit 0c1aa30
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/chrono_logger.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "chrono_logger/version"
require 'logger'
require 'pathname'

# A lock-free logger with timebased file rotation.
class ChronoLogger < Logger
Expand Down Expand Up @@ -91,6 +92,7 @@ def open_logfile(filename)

def create_logfile(filename)
begin
Pathname(filename).dirname.mkpath
logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT | File::EXCL))
logdev.sync = true
rescue Errno::EEXIST
Expand Down
17 changes: 17 additions & 0 deletions test/test_chrono_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ def test_rotation_per_second
end
end

def test_rotation_per_day_and_create_dir
Dir.mktmpdir do |tmpdir|
begin
Delorean.time_travel_to '2015-08-01 23:59:50'
logger = ChronoLogger.new([tmpdir, '/%Y/%m/%d/test.log'].join)
logger.debug 'rotation'
Delorean.time_travel_to '2015-08-02 00:00:01'
logger.debug 'new dir'

assert { File.exist?([tmpdir, '/2015/08/01/test.log'].join) }
assert { File.exist?([tmpdir, '/2015/08/02/test.log'].join) }
ensure
Delorean.back_to_the_present
end
end
end

class PeriodTest
include ChronoLogger::Period
end
Expand Down

0 comments on commit 0c1aa30

Please sign in to comment.