Class: Logger::LogDevice
Defined Under Namespace
Classes: LogDeviceMutex
Constant Summary
- SiD =
24 * 60 * 60
Instance Attribute Summary (collapse)
-
- (Object) dev
readonly
Returns the value of attribute dev.
-
- (Object) filename
readonly
Returns the value of attribute filename.
Instance Method Summary (collapse)
- - (Object) close
-
- (LogDevice) initialize(log = nil, opt = {})
constructor
A new instance of LogDevice.
- - (Object) write(message)
Constructor Details
- (LogDevice) initialize(log = nil, opt = {})
A new instance of LogDevice
493 494 495 496 497 498 499 500 501 502 503 504 505 |
# File 'lib/logger.rb', line 493 def initialize(log = nil, opt = {}) @dev = @filename = @shift_age = @shift_size = nil @mutex = LogDeviceMutex.new if log.respond_to?(:write) and log.respond_to?(:close) @dev = log else @dev = open_logfile(log) @dev.sync = true @filename = log @shift_age = opt[:shift_age] || 7 @shift_size = opt[:shift_size] || 1048576 end end |
Instance Attribute Details
- (Object) dev (readonly)
Returns the value of attribute dev
486 487 488 |
# File 'lib/logger.rb', line 486 def dev @dev end |
- (Object) filename (readonly)
Returns the value of attribute filename
487 488 489 |
# File 'lib/logger.rb', line 487 def filename @filename end |
Instance Method Details
- (Object) close
528 529 530 531 532 533 534 535 536 |
# File 'lib/logger.rb', line 528 def close begin @mutex.synchronize do @dev.close rescue nil end rescue Exception => ignored @dev.close rescue nil end end |
- (Object) write(message)
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 |
# File 'lib/logger.rb', line 507 def write() begin @mutex.synchronize do if @shift_age and @dev.respond_to?(:stat) begin check_shift_log rescue warn("log shifting failed. #{$!}") end end begin @dev.write() rescue warn("log writing failed. #{$!}") end end rescue Exception => ignored warn("log writing failed. #{ignored}") end end |