[logback-user] Number of logs

Greg Flex greg.flex at gmail.com
Mon Sep 22 23:29:09 CEST 2008


Absolutely...
Here is the config file.

<configuration>
  <consolePlugin />

   <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/Greg</url>
      <user>greg</user>
      <password>greg</password>
    </connectionSource>
  </appender>

  <appender name="HSQLDB" class="ch.qos.logback.classic.db.DBAppender">
    <connectionSource
class="ch.qos.logback.core.db.DriverManagerConnectionSource">
      <driverClass>org.hsqldb.jdbcDriver</driverClass>
      <url>jdbc:hsqldb:hsql://localhost/</url>
      <user>sa</user>
      <password></password>
    </connectionSource>
  </appender>

  <appender name="STDOUT"
    class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
      <Pattern>%date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} [%file :
%line] - %msg%n</Pattern>
    </layout>
  </appender>

<appender name="FILE" class="ch.qos.logback.core.FileAppender">
 <layout class="ch.qos.logback.classic.html.HTMLLayout">
   <pattern>%date %relative%thread%mdc%level%logger%msg</pattern>
  </layout>
  <File>C:/tools/test.html</File>
</appender>
    <!--
<appender name="FLAT" class="ch.qos.logback.core.FileAppender">
    <File>H:/tools/testFile.log</File>
    <layout class="ch.qos.logback.classic.PatternLayout">
      <Pattern>%date %relative%thread%mdc%level%logger%msg%n</Pattern>
    </layout>
  </appender>
   -->
<!--
  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <File>testFile.log</File>
    <Append>true</Append>
    <layout class="ch.qos.logback.classic.PatternLayout">
      <Pattern>%date [%thread] %-5level %logger{35} - %msg%n</Pattern>
    </layout>
  </appender>
  -->
  <root>
    <level value="debug" />
   <appender-ref ref="DB" />
  </root>
</configuration>

Right now as you can see is set to write to a DB which is a MySQl database.
Here is the Java code I'm using to test this.


public class DBConnector {
 Logger logger = null;
 public static void main(String[] args) {
  DBConnector dbc  = new DBConnector();
  dbc.doSomething();
 }
 public void doSomething(){
  logger = LoggerFactory.getLogger(DBConnector.class);
  readConfig();
   PerformanceBenchmark();
 }
    public void PerformanceBenchmark()
 {
  // Get current time
     long start = System.currentTimeMillis();
  for (int i = 0; i < 10000; ++i)
  {
   logger.debug("INFO Entering application.");
   logger.info("INFO Entering application.");
  }
   Foo f = new Foo();
   f.doIt();
   logger.info("Exiting Application");
         // Get elapsed time in milliseconds
             try {
       throw new Exception("Testing exception");
     }
     catch(Exception e)
     {
       long elapsedTimeMillis = System.currentTimeMillis()-start;
       logger.info("Time in ms is: " + elapsedTimeMillis, e);
     }
        //System.out.println(elapsedTimeMillis);
 }
 private void readConfig()
 {
     LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
     try {
   JoranConfigurator configurator = new JoranConfigurator();
   lc.shutdownAndReset();
   configurator.setContext(lc);
   configurator.doConfigure("src/DBConnectorXML.xml");
  } catch (JoranException je) {
   StatusPrinter.print(lc);
  }
 }
}


public class Foo {
  static final Logger logger = LoggerFactory.getLogger(Foo.class);
  public void doIt() {
    logger.debug("Got in here!");
  }
}

As you can see I'm just playing aroung with it.....
The code is complete... meaning you can compile it and run it.
See if you can reproduce the problem.....
Thanks





On Mon, Sep 22, 2008 at 2:11 PM, Ceki Gulcu <listid at qos.ch> wrote:

>
>
> Interesting. Could you please share your config file and code?
>
> Greg Flex wrote:
> > Hi all,
> > I'm running some benchmarking and I've noticed that when calling
> logger.xxx
> > in a loop (10,000 iterations) only about 3964 are written. I'm testing
> > this with both
> > MySQL and HSQLDB databases.
> > Can someone please let me know what's seems to be a problem?
> > Do I need to configure this in some config file?
> > How many times I can write at once to a database?
> > Thanks
> >
> >
>
>
> --
> Ceki Gülcü
> Logback: The reliable, generic, fast and flexible logging framework for
> Java.
> http://logback.qos.ch
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://qos.ch/pipermail/logback-user/attachments/20080922/51afe957/attachment.htm 


More information about the Logback-user mailing list