LoggingConfigurator implements GridConfigurator { @Override public String[] configure(String[] args) { boolean isLog4jConfigured = Logger.getRootLogger().getAllAppenders().hasMoreElements(); if (!isLog4jConfigured) { logLevel = Arrays.asList(args).contains("-debug") ? Level.DEBUG : getDefaultLogLevel(); String logFilename = getLogFilename(args); if (logFilename != null && !logFilename.isEmpty()) { installFileAppender(logFilename); } else { installConsoleAppender(); LOG.info("No logging configuration found, logging to console"); } } return clearLogFilenameParam(args); }  @Override String[] configure(String[] args);  }
@Test public void configure_shouldInstallConsoleAppender() throws Exception { loggingConfigurator.configure(NO_ARGS); Appender appender = Logger.getRootLogger().getAppender("Console"); assertNotNull(appender); assertThat(appender, instanceOf(ConsoleAppender.class)); }
@Test public void configure_shouldInstallFileAppenderFromArguments() throws Exception { String[] arguments = loggingConfigurator.configure(new String[]{"-log", "target/" + LOG_FILENAME}); assertEquals(0, arguments.length); Appender appender = Logger.getRootLogger().getAppender("FileAppender"); assertNotNull(appender); assertThat(appender, instanceOf(RollingFileAppender.class)); assertThat(((RollingFileAppender) appender).getFile(), endsWith(LOG_FILENAME)); assertThat(arguments.length, is(0)); }