Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logback log.debug not working

Tags:

I've got some strange behaviour from logback, the issue is that log.debug() call stop working and not write to console.

Here is how I create Logger and call log functions:

 public class MyApp extends Application {
    private static Logger log = LoggerFactory.getLogger(MyApp.class);

      @Override
      public void onCreate() {
        log.info("log.isDebugEnabled() {}", log.isDebugEnabled());
        log.error("error test");
        log.debug("HELLO {}", "WORLD");
        log.debug("debug test");
        ..............
        /*some code here*/
        ..............
        super.onCreate();
      }
    ..............
    }

And here is what I see in Android Monitor: android monitor output

As you can see there is NO debug lines, only error and info.

Here is my logback.xml:

    <?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <property name="EXT_FILES_DIR" value="/mnt/sdcard/Android/data/my_dir/files/logs" />
    <timestamp key="bySecond" datePattern="dd.MM.yy'__'HH.mm.ss"/>

    <appender name="logcat" class="ch.qos.logback.classic.android.LogcatAppender">
        <encoder>
            <pattern>%d{HH:mm:ss} :: %-5level :: THREAD [%thread] IN CLASS %logger{5} ON LINE %line - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="FILE"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${EXT_FILES_DIR}/my_log-${bySecond}.log</file>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} :: %-5level :: THREAD [%thread] IN CLASS %logger{5} ON LINE %line - %msg%n</Pattern>
        </encoder>

        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <FileNamePattern>${EXT_FILES_DIR}/my_log-${bySecond}.%i.log.txt</FileNamePattern>
            <MinIndex>1</MinIndex>
            <MaxIndex>10</MaxIndex>
        </rollingPolicy>

        <triggeringPolicy
            class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>2MB</MaxFileSize>
        </triggeringPolicy>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="logcat" />
        <appender-ref ref="FILE"/>
    </root>
</configuration>

Any suggestion? Regards.

like image 863
whizzzkey Avatar asked May 24 '16 06:05

whizzzkey


1 Answers

The problem was in my Device Hyawei Honor 4x - the manufacturer disabled logs on debug level. Solution is:

  1. Dial

    *#*#2846579#*#*
    
  2. Click on ProjectMenu

  3. Click on Background Setting
  4. Click on Log Setting
  5. Select LOG CP and confirm
  6. Reboot the phone.
like image 138
whizzzkey Avatar answered Sep 28 '22 03:09

whizzzkey