You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Darshan Mangani <da...@yahoo.com> on 2001/03/07 17:36:16 UTC
Newbie question about PatternLayout and Appenders.
Hi folks,
I am a new user of Log4J ver 1.0.4.
I have come on board to an existing
implementation/project that uses Log4J for logging. I
have a requirement to log to a database. I have taken
a look at the 2 JDBC appenders that have been
contributed but unfortunately, I have to work with the
existing framework (we have our own DB connection
pooling code, DB access wrappers ..etc..)
My questions are:
(1) How can I access each piece of the LoggingEvent
before or after it gets converted to a string? I use
PatternLayout and the format specifiers are more than
enough for my needs. I need to get at these so that
each piece of it can be persisted in a DB column of a
table. Am I restricted to calling layout.format() in
my appender and then parsing thro' this myself? What
would you suggest?
(2) Is logging done via separate threads? i.e. when my
application calls someCategory.info() or other logging
methods, does the log message immediately get output
or is it handed off to a background thread? I think
AsyncAppender does this part of it, but I am unsure
about how to configure this via XML config files since
we use DOMConfigurator extensively. Also, how does
AsyncAppender know how to log to console as well as to
a file (right now, we have this setup)?
Thanks very much for your patience and help,
Dash
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/
Re: Newbie question about PatternLayout and Appenders.
Posted by Ceki Gülcü <cg...@qos.ch>.
Darshan,
At 08:36 07.03.2001 -0800, Darshan Mangani wrote:
>Hi folks,
>
>I am a new user of Log4J ver 1.0.4.
>
>I have come on board to an existing
>implementation/project that uses Log4J for logging. I
>have a requirement to log to a database. I have taken
>a look at the 2 JDBC appenders that have been
>contributed but unfortunately, I have to work with the
>existing framework (we have our own DB connection
>pooling code, DB access wrappers ..etc..)
>
>My questions are:
>
>(1) How can I access each piece of the LoggingEvent
>before or after it gets converted to a string? I use
>PatternLayout and the format specifiers are more than
>enough for my needs. I need to get at these so that
>each piece of it can be persisted in a DB column of a
>table. Am I restricted to calling layout.format() in
>my appender and then parsing thro' this myself? What
>would you suggest?
See org.apache.log4j.spi.LoggingEvent class.
>(2) Is logging done via separate threads? i.e. when my
>application calls someCategory.info() or other logging
>methods, does the log message immediately get output
>or is it handed off to a background thread? I think
>AsyncAppender does this part of it, but I am unsure
>about how to configure this via XML config files since
>we use DOMConfigurator extensively. Also, how does
>AsyncAppender know how to log to console as well as to
>a file (right now, we have this setup)?
No, logging does not occur through a separate thread except if you use AsyncAppender.
Here is a sample config file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration configDebug="true">
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="TEMP"/>
<appender-ref ref="CONSOLE"/>
</appender>
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
</layout>
</appender>
<appender name="TEMP" class="org.apache.log4j.FileAppender">
<param name="File" value="temp"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
</layout>
</appender>
<root>
<priority value="debug"/>
<appender-ref ref="ASYNC"/>
</root>
</log4j:configuration>
Hope this helps, Ceki
----
Ceki Gülcü Web: http://qos.ch
av. de Rumine 5 email: cgu@qos.ch (preferred)
CH-1005 Lausanne ceki_gulcu@yahoo.com
Switzerland Tel: ++41 21 351 23 15