Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decrease ORMlite's internal log verbosity or disable it

We're doing some heavy performance tuning in our app, hence we start using method tracing to find the bottlenecks.

At first glance Ormlite was fine, but we found that for example in one query that takes 8ms, 6ms (75%) were needed by Ormlite's internal log. Futhermore those log call are in DEBUG level.

At the moment I have tried (without success) setting log level to ERROR this way:

  • with adb: adb shell setprop log.tag.ORMLite ERROR
  • with logback: <logger name="com.j256.ormlite" level="ERROR"/>

This are a few lines from the logcat

I/System.out( 4207): 2014-10-01 10:50:14,702 [DEBUG] BaseMappedStatement query-for-id using ...
I/System.out( 4207): 2014-10-01 10:50:14,706 [DEBUG] StatementExecutor executing raw query for ...
I/System.out( 4207): 2014-10-01 10:50:14,709 [DEBUG] SelectIterator starting iterator  @-1593957304 for ...
I/System.out( 4207): 2014-10-01 10:50:14,711 [DEBUG] SelectIterator closed iterator @-1593957304 after 1 rows
I/System.out( 4207): 2014-10-01 10:50:14,714 [DEBUG] BaseMappedStatement query-for-id using ...
I/System.out( 4207): 2014-10-01 10:50:14,717 [DEBUG] BaseMappedStatement query-for-id using ...
I/System.out( 4207): 2014-10-01 10:50:14,718 [DEBUG] StatementBuilder built statement ...
I/System.out( 4207): 2014-10-01 10:50:14,719 [DEBUG] BaseMappedStatement prepared statement ...

Here is a screnshot of method tracing

ORMLite method tracing

Any thoughts on how to handle this out?

like image 896
Axxiss Avatar asked Sep 30 '14 19:09

Axxiss


2 Answers

With method tracing we saw that LocalLog was being used. As is stated on LocalLog's documentation:

You can set the log level by setting the System.setProperty(LocalLog.LOCAL_LOG_LEVEL_PROPERTY, "trace").
Acceptable values are: TRACE, DEBUG, INFO, WARN, ERROR, and FATAL.

We couldn't set the property using adb shell so we added the following line to our Application.onCreate

System.setProperty(LocalLog.LOCAL_LOG_LEVEL_PROPERTY, "ERROR");

Finally we stop seeing ORMLite output on logcat and performance increased as expected.

like image 181
Axxiss Avatar answered Nov 05 '22 04:11

Axxiss


For me I used ORMLite in my project (not with android). there I used the logback.xml to configure it.

http://ormlite.com/javadoc/ormlite-core/doc-files/ormlite_5.html

If that class is not found it then looks for org.apache.log4j.Logger and if found will use Log4j.

So we can simply use logback.xml as bellow.

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <logger name="com.my.test" level="TRACE" additivity="false">
        <appender-ref ref="STDOUT" />
    </logger>

    <root level="INFO">
        <appender-ref ref="STDOUT"/>
    </root>
</configuration>
like image 1
Janaka Priyadarshana Avatar answered Nov 05 '22 06:11

Janaka Priyadarshana