Skip to content

Latest commit

 

History

History
128 lines (112 loc) · 3.2 KB

README.md

File metadata and controls

128 lines (112 loc) · 3.2 KB

Log4j2-HtmlPatternLayout

Extends log4j2 HTMLLayout with the possibility to format strings using the syntax used in the pattern layout.

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration packages="com.github.kilianB.log4j"
	status="WARN">
	<Appenders>
		<File name="LOGFILE" fileName="logfile.html" append="false">
			<PatternHtmlLayout
				pattern="%p %td %d{HH:mm:ss} %td %c{1} %td %m"
				header="Priority,Time,Sender,Message" omitStyle="true"
				justTable = "true"
				theadCSSClass= "thead-dark"
				tableCSSClass="table table-striped" />
		</File>
	</Appenders>
	<Loggers>
		<Root level="info">
			<AppenderRef ref="LOGFILE" />
		</Root>
	</Loggers>
</Configuration>

log4j2.properties example

packages = com.github.kilianB.log4j

appender.fileAppender.type = File
appender.fileAppender.name = LOGFILE
appender.fileAppender.append = FALSE
appender.fileAppender.layout.type = PatternHtmlLayout
appender.fileAppender.layout.header = Priority,Time,Sender,Message
appender.fileAppender.layout.pattern = %p %td %d{HH:mm:ss} %td %c{1} %td %m
appender.fileAppender.layout.omitStyle = TRUE
appender.fileAppender.layout.tableCSSClass = striped highlight responsive-table

Configuration parameters.

Tags Description Default
header Comma seperated list of table headers. The table will have as many columns as headers supplied REQUIRED
pattern The pattern usage as defined by the pattern layout. The new introduced %td% keyword symbolizes the start of a new table cell. REQUIRED - %m%n
omitStyle TRUE | FALSE. Ignore the default styling of the original htmlLayout FALSE
justTable TRUE | FALSE. Only print the table content to the file without html head/body markup. if true omitStyle is implied to be true FALSE
tableCSSClass CSS class attached to the table tag. Useful if embedded into page with external styles
theadCSSClass CSS class attached to the thead tag. Useful if embedded into page with external styles
title title of the html page Log4j Log Messages
contentType html head tag. default text/html
charset charset of the html page UTF-8
fontSize fontSize used in the table. Ignored if omitStyle = TRUE small
fontName Font used in the table. Ignored if omitStyle = TRUE arial,sans-serif
fontName Font used in the table. Ignored if omitStyle = TRUE arial,sans-serif
alwaysWriteExceptions Outputs exceptions even if no exception is included in the pattern TRUE
noConsoleNoAnsi If true and System.console() is null, do not output ANSI escape codes. FALSE