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.
502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/logger.rb', line 502 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.
495 496 497 |
# File 'lib/logger.rb', line 495 def dev @dev end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
496 497 498 |
# File 'lib/logger.rb', line 496 def filename @filename end |
Instance Method Details
#close ⇒ Object
537 538 539 540 541 542 543 544 545 |
# File 'lib/logger.rb', line 537 def close begin @mutex.synchronize do @dev.close rescue nil end rescue Exception @dev.close rescue nil end end |
#write(message) ⇒ Object
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 |
# File 'lib/logger.rb', line 516 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 |