Reduce the internal logarithmic logic of ORMlite or disable it.

We are doing a very difficult performance tuning in our application, so we are starting to use the method trace to find bottlenecks.

At first glance, Ormlite was fine, but we found that, for example, in one request, which takes 8 ms, 6ms (75%) is required for the internal Ormlite log. Moreover, these log calls are at the DEBUG level.

Currently, I have tried (without success) to set the log level to ERROR as follows:

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

These are a few lines from 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 screenshot of the method trace

ORMLite method tracing

Any thoughts on how to handle this?

+6
source share
2 answers

Using the method trace, we saw that LocalLog was being used. As stated in LocalLog's documentation :

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

We were unable to 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 is increasing as expected.

+10
source

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

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

If this class is not found, it searches for org.apache.log4j.Logger and if found it will use Log4j.

So, we can just use logback.xml as shown below.

 <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> 
+1
source

Source: https://habr.com/ru/post/976073/


All Articles