I suspect you will need Dropwizard >= 1.2.0 for looser coupling between DW and logging initialization. See: https://github.com/dropwizard/dropwizard/pull/1900
On Monday, January 15, 2018 at 2:17:06 PM UTC-5, tuk wrote: > > Crossposting from stackoverflow > <https://stackoverflow.com/questions/48268724/slf4j-warning-loggers-will-not-work-as-they-were-created-during-initialization> > > I am using slf4j with logback in a dropwizard application. During the > application initialization I am seeing logs like below > > SLF4J: The following loggers will not work because they were created > SLF4J: during the default configuration phase of the underlying logging > system. > SLF4J: See also http://www.slf4j.org/codes.html#substituteLogger > SLF4J: com.vnera.healthandmetrics.VneraMetrics > > I am using logback.xml with my dropwizard application. My code flow looks > like below > > public class VneraMetrics { > private static final Logger logger = > LoggerFactory.getLogger(VneraMetrics.class); > ... > // This method is getting called from Service.run() during the dropwizard > application initialization > public String getSomeValue() { > // logger is not accessed from this function > return "Some initialized value"; > }} > public class Service extends Application<Conf> { > public static final Logger logger = LoggerFactory.getLogger(Service.class); > public static void main(String args[]) { > logger.info("Some logs"); > Service service = new Service(); > service.run(dropWizardArgs); > Utils.reloadLogger(); > }} > > Utils.reloadLogger() is loading the loggback configuration as discussed > here > > public static void reloadLogger() { > String loggingConfig = > System.getProperty("logback.configurationFile"); > if(loggingConfig == null) { > System.out.println("Logging Config is null"); > } > > LoggerContext loggerContext = (LoggerContext) > LoggerFactory.getILoggerFactory(); > loggerContext.reset(); > JoranConfigurator configurator = new JoranConfigurator(); > > try { > InputStream configStream = FileUtils.openInputStream(new > File(loggingConfig)); > configurator.setContext(loggerContext); > configurator.doConfigure(configStream); // loads logback file > configStream.close(); > System.out.println("Loaded configuration file"); > } catch (JoranException | IOException e) { > e.printStackTrace(); > System.out.println("Failed to log configuration file"); > System.exit(1); > } > }} > > *Versions* > > - Logback - 1.2.3 > - Dropwizard - 1.0.2 > > Can some one let me know what does the SLF4J warning denotes? I have seen > the substituteLogger <http://www.slf4j.org/codes.html#substituteLogger> page > but this does not mention how can I get around this? On trying to use > logger in VneraMetrics it is not printing anything. > -- 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.
