Class: Logger::LogDevice
- Inherits:
-
Object
- Object
- Logger::LogDevice
- Defined in:
- lib/logger.rb
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.
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
#dev ⇒ Object (readonly)
Returns the value of attribute dev.
486 487 488 |
# File 'lib/logger.rb', line 486 def dev @dev end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
487 488 489 |
# File 'lib/logger.rb', line 487 def filename @filename end |
Instance Method Details
#close ⇒ Object
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 |
#write(message) ⇒ Object
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 |