Class: EventHub::MultiLogger
- Inherits:
-
Object
- Object
- EventHub::MultiLogger
- Defined in:
- lib/eventhub/multi_logger.rb
Constant Summary collapse
- MAX_EXCEPTIONS_FILES =
500
Instance Attribute Summary collapse
-
#devices ⇒ Object
Returns the value of attribute devices.
-
#folder ⇒ Object
Returns the value of attribute folder.
Instance Method Summary collapse
- #add_device(device) ⇒ Object
-
#initialize(folder = nil) ⇒ MultiLogger
constructor
A new instance of MultiLogger.
- #save_detailed_error(feedback, message = nil) ⇒ Object
Constructor Details
#initialize(folder = nil) ⇒ MultiLogger
Returns a new instance of MultiLogger.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/eventhub/multi_logger.rb', line 23 def initialize(folder=nil) @folder_base = folder || Dir.pwd @folder_base.chomp!('/') @folder = [@folder_base,'logs'].join('/') @folder_exceptions = [@folder_base,'exceptions'].join('/') @devices = [] FileUtils.makedirs(@folder) end |
Instance Attribute Details
#devices ⇒ Object
Returns the value of attribute devices.
21 22 23 |
# File 'lib/eventhub/multi_logger.rb', line 21 def devices @devices end |
#folder ⇒ Object
Returns the value of attribute folder.
21 22 23 |
# File 'lib/eventhub/multi_logger.rb', line 21 def folder @folder end |
Instance Method Details
#add_device(device) ⇒ Object
34 35 36 |
# File 'lib/eventhub/multi_logger.rb', line 34 def add_device(device) @devices << device end |
#save_detailed_error(feedback, message = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/eventhub/multi_logger.rb', line 38 def save_detailed_error(feedback,=nil) time = Time.now stamp = "#{time.strftime("%Y%m%d_%H%M%S")}_#{"%03d" % (time.usec/1000)}" filename = "#{stamp}.log" FileUtils.makedirs(@folder_exceptions) # check max exception log files exception_files = Dir.glob(@folder_exceptions + '/*.log') if exception_files.size > MAX_EXCEPTIONS_FILES exception_files.reverse[MAX_EXCEPTIONS_FILES..-1].each do |file| begin File.delete(file) File.delete(File.dirname(file) + '/' + File.basename(file,".*") + '.msg.raw') rescue end end end File.open("#{@folder_exceptions}/#{filename}","w") do |output| output.write("#{feedback}\n\n") output.write("Exception: #{feedback.class.to_s}\n\n") output.write("Call Stack:\n") feedback.backtrace.each do |line| output.write("#{line}\n") end end # save message if provided if File.open("#{@folder_exceptions}/#{stamp}.msg.raw","wb") do |output| output.write() end end return stamp end |