Class: Arrow::Logger::ApacheOutputter

Inherits:
Outputter
  • Object
show all
Defined in:
lib/arrow/logger/apacheoutputter.rb

Overview

The Arrow::Logger::ApacheOutputter class, a derivative of Apache::Logger::Outputter. Instances of this class write log messages of the corresponding error level to the Apache log

Authors

  • Michael Granger

Please see the file LICENSE in the top-level directory for licensing details.

Constant Summary

DefaultDescription =

The default description

"Apache Log Outputter"
DefaultFormat =

The default interpolatable string that’s used to build the message to output

%q{#{name}#{frame ? '('+frame+')' : ''}: #{msg[0,2048]}}
LEVELS =

The Logger log levels (copied for easy access)

Arrow::Logger::LEVELS

Constants inherited from Outputter

DEFAULT_DESCRIPTION, DEFAULT_FORMAT

Instance Method Summary

Methods inherited from Outputter

create, derivativeDirs, #inspect, #inspection_details, parse_uri

Constructor Details

- (ApacheOutputter) initialize(uri, description = DefaultDescription, format = DefaultFormat)

Create a new Arrow::Logger::ApacheOutputter object that will write to the apache log, and use the given description and format.



37
38
39
# File 'lib/arrow/logger/apacheoutputter.rb', line 37

def initialize( uri, description=DefaultDescription, format=DefaultFormat )
  super
end

Instance Method Details

- (Object) write(time, level, name, frame, msg)

Write the given level, name, frame, and msg to the target output mechanism.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/arrow/logger/apacheoutputter.rb', line 48

def write( time, level, name, frame, msg )
  return unless defined?( ::Apache )
  srvr = ::Apache.request.server
  return unless srvr.loglevel >= LEVELS[ level ]

  # Translate calls to log.warning into Apache::Server#log_warn
  level = :warn if level == :warning

  logMethod = srvr.method( "log_#{level}" )
  super {|msg|
    # Escape any unexpanded sprintf format patterns
    msg.gsub!( /%/, '%%' )
    logMethod.call( msg )
  }
end