mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-24 02:46:50 +01:00
Use logback-android for logging to external storage
(no WRITE_EXTERNAL_STORAGE permission necessary!)
This commit is contained in:
parent
27d725853f
commit
d2bcccaeef
@ -23,5 +23,7 @@ dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile 'com.android.support:appcompat-v7:21.0.3'
|
||||
compile 'com.android.support:support-v4:21.0.3'
|
||||
compile 'com.noveogroup.android:android-logger:1.3.5'
|
||||
// compile 'com.noveogroup.android:android-logger:1.3.5'
|
||||
compile 'com.github.tony19:logback-android-classic:1.1.1-3'
|
||||
compile 'org.slf4j:slf4j-api:1.7.7'
|
||||
}
|
||||
|
28
app/src/main/assets/logback.xml
Normal file
28
app/src/main/assets/logback.xml
Normal file
@ -0,0 +1,28 @@
|
||||
<configuration debug="true">
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.classic.android.LogcatAppender">
|
||||
<!-- encoders are by default assigned the type
|
||||
ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
|
||||
<!--<file>/storage/emulated/0/Android/data/nodomain.freeyourgadget.gadgetbridge/files/gadgetbridge.log</file>-->
|
||||
<file>${GB_LOGFILES_DIR}/gadgetbridge.log</file>
|
||||
<lazy>true</lazy>
|
||||
<!-- encoders are by default assigned the type
|
||||
ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
|
||||
<encoder>
|
||||
<!--<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>-->
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{25} - %msg%n</pattern>
|
||||
<!--<pattern>%date [%thread] %-5level %logger{25} - %msg%n</pattern>-->
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="DEBUG">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="FILE" />
|
||||
</root>
|
||||
</configuration>
|
@ -3,6 +3,17 @@ package nodomain.freeyourgadget.gadgetbridge;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.core.CoreConstants;
|
||||
import ch.qos.logback.core.util.FileUtil;
|
||||
import ch.qos.logback.core.util.StatusPrinter;
|
||||
|
||||
public class GBApplication extends Application {
|
||||
private static GBApplication context;
|
||||
|
||||
@ -10,6 +21,29 @@ public class GBApplication extends Application {
|
||||
context = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
setupLogFileDir();
|
||||
// For debugging problems with the logback configuration
|
||||
// LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
// print logback's internal status
|
||||
// StatusPrinter.print(lc);
|
||||
// String dataDir = lc.getProperty(CoreConstants.DATA_DIR_KEY);
|
||||
// String filename = FileUtil.prefixRelativePath(dataDir, "gadgetbridge.log");
|
||||
// Logger logger = LoggerFactory.getLogger(GBApplication.class);
|
||||
}
|
||||
|
||||
private void setupLogFileDir() {
|
||||
File dir = getExternalFilesDir(null);
|
||||
if (dir != null && !dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
// used by assets/logback.xml since the location cannot be statically determined
|
||||
System.setProperty("GB_LOGFILES_DIR", dir.getAbsolutePath());
|
||||
}
|
||||
|
||||
public static Context getContext() {
|
||||
return context;
|
||||
}
|
||||
|
25
app/src/main/resources/logback.xml
Normal file
25
app/src/main/resources/logback.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<configuration debug="true">
|
||||
|
||||
<!--<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">-->
|
||||
<!--<!– encoders are by default assigned the type-->
|
||||
<!--ch.qos.logback.classic.encoder.PatternLayoutEncoder –>-->
|
||||
<!--<encoder>-->
|
||||
<!--<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>-->
|
||||
<!--</encoder>-->
|
||||
<!--</appender>-->
|
||||
|
||||
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
|
||||
<file>gadgetbridge.log</file>
|
||||
<!-- encoders are by default assigned the type
|
||||
ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
|
||||
<encoder>
|
||||
<!--<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>-->
|
||||
<!--<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{25} - %msg%n</pattern>-->
|
||||
<pattern>%date [%thread] %-5level %logger{25} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="debug">
|
||||
<appender-ref ref="FILE" />
|
||||
</root>
|
||||
</configuration>
|
Loading…
Reference in New Issue
Block a user