Class: DRbService::HtmlLogFormatter

Inherits:
Logger::Formatter
  • Object
show all
Includes:
ERB::Util
Defined in:
lib/drbservice/utils.rb

Overview

An alternate formatter for Logger instances that outputs div HTML fragments.

Usage

require 'drbservice/utils'
DRbService.logger.formatter = DRbService::HtmlLogFormatter.new( DRbService.logger )

Version

$Id: utils.rb,v 87bc5aa9e2be 2011/08/29 21:05:42 ged $

Authors

:include: LICENSE

Please see the file LICENSE in the ‘docs’ directory for licensing details.

Constant Summary collapse

HTML_LOG_FORMAT =

The default HTML fragment that’ll be used as the template for each log message.

%q{
<div class="log-message %5$s">
	<span class="log-time">%1$s.%2$06d</span>
	[
		<span class="log-pid">%3$d</span>
		/
		<span class="log-tid">%4$s</span>
	]
	<span class="log-level">%5$s</span>
	:
	<span class="log-name">%6$s</span>
	<span class="log-message-text">%7$s</span>
</div>
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, format = HTML_LOG_FORMAT) ⇒ HtmlLogFormatter

Override the logging formats with ones that generate HTML fragments



270
271
272
273
274
# File 'lib/drbservice/utils.rb', line 270

def initialize( logger, format=HTML_LOG_FORMAT ) # :notnew:
	@logger = logger
	@format = format
	super()
end

Instance Attribute Details

#formatObject

The HTML fragment that will be used as a format() string for the log



282
283
284
# File 'lib/drbservice/utils.rb', line 282

def format
  @format
end

Instance Method Details

#call(severity, time, progname, msg) ⇒ Object

Return a log message composed out of the arguments formatted using the formatter’s format string



287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/drbservice/utils.rb', line 287

def call( severity, time, progname, msg )
	args = [
		time.strftime( '%Y-%m-%d %H:%M:%S' ),                         # %1$s
		time.usec,                                                    # %2$d
		Process.pid,                                                  # %3$d
		Thread.current == Thread.main ? 'main' : Thread.object_id,    # %4$s
		severity.downcase,                                                     # %5$s
		progname,                                                     # %6$s
		html_escape( msg ).gsub(/\n/, '<br />')                       # %7$s
	]

	return self.format % args
end