Class: UU::AppLog::Outputter

Inherits:
Log4r::Outputter
  • Object
show all
Defined in:
uu_applog-0.27.16/lib/uu/applog/outputter.rb

Overview

Log4r outputter class for logger use with remote logging service application log by client api [UU::OS::AppLog::ApplicationLog].

Constant Summary

TABBED_LINE_SEPARATOR =

Tabbed line separator

"\n\t"
EXCEPTION_SEPARATOR =

Separator of exception part in data field of [Log4r::LogEvent]. If we want store exception with stack trace to application log separated from logged message we have to use separator in data field because Log4r doesn't support in [Log4r::LogEvent] separated exception. This separator is e.g. used by Log4rPlugin of [UU::OS::Logger].

"#{TABBED_LINE_SEPARATOR}@@exception@@#{TABBED_LINE_SEPARATOR}"
APPLOG_URI_KEY =

key to MDC to get application log uri

'uu-applogURI'
APPLICATION_URI_KEY =

key to MDC to get application uri

'uu-appURI'
DEFAULT_APPLOG_CODE =

default application log code for generating default application log uri from application uri

'APPLOG'

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Outputter) initialize(_name, hash = {})

Creates new instance of Outputter.

Parameters:

  • _name (String)

    the name of outputter

  • hash (Hash) (defaults to: {})

    map containing application log uri [String, UU::OS::UESURI] under the key loguri or log_uri or logURI



67
68
69
70
71
72
73
74
75
# File 'uu_applog-0.27.16/lib/uu/applog/outputter.rb', line 67

def initialize(_name, hash={})
  super(_name, hash)
  uri = (hash[:loguri] or hash['loguri'] or hash[:log_uri] or hash[:logURI])
  if uri.nil? || uri.strip.empty?
    Log4r::Logger.log_internal {"#{self.class} #{self.name}: Application log uri is not defined in initialization. Application log URI can be defined or generated from application URI also dynamically by getting it from Log4r::MDC."}
  else
    @log_uri = UU::OS::UESURI.new(uri)
  end
end

Instance Attribute Details

- (UU::OS::UESURI) log_uri

UESURI of the specified application log.

Parameters:

Returns:



46
47
48
# File 'uu_applog-0.27.16/lib/uu/applog/outputter.rb', line 46

def log_uri
  @log_uri
end

Instance Method Details

- (Object) canonical_log(logevent)

This method handles all log events passed to a Outputter.

Parameters:

  • logevent (Log4r::LogEvent)

    wraps all data associated with a logging statement



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'uu_applog-0.27.16/lib/uu/applog/outputter.rb', line 85

def canonical_log(logevent)
  require 'uu/applog/application_log' # the require must be called here to prevent cyclic dependency (which occurs if this require is at the top of the file)
  if loop_detected?
    Log4r::Logger.log_internal {"#{self.class} #{self.name}: Logging loop detected, because some component in the logging process called logger. Data being logged: logger name=#{logevent.fullname}, level=#{logevent.level}, message=#{logevent.data}, tracer=#{logevent.tracer}"}
    end_loop!
    return
  end
  begin_loop!
  begin
    applog_uri = log_uri
    if(applog_uri.nil?)
      Log4r::Logger.log_internal {"#{self.class} #{self.name}: Cannot log without UESURI of application log. First set log_uri parameter in log4r.xml or set on Log4r::MDC uu-appURI parameter or uu-applogURI parameter."}
      return
    end
    record = {}
    record[:applog_uri] = applog_uri
    record[:message] = create_message(logevent)
    record[:outputter] = self
    record[:token] = UU::OS::Security::Session.send(:get_authn_token)
    # Push message to queue (it will be written asynchronously).
    @@msg_queue.push(record)
  rescue Exception => e
    Log4r::Logger.log_internal {"#{self.class} #{self.name}: Remote logging ends with exception: Exception message=#{e.message}; stacktrace=#{e.backtrace}"}
  ensure
    end_loop!
  end
end