use of org.apache.log4j.varia.NullAppender in project traccar by traccar.
the class Log method setupLogger.
public static void setupLogger(Config config) throws IOException {
Layout layout = new PatternLayout("%d{" + DATE_FORMAT + "} %5p: %m%n");
Appender appender = new DailyRollingFileAppender(layout, config.getString("logger.file"), "'.'yyyyMMdd");
LogManager.resetConfiguration();
LogManager.getRootLogger().addAppender(new NullAppender());
logger = Logger.getLogger(LOGGER_NAME);
logger.addAppender(appender);
logger.setLevel(Level.toLevel(config.getString("logger.level"), Level.ALL));
// Workaround for "Bug 745866 - (EDG-45) Possible netty logging config problem"
InternalLoggerFactory.setDefaultFactory(new InternalLoggerFactory() {
@Override
public InternalLogger newInstance(String string) {
return new NettyInternalLogger();
}
});
Log.logSystemInfo();
Log.info("Version: " + getAppVersion());
}
use of org.apache.log4j.varia.NullAppender in project pwm by pwm-project.
the class MainClass method initLog4j.
private static void initLog4j(final PwmLogLevel logLevel) {
if (logLevel == null) {
Logger.getRootLogger().removeAllAppenders();
Logger.getRootLogger().addAppender(new NullAppender());
PwmLogger.markInitialized();
return;
}
final Layout patternLayout = new EnhancedPatternLayout(LOGGING_PATTERN);
final ConsoleAppender consoleAppender = new ConsoleAppender(patternLayout);
for (final Package logPackage : PwmLogManager.LOGGING_PACKAGES) {
if (logPackage != null) {
final Logger logger = Logger.getLogger(logPackage.getName());
logger.addAppender(consoleAppender);
logger.setLevel(logLevel.getLog4jLevel());
}
}
PwmLogger.markInitialized();
}
use of org.apache.log4j.varia.NullAppender in project ignite by apache.
the class GridCacheAbstractLoadTest method configuration.
/**
* Initializes configurations.
*
* @param springCfgPath Configuration file path.
* @param log Log file name.
* @return Configuration.
* @throws IgniteCheckedException If fails.
*/
protected IgniteConfiguration configuration(String springCfgPath, String log) throws IgniteCheckedException {
File path = GridTestUtils.resolveIgnitePath(springCfgPath);
if (path == null)
throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + ". Note that this path should be either absolute path or a relative path to IGNITE_HOME.");
if (!path.isFile())
throw new IgniteCheckedException("Provided file path is not a file: " + path);
// Add no-op logger to remove no-appender warning.
Appender app = new NullAppender();
Logger.getRootLogger().addAppender(app);
ApplicationContext springCtx;
try {
springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString());
} catch (BeansException | MalformedURLException e) {
throw new IgniteCheckedException("Failed to instantiate Spring XML application context: " + e.getMessage(), e);
}
Map cfgMap;
try {
// Note: Spring is not generics-friendly.
cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
} catch (BeansException e) {
throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e);
}
if (cfgMap == null)
throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path);
// Remove previously added no-op logger.
Logger.getRootLogger().removeAppender(app);
if (cfgMap.isEmpty())
throw new IgniteCheckedException("Can't find grid factory configuration in: " + path);
else if (cfgMap.size() > 1)
throw new IgniteCheckedException("More than one configuration provided for cache load test: " + cfgMap.values());
IgniteConfiguration cfg = (IgniteConfiguration) cfgMap.values().iterator().next();
cfg.setGridLogger(initLogger(log));
cfg.getTransactionConfiguration().setDefaultTxIsolation(isolation);
cfg.getTransactionConfiguration().setDefaultTxConcurrency(concurrency);
return cfg;
}
Aggregations