Class: Unilogger::LogFileEmitter
- Inherits:
-
Object
- Object
- Unilogger::LogFileEmitter
- Defined in:
- lib/unilogger/log_file_emitter.rb
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #emit(details, message, options) ⇒ Object
-
#initialize(logdev, options = {}) ⇒ LogFileEmitter
constructor
options includes a JSON representation of logdev.
Constructor Details
#initialize(logdev, options = {}) ⇒ LogFileEmitter
options includes a JSON representation of logdev
22 23 24 25 |
# File 'lib/unilogger/log_file_emitter.rb', line 22 def initialize( logdev, = {} ) @options = @logdev = ::Logger::LogDevice.new( logdev, ) end |
Class Method Details
.build(options) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/unilogger/log_file_emitter.rb', line 8 def build( ) logdev = .delete("logdev") case logdev when nil, /stderr/i new( STDERR, :logdev => "STDERR" ) when /stdout/i new( STDOUT, :logdev => "STDOUT" ) else new( logdev, .merge( :logdev => logdev ) ) end end |
Instance Method Details
#as_json ⇒ Object
35 36 37 |
# File 'lib/unilogger/log_file_emitter.rb', line 35 def as_json { :log_file => @options } end |
#emit(details, message, options) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/unilogger/log_file_emitter.rb', line 27 def emit( details, , ) if && .size > 0 then = .map { |k,v| [k, v.to_json].join(":") }.join(",") = "#{}; #{}" end @logdev.write "#{details[:time].to_i} [#{details[:pid]}:#{details[:fiber]}] #{details[:pri_sym]} #{}\n" end |