[logback-user] About DBAppender

Mohammad Firoj Haider mohammadh at lashpoint.com
Sun Feb 28 17:17:47 CET 2010


I am new in Logback framework. I want to use mysql database to store my log.
So I have set my logback-test.xml file in the following way:

<?xml version="1.0" encoding="UTF-8"?>
  <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">

  <root level="debug">
    <appender-ref ref="DB" />

After that I created a database which is called "testlogback".

I have two simple java classes. The code snippet is:
 public class TestLogger { public static void main(String[] args){

Logger logger = LoggerFactory.getLogger("com.lashpoint.TestLogger");
LoggerContext lc=(LoggerContext) LoggerFactory.getILoggerFactory();

logger.debug("Test start");
System.out.println("Hello World Logback");
SalaryTestLogger test=new SalaryTestLogger ();
System.out.println("Division: "+test.getSalary());
logger.debug("Test end");

public class SalaryTestLogger {

        public SalaryTestLogger(){
logger=LoggerFactory.getLogger("com.lashpoint.SalaryTestLogger ");


After running the code, I got the following output (However, I put
StatusPrinter.print(lc) to see internal state).

Driver name=MySQL-AB JDBC Driver
Driver version=mysql-connector-java-5.0.7 ( $Date: 2007-03-09 22:13:57 +0100
(Fri, 09 Mar 2007) $, $Revision: 6341 $ )
12:08:37,312 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found
resource [logback-test.xml] at
12:08:37,421 |-INFO in
ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute
not set
12:08:37,421 |-INFO in ch.qos.logback.core.joran.action.AppenderAction -
About to instantiate appender of type [ch.qos.logback.classic.db.DBAppender]
12:08:37,437 |-INFO in ch.qos.logback.core.joran.action.AppenderAction -
Naming appender as [DB]
12:08:37,468 |-INFO in
ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Pushing component
[connectionSource] on top of the object stack.
12:08:37,812 |-INFO in ch.qos.logback.core.joran.action.AppenderAction -
Popping appender named [DB] from the object stack
12:08:37,812 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction
- Setting level of ROOT logger to DEBUG
12:08:37,812 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction -
Attaching appender named [DB] to Logger[ROOT]

Hello World Logback
Salry Per Hour: 0.0

The MOST INTERESTING THING is that, it did not log anything to
logging_event, logging_event_exception, logging_event_property tables.

So I think I am missing something. I would be glad if someone kindly help me
to solve this issue.

 Mohammad Firoj Haider
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/logback-user/attachments/20100228/99139360/attachment.html>

More information about the Logback-user mailing list