
Hi, 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"?> <configuration> <appender name="DB" class="ch.qos.logback.classic.db.DBAppender"> <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource"> <driverClass>com.mysql.jdbc.Driver</driverClass> <url>jdbc:mysql://localhost:3306/testlogback</url> <user>root</user> <password>test</password> </connectionSource> </appender> <root level="debug"> <appender-ref ref="DB" /> </root> </configuration> 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(); StatusPrinter.print(lc); logger.debug("Test start"); System.out.println("Hello World Logback"); SalaryTestLogger test=new SalaryTestLogger (); test.setHour(0); test.setSalary(100); 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 $ ) supportsGetGeneratedKeys=true true 12:08:37,312 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback-test.xml] at [file:/E:/DevTools/projects/Test/LogbackTest/src/com/lashpoint/logger/logback-test.xml] 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. -- Thanks Mohammad Firoj Haider
participants (1)
-
Mohammad Firoj Haider