Decrease ORMlite's internal log verbosity or disable it

后端 未结 3 1033
-上瘾入骨i
-上瘾入骨i 2021-01-12 08:47

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 t

相关标签:
3条回答
  • 2021-01-12 09:05

    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>
    
    0 讨论(0)
  • 2021-01-12 09:12

    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.

    0 讨论(0)
  • 2021-01-12 09:18

    ORMLite documentation on Android mentions how to enable the logs over adb: http://ormlite.com/javadoc/ormlite-core/doc-files/ormlite_4.html#Android-Logging

    However, there's no mention how to disable them. From @Axxiss answer, we can see the proper log level is ERROR. Thus, to disable the logs using adb:

    adb shell setprop log.tag.StatementExecutor ERROR
    adb shell setprop log.tag.BaseMappedStatement ERROR
    adb shell setprop log.tag.MappedCreate ERROR
    
    0 讨论(0)
提交回复
热议问题