use of org.apache.log4j.PatternLayout in project com.revolsys.open by revolsys.
the class ThreadLocalAppenderBean method postProcessBeanFactory.
@Override
public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException {
final ThreadLocalFileAppender localAppender = ThreadLocalFileAppender.getAppender();
final String logFilePath = this.logFile.getAbsolutePath();
if (localAppender != null && this.logFile != null) {
final File parentFile = this.logFile.getParentFile();
if (parentFile != null) {
parentFile.mkdirs();
}
localAppender.setLocalFile(logFilePath);
} else if (this.logFile != null) {
final org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
try {
final Layout layout = new PatternLayout("%d\t%p\t%m%n");
final Appender appender = new ThreadLocalFileAppender(layout, logFilePath, false);
appender.setName("ThreadLocalLog");
rootLogger.addAppender(appender);
} catch (final IOException e) {
final Layout layout = new PatternLayout("%p\t%m%n");
final Appender appender = new ConsoleAppender(layout);
rootLogger.addAppender(appender);
Logs.error(this, "Cannot find log file " + this.logFile, e);
}
}
}
use of org.apache.log4j.PatternLayout in project openmrs-core by openmrs.
the class OpenmrsUtil method setupLogAppenders.
/**
* Setup root level log appenders.
*
* @since 1.9.2
*/
public static void setupLogAppenders() {
Logger rootLogger = Logger.getRootLogger();
FileAppender fileAppender = null;
@SuppressWarnings("rawtypes") Enumeration appenders = rootLogger.getAllAppenders();
while (appenders.hasMoreElements()) {
Appender appender = (Appender) appenders.nextElement();
if (OpenmrsConstants.LOG_OPENMRS_FILE_APPENDER.equals(appender.getName())) {
// the appender already exists
fileAppender = (FileAppender) appender;
break;
}
}
String logLayout = Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GP_LOG_LAYOUT, "%p - %C{1}.%M(%L) |%d{ISO8601}| %m%n");
PatternLayout patternLayout = new PatternLayout(logLayout);
String logLocation = null;
try {
logLocation = OpenmrsUtil.getOpenmrsLogLocation();
if (fileAppender == null) {
fileAppender = new RollingFileAppender(patternLayout, logLocation);
fileAppender.setName(OpenmrsConstants.LOG_OPENMRS_FILE_APPENDER);
rootLogger.addAppender(fileAppender);
} else {
fileAppender.setFile(logLocation);
fileAppender.setLayout(patternLayout);
}
fileAppender.activateOptions();
} catch (IOException e) {
log.error("Error while setting an OpenMRS log file to " + logLocation, e);
}
}
use of org.apache.log4j.PatternLayout 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.PatternLayout in project devonfw-testing by devonfw.
the class BFLoggerInstance method createFileAppender.
private FileAppender createFileAppender() {
PatternLayout patternLayout = new PatternLayout(logPattern);
FileAppender appender;
try {
appender = new FileAppender(patternLayout, getLogFile().getPath(), true);
appender.setName(getAppenderName());
appender.setThreshold(Level.DEBUG);
appender.activateOptions();
} catch (Exception e) {
System.out.println("Unable to create appender: " + e);
return null;
}
return appender;
}
use of org.apache.log4j.PatternLayout in project devonfw-testing by devonfw.
the class BFLoggerInstance method createConsoleAppender.
private ConsoleAppender createConsoleAppender() {
PatternLayout patternLayout = new PatternLayout(logPattern);
ConsoleAppender appender;
try {
appender = new ConsoleAppender(patternLayout);
appender.setTarget(ConsoleAppender.SYSTEM_OUT);
appender.setName("Console");
appender.setThreshold(Level.DEBUG);
appender.activateOptions();
} catch (Exception e) {
System.out.println("Unable to create appender: " + e);
return null;
}
return appender;
}
Aggregations