Class: StrftimeLogger::Adapter::File
- Inherits:
-
Object
- Object
- StrftimeLogger::Adapter::File
- Defined in:
- lib/strftime_logger/adapter/file.rb
Defined Under Namespace
Classes: LogFileMutex
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(level, path) ⇒ File
constructor
A new instance of File.
- #write(msg) ⇒ Object
Constructor Details
#initialize(level, path) ⇒ File
11 12 13 14 15 16 17 |
# File 'lib/strftime_logger/adapter/file.rb', line 11 def initialize(level, path) @level = level @path = path = Time.now.strftime(path) @mutex = LogFileMutex.new @log = open_logfile() end |
Instance Method Details
#close ⇒ Object
43 44 45 46 47 |
# File 'lib/strftime_logger/adapter/file.rb', line 43 def close if !@log.nil? && !@log.closed? @log.close end end |
#write(msg) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/strftime_logger/adapter/file.rb', line 19 def write(msg) begin @mutex.synchronize do if @log.nil? || !same_path? begin = Time.now.strftime(@path) @log.close rescue nil @log = create_logfile() rescue warn("log shifting failed. #{$!}") end end begin @log.write msg rescue warn("log writing failed. #{$!}") end end rescue Exception => ignored warn("log writing failed. #{ignored}") end end |