Class: Unilogger::LogFileEmitter

Inherits:
Object
  • Object
show all
Defined in:
lib/unilogger/log_file_emitter.rb

Class Method Summary collapse

Instance Method Summary collapse

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 = {} )
  @options = options
  @logdev  = ::Logger::LogDevice.new( logdev, options )
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( options )
  logdev = options.delete("logdev")
  case logdev
  when nil, /stderr/i
    new( STDERR, :logdev => "STDERR" )
  when /stdout/i
    new( STDOUT, :logdev => "STDOUT" )
  else
    new( logdev, options.merge( :logdev => logdev ) )
  end
end

Instance Method Details

#as_jsonObject



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, message, options )
  if options && options.size > 0 then
    options = options.map { |k,v| [k, v.to_json].join(":") }.join(",")
    message = "#{message}; #{options}"
  end
  @logdev.write "#{details[:time].to_i} [#{details[:pid]}:#{details[:fiber]}] #{details[:pri_sym]} #{message}\n"
end