org.x4juli.formatter
Class HTMLFormatter

java.lang.Object
  extended byjava.util.logging.Formatter
      extended byorg.x4juli.global.components.AbstractFormatter
          extended byorg.x4juli.formatter.HTMLFormatter
All Implemented Interfaces:
Component, ExtendedFormatter, Formatter, OptionHandler

public class HTMLFormatter
extends AbstractFormatter

Logging API as a whole was originally done for Apache log4j. Juli is a port of main parts of that to complete the Java Logging APIs. All credits for initial idea, design, implementation, documentation belong to the log4j crew. This file was originally published by Ceki Gülcü, Steve Mactaggart . Please use exclusively the appropriate mailing lists for questions, remarks and contribution.

Since:
0.5
Author:
Boris Unckel

Field Summary
private  boolean chainHandlesThrowable
           
private  long counter
           
private  boolean internalCSS
           
private  java.lang.String pattern
           
private static java.lang.String PATTERN_RULE_REGISTRY
          Customized pattern conversion rules are stored under this key in the LoggerRepositoryHolder object store.
private  LogRecordPatternConverter[] patternConverters
           
private  FormattingInfo[] patternFields
           
private  java.lang.String title
           
protected static java.lang.String TRACE_PREFIX
          Prefix for Stacktraces.
private  java.lang.String url2ExternalCSS
           
 
Fields inherited from class org.x4juli.global.components.AbstractFormatter
ignoresThrowable, manager, repository
 
Constructor Summary
HTMLFormatter()
          Constructs a PatternLayout using the PatternFormatter.DEFAULT_CONVERSION_PATTERN.
HTMLFormatter(java.lang.String pattern)
          Constructs a PatternLayout using the supplied conversion pattern.
 
Method Summary
 void activateOptions()
          Activate the options that were previously set with calls to option setters.

This allows to defer activiation of the options until all options have been set. This is required for components which have related options that remain ambigous until all are set.

(package private)  void appendThrowableAsHTML(java.lang.String[] s, java.io.Writer sbuf)
          Write an Throwable as HTML code.
 java.lang.String doFormat(ExtendedLogRecord extRecord)
          
 java.lang.String getContentType()
          The Content type.
 java.lang.String getConversionPattern()
          The conversionpattern.
 java.lang.String getFooter()
          The footer.
 java.lang.String getHead(java.util.logging.Handler h)
          
 java.lang.String getHeader()
          Returns appropriate HTML headers.
(package private)  void getInternalCSS(java.lang.StringBuffer buf)
          Generate an internal CSS file.
 java.lang.String getTail(java.util.logging.Handler h)
          
 java.lang.String getTitle()
          Returns the current value of the Title option.
 java.lang.String getURL2ExternalCSS()
          Return the URL to the external CSS file.
 boolean ignoresThrowable()
          The HTML layout handles the throwable contained in logging events.
 boolean isInternalCSS()
          Returns the value of the internalCSS option.
 void setConversionPattern(java.lang.String conversionPattern)
          Set the ConversionPattern option.
 void setInternalCSS(boolean internalCSS)
          Set the value of the internalCSS option.
 void setTitle(java.lang.String title)
          The Title option takes a String value.
 void setURL2ExternalCSS(java.lang.String url2ExternalCss)
          Set the URL for the external CSS file.
 
Methods inherited from class org.x4juli.global.components.AbstractFormatter
format, format, formatMessage, getLogger, getLoggerRepository, getMessageProperties, getNonFloodingLogger, getProperty, getProperty, getProperty, resetErrorCount, setIgnoresThrowable, setObjectStore
 
Methods inherited from class java.util.logging.Formatter
formatMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.x4juli.global.spi.ExtendedFormatter
formatMessage
 

Field Detail

TRACE_PREFIX

protected static final java.lang.String TRACE_PREFIX
Prefix for Stacktraces.

See Also:
Constant Field Values

PATTERN_RULE_REGISTRY

private static final java.lang.String PATTERN_RULE_REGISTRY
Customized pattern conversion rules are stored under this key in the LoggerRepositoryHolder object store.

See Also:
Constant Field Values

pattern

private java.lang.String pattern

title

private java.lang.String title

internalCSS

private boolean internalCSS

url2ExternalCSS

private java.lang.String url2ExternalCSS

chainHandlesThrowable

private boolean chainHandlesThrowable

counter

private long counter

patternConverters

private LogRecordPatternConverter[] patternConverters

patternFields

private FormattingInfo[] patternFields
Constructor Detail

HTMLFormatter

public HTMLFormatter()
Constructs a PatternLayout using the PatternFormatter.DEFAULT_CONVERSION_PATTERN. The default pattern just produces the application supplied message.


HTMLFormatter

public HTMLFormatter(java.lang.String pattern)
Constructs a PatternLayout using the supplied conversion pattern.

Parameters:
pattern - to format logrecords.
Method Detail

doFormat

public java.lang.String doFormat(ExtendedLogRecord extRecord)

Specified by:
doFormat in class AbstractFormatter
Since:
0.5
See Also:
Formatter.format(java.util.logging.LogRecord)

activateOptions

public void activateOptions()
Activate the options that were previously set with calls to option setters.

This allows to defer activiation of the options until all options have been set. This is required for components which have related options that remain ambigous until all are set.

Since:
0.5

setConversionPattern

public void setConversionPattern(java.lang.String conversionPattern)
Set the ConversionPattern option. This is the string which controls formatting and consists of a mix of literal content and conversion specifiers.

Parameters:
conversionPattern - controls formatting.
Since:
0.5

getConversionPattern

public java.lang.String getConversionPattern()
The conversionpattern.

Returns:
the value of the ConversionPattern option.
Since:
0.5

setTitle

public void setTitle(java.lang.String title)
The Title option takes a String value. This option sets the document title of the generated HTML document.

Defaults to 'x4juli Log Messages'.

Parameters:
title - of the page.
Since:
0.5

getTitle

public java.lang.String getTitle()
Returns the current value of the Title option.

Returns:
the title.
Since:
0.5

isInternalCSS

public boolean isInternalCSS()
Returns the value of the internalCSS option. See setInternalCSS(boolean) method for details about the meaning of this option.

Returns:
boolean Value of internalCSS option
Since:
0.5

setInternalCSS

public void setInternalCSS(boolean internalCSS)
Set the value of the internalCSS option. If set to true, the generated HTML ouput will include an internal cascading style sheet. Otherwise, the generated HTML output will include a reference to an external CSS.

By default, internalCSS value is set to false, that is, by default, only a link to an external CSS file will be generated.

Parameters:
internalCSS - to use or not.
Since:
0.5
See Also:
setURL2ExternalCSS(java.lang.String)

getURL2ExternalCSS

public java.lang.String getURL2ExternalCSS()
Return the URL to the external CSS file. See setURL2ExternalCSS(java.lang.String) method for details about the meaning of this option.

Returns:
URL to the external CSS file.
Since:
0.5

setURL2ExternalCSS

public void setURL2ExternalCSS(java.lang.String url2ExternalCss)
Set the URL for the external CSS file. By default, the external CSS file is set to "http://logging.apache.org/log4j/docs/css/eventTable-1.0.css".

Parameters:
url2ExternalCss - URL where to find the CSS.
Since:
0.5

getContentType

public java.lang.String getContentType()
The Content type.

Returns:
the content type output by this layout, i.e "text/html".
Since:
0.5

getHeader

public java.lang.String getHeader()
Returns appropriate HTML headers.

Returns:
the header.
Since:
0.5

getFooter

public java.lang.String getFooter()
The footer.

Returns:
the appropriate HTML footers.
Since:
0.5

getHead

public java.lang.String getHead(java.util.logging.Handler h)

Since:
0.5

getTail

public java.lang.String getTail(java.util.logging.Handler h)

Since:
0.5

ignoresThrowable

public boolean ignoresThrowable()
The HTML layout handles the throwable contained in logging events. Hence, this method return false.

Specified by:
ignoresThrowable in interface ExtendedFormatter
Overrides:
ignoresThrowable in class AbstractFormatter
Returns:
false
Since:
0.5

appendThrowableAsHTML

void appendThrowableAsHTML(java.lang.String[] s,
                           java.io.Writer sbuf)
                     throws java.io.IOException
Write an Throwable as HTML code.

Parameters:
s - the throwable as String array.
sbuf - where to append the output.
Throws:
java.io.IOException - if write fails.
Since:
0.5

getInternalCSS

void getInternalCSS(java.lang.StringBuffer buf)
Generate an internal CSS file.

Parameters:
buf - The StringBuffer where the CSS file will be placed.
Since:
0.5


${license_html}