Class: EventHub::Components::ExceptionWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/eventhub/components/exception_writer.rb

Constant Summary collapse

MAX_EXCEPTIONS_FILES =
500

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#folderObject

Returns the value of attribute folder.



4
5
6
# File 'lib/eventhub/components/exception_writer.rb', line 4

def folder
  @folder
end

#max_filesObject

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, message = 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)
  write_message("#{stamp}.msg.raw", message)

  restrict_to_max_files

  stamp
end