Hi!

I ended up with this solution:

@Override
public void run(Configuration configuration, Environment environment) {
    addFileLogger("/tmp/application.log");

    LOGGER.info("Preparing configuration");
}

private void addFileLogger(String logFilename) {
    FileAppenderFactory<ILoggingEvent> fileAppenderFactory = new
FileAppenderFactory<>();
    fileAppenderFactory.setCurrentLogFilename(logFilename);
    fileAppenderFactory.setArchive(false);

    LoggerContext loggerContext = LoggingUtil.getLoggerContext();
    LayoutFactory layoutFactory = new DropwizardLayoutFactory();
    LevelFilterFactory levelFilterFactory = new ThresholdLevelFilterFactory();
    AsyncAppenderFactory asyncAppenderFactory = new
AsyncLoggingEventAppenderFactory();
    Appender appender = fileAppenderFactory.build(loggerContext,
getName(), layoutFactory, levelFilterFactory, asyncAppenderFactory);

    Logger root = loggerContext.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    root.addAppender(appender);
}

It is almost a verbatim copy of the solution suggested by Artem Prigoda.

/Thomas


On 21 March 2018 at 08:41, Thomas Sundberg <[email protected]> wrote:
> Hi!
>
> On 20 March 2018 at 20:51, Artem Prigoda <[email protected]> wrote:
>> Hi,
>>
>> Would something likes this work? [1] You can programmatically create and
>> start a file appender via Dropwizard's `FileAppenderFactory` and attach it
>> to the root logger.
>>
>> [1] https://gist.github.com/arteam/355479216321f93f676af7e0839ca940
>>
>
> I kept digging yesterday and I was approaching this solution. Didn't
> get it to work yesterday. Will try your suggestion. It looks very
> promising!
>
> As a side note, this is a very friendly mailing list! I don't ask one
> some other mailing lists anymore because the tone in the responses are
> not so nice. Not the case here.
>
> Thank you!
> Thomas
>
> --
> Thomas Sundberg
> M. Sc. in Computer Science
>
> Mobile: +46 70 767 33 15
> Blog: http://www.thinkcode.se/blog
> Twitter: @thomassundberg
>
> Better software through faster feedback



-- 
Thomas Sundberg
M. Sc. in Computer Science

Mobile: +46 70 767 33 15
Blog: http://www.thinkcode.se/blog
Twitter: @thomassundberg

Better software through faster feedback

-- 
You received this message because you are subscribed to the Google Groups 
"dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to