class Loggability::Formatter::HTML

The default log formatter class.

Constants

HTML_EXCEPTION_FORMAT

The format for dumping exceptions

HTML_LOG_FORMAT

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

Public Instance Methods

call( severity, time, progname, message ) click to toggle source

Format the message; Overridden to escape the progname.

Calls superclass method Loggability::Formatter#call
# File lib/loggability/formatter/html.rb, line 43
def call( severity, time, progname, message )
        super( severity, time, escape_html(progname), message )
end

Protected Instance Methods

initialize( format=HTML_LOG_FORMAT ) click to toggle source

Override the logging formats with ones that generate HTML fragments

Calls superclass method
# File lib/loggability/formatter/html.rb, line 37
def initialize( format=HTML_LOG_FORMAT ) # :notnew:
        super
end
msg2str( object, severity ) click to toggle source

Format the specified object for output to the log.

# File lib/loggability/formatter/html.rb, line 53
def msg2str( object, severity )
        case object
        when String
                return escape_html( object )
        when Exception
                return HTML_EXCEPTION_FORMAT % [
                        object.class,
                        escape_html(object.message),
                        escape_html(object.backtrace.first)
                ]
        else
                return escape_html(object.inspect)
        end
end

Private Instance Methods

escape_html( string ) click to toggle source

Escape any HTML special characters in string.

# File lib/loggability/formatter/html.rb, line 74
def escape_html( string )
        return string unless string.respond_to?( :gsub )
        return string.
                gsub( '&', '&' ).
                gsub( '<', '&lt;'  ).
                gsub( '>', '&gt;'  )
end