Class: Logger::LogDevice
- Inherits:
-
Object
- Object
- Logger::LogDevice
- Defined in:
- lib/logger.rb
Overview
Device used for logging messages.
Defined Under Namespace
Classes: LogDeviceMutex
Instance Attribute Summary collapse
-
#dev ⇒ Object
readonly
Returns the value of attribute dev.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(log = nil, opt = {}) ⇒ LogDevice
constructor
A new instance of LogDevice.
- #write(message) ⇒ Object
Constructor Details
#initialize(log = nil, opt = {}) ⇒ LogDevice
Returns a new instance of LogDevice.
543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'lib/logger.rb', line 543 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
#dev ⇒ Object (readonly)
Returns the value of attribute dev
536 537 538 |
# File 'lib/logger.rb', line 536 def dev @dev end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename
537 538 539 |
# File 'lib/logger.rb', line 537 def filename @filename end |
Instance Method Details
#close ⇒ Object
578 579 580 581 582 583 584 585 586 |
# File 'lib/logger.rb', line 578 def close begin @mutex.synchronize do @dev.close rescue nil end rescue Exception @dev.close rescue nil end end |
#write(message) ⇒ Object
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/logger.rb', line 557 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 |