[logback-user] Stop & Start Appender?

Martin Vávra martin.vavra.cz at gmail.com
Sun Aug 16 02:25:33 CEST 2015


Hi,

Short version: If the creation of the appender fails (permission denied),
how do I explicitly re-attempt to create it when the problems with the
permissions are resolved. I am using XML configuration. I would like to do
this without re-starting my process.

Longer version:

I am using Logback on Android (logback-android).

I am logging to a directory on the external storage, which means that if
the user connects the device to the PC and enables mass-storage, the file
system of the directory will be unmounted.

If the application is started, while the directory is not available, I
inform the user but since the loggers are defined as static fields ...

private static final Logger LOG =
LoggerFactory.getLogger(MyApplication.class);

... logback attempts to create the appender anyway and fails.

Because of how Android works, the application process continues running
even when the user leaves all screens of my application (for example goes
to the home screen) and so the appender will never be re-attempted to be
created.

Is there some way to reset the appender from the config? If so, I could
attempt to reset logback if necessary whenever the user enters the initial
screen of my application.

I tried to stop it using ...

LoggerContext loggerContext = (LoggerContext)
LoggerFactory.getILoggerFactory();
if (loggerContext != null)
loggerContext.stop();

... which seems to work fine but I don't seem to be able to re-start it:

loggerContext.start()

This does not seem to re-create the appender.

Many thanks in advance for help.

Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20150816/fc3332bf/attachment.html>


More information about the Logback-user mailing list