use of org.apache.log4j.PatternLayout in project n4js by eclipse.
the class N4jsUiLoggingInitializer method init.
/**
* Initializes the log4j logging with an additional appender which routes the logging to the Eclipse ErrorView.
*/
public static void init() {
Logger rootLogger = Logger.getRootLogger();
// # This appender will write to the Eclipse error log. It will ONLY log ERROR and FATAL messages.
// log4j.appender.eclipse=org.eclipse.xtext.logging.EclipseLogAppender
EclipseLogAppender eclipseAppender = new EclipseLogAppender();
eclipseAppender.setName("eclipse");
rootLogger.addAppender(eclipseAppender);
// log4j.appender.eclipse.layout=org.apache.log4j.PatternLayout
// log4j.appender.eclipse.layout.ConversionPattern=%c %x - %m%n
eclipseAppender.setLayout(new PatternLayout("%c %x - %m%n"));
// # EclipseLogAppender must not log to the 'eclipse' appender as that would cause a stack overflow!
// log4j.additivity.org.eclipse.xtext.logging.EclipseLogAppender=false
// log4j.logger.org.eclipse.xtext.logging.EclipseLogAppender=WARN, default
Logger eclipseAppenderLogger = Logger.getLogger(EclipseLogAppender.class);
eclipseAppenderLogger.setAdditivity(false);
eclipseAppenderLogger.setLevel(Level.WARN);
Appender defaultAppender = eclipseAppenderLogger.getAppender("default");
if (eclipseAppenderLogger.getAllAppenders().hasMoreElements()) {
eclipseAppenderLogger.removeAllAppenders();
}
if (defaultAppender != null) {
eclipseAppenderLogger.addAppender(defaultAppender);
}
}
use of org.apache.log4j.PatternLayout in project incubator-servicecomb-java-chassis by apache.
the class Log4JMetricsFileWriter method initLogger.
private RollingFileAppender initLogger(String loggerName, String filePrefix) {
String fileName = Paths.get(rootPath, filePrefix + "." + loggerName + ".dat").toString();
RollingFileAppender fileAppender = new RollingFileAppender();
fileAppender.setName(loggerName);
fileAppender.setFile(fileName);
fileAppender.setLayout(new PatternLayout("%m%n"));
fileAppender.setAppend(true);
fileAppender.setMaxFileSize(maxFileSize);
fileAppender.setMaxBackupIndex(maxFileCount);
fileAppender.activateOptions();
return fileAppender;
}
use of org.apache.log4j.PatternLayout in project walkmod-core by walkmod.
the class AbstractWalkmodExecutionTest method run.
public String run(String[] args) throws Exception {
ByteArrayOutputStream mem = new ByteArrayOutputStream();
BufferedOutputStream stream = new BufferedOutputStream(mem);
PrintStream ps = new PrintStream(stream);
PrintStream old = System.out;
System.setOut(ps);
WalkModFacade.log = Logger.getLogger(WalkModFacade.class.getName());
WalkModFacade.log.removeAllAppenders();
ConfigurationImpl.log = Logger.getLogger(ConfigurationImpl.class.getName());
ConfigurationImpl.log.removeAllAppenders();
ConsoleAppender appender = new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN));
appender.setName("stdout");
WalkModFacade.log.addAppender(appender);
ConfigurationImpl.log.addAppender(appender);
String result = "";
try {
WalkModDispatcher.main(args);
stream.flush();
result = mem.toString();
} finally {
System.setOut(old);
ps.close();
stream.close();
mem.close();
}
return result;
}
use of org.apache.log4j.PatternLayout in project QueryAnalysis by Wikidata.
the class LoggingHandler method initFileLog.
/**
* Defines an appender that writes all log messages of level levelToWrite or higher to the file fileToWrite.
*
* @param fileToWrite File to write the log to.
*/
public static void initFileLog(String fileToWrite, Level levelToWrite) {
TimestampFileAppender fileAppender = new TimestampFileAppender();
fileAppender.setName("FileLogger");
fileAppender.setLayout(new PatternLayout(" [%p] %d [%t] %x %c %M - %m%n"));
fileAppender.setFile(fileToWrite);
fileAppender.setThreshold(levelToWrite);
fileAppender.activateOptions();
Logger.getRootLogger().addAppender(fileAppender);
}
use of org.apache.log4j.PatternLayout in project com.revolsys.open by revolsys.
the class ScriptTool method run.
private void run() {
final long startTime = System.currentTimeMillis();
final ThreadLocalFileAppender localAppender = ThreadLocalFileAppender.getAppender();
if (localAppender != null && this.logFile != null) {
final File parentFile = this.logFile.getParentFile();
if (parentFile != null) {
parentFile.mkdirs();
}
localAppender.setLocalFile(this.logFile.getAbsolutePath());
} 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 FileAppender(layout, this.logFile.getAbsolutePath(), false);
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);
}
}
final StringBuilder message = new StringBuilder("Processing ");
message.append(" -s ");
message.append(this.scriptFileName);
if (this.propertiesName != null) {
message.append(" -p ");
message.append(this.propertiesName);
}
for (final Entry<String, String> parameter : this.parameters.entrySet()) {
message.append(" ");
message.append(parameter.getKey());
message.append("=");
message.append(parameter.getValue());
}
System.out.println(message);
if (System.getProperty("applicationHome") == null) {
ThreadSharedProperties.setProperty("applicationHome", ".");
System.setProperty("applicationHome", ".");
}
try {
final GenericApplicationContext beans = new GenericApplicationContext();
AnnotationConfigUtils.registerAnnotationConfigProcessors(beans, null);
beans.getBeanFactory().addPropertyEditorRegistrar(new ResourceEditorRegistrar());
if (this.scriptFile != null) {
new XmlBeanDefinitionReader(beans).loadBeanDefinitions("file:" + this.scriptFile.getAbsolutePath());
} else {
new XmlBeanDefinitionReader(beans).loadBeanDefinitions("classpath:" + this.scriptFileName);
}
beans.refresh();
try {
Logs.info(this, message.toString());
final Object bean = beans.getBean("processNetwork");
final ProcessNetwork pipeline = (ProcessNetwork) bean;
pipeline.startAndWait();
} finally {
beans.close();
}
} catch (final BeanCreationException e) {
final Throwable cause = getBeanExceptionCause(e);
Logs.error(this, cause.getMessage(), cause);
cause.printStackTrace();
System.err.flush();
}
final long endTime = System.currentTimeMillis();
final long time = endTime - startTime;
long seconds = time / 1000;
final long minutes = seconds / 60;
seconds = seconds % 60;
Logs.info(this, minutes + " minutes " + seconds + " seconds");
System.out.println(minutes + " minutes " + seconds + " seconds");
}
Aggregations