2

I'm using dropwizard 0.7-rc1. I'm able to write a log by providing config.yaml. I want to override some of the properties through code. I tried with code but it doesn't work.

code.

@Override
    public void run(XConfiguration configuration, Environment environment)
            throws Exception {
        configuration.setLoggingFactory(null);
        LoggingFactory loggingFactory = new LoggingFactory();
        FileAppenderFactory fileAppenderFactory = new FileAppenderFactory();
        fileAppenderFactory.setArchive(true);
        fileAppenderFactory.setArchivedFileCount(7);
        fileAppenderFactory.setArchivedLogFilenamePattern("rest_service-%d{yyyy-MM-dd}-%i.log.gz");
        Duration duration = Duration. milliseconds(100);
        fileAppenderFactory.setBatchDuration(duration);
        fileAppenderFactory.setBatchSize(128);
        fileAppenderFactory.setBounded(false);
        fileAppenderFactory.setCurrentLogFilename("rest_service.log");
        fileAppenderFactory.setLogFormat("%-6level [%d{HH:mm:ss.SSS}] [%t] %logger{5} - %X{code} %msg %n"); 
        fileAppenderFactory.setThreshold(Level.INFO);
        fileAppenderFactory.setTimeZone(TimeZone.getTimeZone("UTC"));
        ArrayList<AppenderFactory> arrayList = new ArrayList<AppenderFactory>();
        arrayList.add(fileAppenderFactory);
        loggingFactory.setAppenders(arrayList);
        configuration.setLoggingFactory(loggingFactory);

        //registered some resources.     
}

So, How can I do it?

Vishvesh Phadnis
  • 2,448
  • 5
  • 19
  • 35

1 Answers1

0

you can overwrite the logging in dropwizard by overwriting the factory. See DefaultLogginFactory for the class.

I wrote up a complete example on how to overwrite things in dropwizard here:

Dropwizard doesn't log custom loggers to file

Essentially, you'll want to overwrite the build method in the logging factory and add your custom code there.

I hope that helps,

Artur

Community
  • 1
  • 1
pandaadb
  • 6,306
  • 2
  • 22
  • 41