JakeWharton / JakeWharton/timber
Timber with Logback - Logs appearing only once
- Dominant language
- Kotlin
- Stars
- 10.9k
- Forks
- 994
- Avg merge
- 17h 16m
- Merged PRs (30d)
- 17
Description
Hi,
We have integrated timber and logback into our application and created FileLoggingTree class extending from the Tree provided by Timber.
In the constructor of this we are loading the logback configuration to make use of RollingFileAppender to write the logs to the file specified in the logback.xml. We are planting the FileLoggingTree in our Application's onCreate().
public class FileLoggingTree extends Timber.Tree {
Logger mLogger = (Logger) LoggerFactory.getLogger("filelogger");
public FileLoggingTree() {
configureLogger();
}
private void configureLogger() {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.reset();
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(loggerContext);
URL logbackXml = getClass().getClassLoader().getResource("assets/logback.xml");
try {
configurator.doConfigure(logbackXml);
}
catch (JoranException e) {
e.printStackTrace();
}
}
@Override
protected void log(int priority, String tag, String message, Throwable t) {
String logMessage = tag + " : " + message;
switch (priority) {
case Log.DEBUG:
mLogger.debug(logMessage);
break;
case Log.INFO:
mLogger.info(logMessage);
break;
case Log.WARN:
mLogger.warn(logMessage);
break;
case Log.ERROR:
mLogger.error(logMessage);
break;
}
}
}
Application oncreate() --> Timber.plant(new FileLoggingTree());
Now in this case, the FileLoggingTree is adding logs to the file only once (when configure() is called) after app is launched, but stops logging subsequently.
Thanks in advance!
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the FileLoggingTree implementation and the Application onCreate() call that plants it. Reproduce the behavior with the shown Logback configuration and inspect the Timber.Tree log override and logger setup; done means logs continue being written after the application starts, not only during configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100