Class: EventHub::Components::ExceptionWriter
- Inherits:
-
Object
- Object
- EventHub::Components::ExceptionWriter
- Defined in:
- lib/eventhub/components/exception_writer.rb
Constant Summary collapse
- MAX_EXCEPTIONS_FILES =
500
Instance Attribute Summary collapse
-
#folder ⇒ Object
Returns the value of attribute folder.
-
#max_files ⇒ Object
Returns the value of attribute max_files.
Instance Method Summary collapse
-
#initialize(base = nil, max_files = MAX_EXCEPTIONS_FILES) ⇒ ExceptionWriter
constructor
A new instance of ExceptionWriter.
- #write(exception, message = nil) ⇒ Object
Constructor Details
#initialize(base = nil, max_files = MAX_EXCEPTIONS_FILES) ⇒ ExceptionWriter
Returns a new instance of ExceptionWriter.
6 7 8 9 10 |
# File 'lib/eventhub/components/exception_writer.rb', line 6 def initialize(base = nil, max_files = MAX_EXCEPTIONS_FILES) base ||= Dir.pwd @folder = File.join(base, "exceptions") @max_files = max_files end |
Instance Attribute Details
#folder ⇒ Object
Returns the value of attribute folder.
4 5 6 |
# File 'lib/eventhub/components/exception_writer.rb', line 4 def folder @folder end |
#max_files ⇒ Object
Returns the value of attribute max_files.
4 5 6 |
# File 'lib/eventhub/components/exception_writer.rb', line 4 def max_files @max_files end |
Instance Method Details
#write(exception, message = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/eventhub/components/exception_writer.rb', line 12 def write(exception, = nil) time = Time.now stamp = "#{time.strftime("%Y%m%d_%H%M%S")}_%i" % time.usec # create exception folder when it's needed (but not before) FileUtils.makedirs(@folder) write_exception("#{stamp}.log", exception) ("#{stamp}.msg.raw", ) restrict_to_max_files stamp end |