Skip to content

Logging

Entity Service uses slf4j-api as the logging facade library. The appropriate adapter dependencies that makes sense for your logging setup, like slf4j-log4j2 or slf4j-nop will need to be added.

On Android, it's recommended to use logback-android.

Add dependencies

1
runtimeOnly 'com.github.tony19:logback-android:2.0.0'

It is recommended to declare logback-android with runtimeOnly scope (comparable to the runtime scope in Maven). This means the classes are first available at runtime and not during development. This ensures that you are always programming against the Slf4j API.

Customize the configuration

Configuration is done in logback.xml which on Android is placed in the assets directory.

Below shows an example to log the SDK logs to logcat console.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
    <configuration>

        <!-- Create a appender to logcat -->
        <appender name="logcat" class="ch.qos.logback.classic.android.LogcatAppender">
            <encoder>
              <pattern>%msg</pattern>
            </encoder>
        </appender>

        <!-- Log from Telenav SDK -->
        <logger name="com.telenav.sdk" level="INFO">
            <appender-ref ref="logcat" />
        </logger>

        <!-- Log from Telenav Search engine -->
        <logger name="UnifiedSearch" level="INFO">
            <appender-ref ref="logcat" />
        </logger>
    </configuration>

Below shows an example to log the SDK logs to file #APP_LOG_PATH#/sdkLogs/sdkLog.log and the log files will be rotated by daily, meanwhile only the most recent 7 log files will be kept. Refer to document to get more details.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
    <configuration>
        <property name="LOG_DIR" value="#YOUR_APP_LOG DIRECTORY#" />

        <!-- Create a file appender for SDK log -->
        <appender name="sdkLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <filter class="ch.qos.logback.classic.filter.LevelFilter">
                <level>INFO</level>
                <onMatch>ACCEPT</onMatch>
                <onMismatch>DENY</onMismatch>
            </filter>
            <file>${LOG_DIR}/sdkLogs/sdkLog.log</file>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <!-- daily rollover -->
                <fileNamePattern>${LOG_DIR}/sdkLogs/sdkLog.log.%d{yyyy-MM-dd}</fileNamePattern>

                <!-- keep 7 days' worth of history -->
                <maxHistory>7</maxHistory>
            </rollingPolicy>
            <encoder>
                <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
            </encoder>
        </appender>

        <!-- Log from Telenav SDK -->
        <logger name="com.telenav.sdk" level="INFO">
            <appender-ref ref="sdkLog" />
        </logger>

        <!-- Log from Telenav Search engine -->
        <logger name="UnifiedSearch" level="INFO">
            <appender-ref ref="sdkLog" />
        </logger>

    </configuration>