use of org.apache.log4j.PatternLayout in project cpsolver by UniTime.
the class Test method setupLogging.
/**
* Setup log4j logging
*
* @param logFile
* log file
* @param debug
* true if debug messages should be logged (use -Ddebug=true to
* enable debug message)
*/
public static void setupLogging(File logFile, boolean debug) {
Logger root = Logger.getRootLogger();
ConsoleAppender console = new ConsoleAppender(new PatternLayout("[%t] %m%n"));
console.setThreshold(Level.INFO);
root.addAppender(console);
if (logFile != null) {
try {
FileAppender file = new FileAppender(new PatternLayout("%d{dd-MMM-yy HH:mm:ss.SSS} [%t] %-5p %c{2}> %m%n"), logFile.getPath(), false);
file.setThreshold(Level.DEBUG);
root.addAppender(file);
} catch (IOException e) {
sLog.fatal("Unable to configure logging, reason: " + e.getMessage(), e);
}
}
if (!debug)
root.setLevel(Level.INFO);
}
use of org.apache.log4j.PatternLayout in project suite by stupidsing.
the class LogUtil method initLog4j.
public static void initLog4j(Level level) {
Path logDir = Constants.tmp("logs");
PatternLayout layout = new PatternLayout("%d %-5p [%c{1}] %m%n");
ConsoleAppender console = new ConsoleAppender(layout);
console.setWriter(new PrintWriter(System.err));
console.activateOptions();
DailyRollingFileAppender file = new DailyRollingFileAppender();
file.setFile(logDir.resolve("suite.log").toString());
file.setDatePattern("'.'yyyyMMdd");
file.setLayout(layout);
file.activateOptions();
Logger logger = Logger.getRootLogger();
logger.setLevel(level);
logger.removeAllAppenders();
logger.addAppender(console);
logger.addAppender(file);
}
use of org.apache.log4j.PatternLayout in project traccar by tananaev.
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 uavstack by uavorg.
the class Log4jHookProxy method figureoutLogConfiguration.
@SuppressWarnings("unchecked")
private void figureoutLogConfiguration(Logger Logger, LinkedList<LogProfileInfo> list, String appid) {
Enumeration<Appender> appenders = Logger.getAllAppenders();
while (appenders != null && appenders.hasMoreElements()) {
LogProfileInfo logProfileInfo = new LogProfileInfo();
if (appid != null) {
logProfileInfo.setAppId(appid);
}
logProfileInfo.setLogType(LogProfileInfo.LogType.Log4j);
Map<String, String> attributes = new HashMap<String, String>();
attributes.put(LogProfileInfo.ENGINE, "log4j");
Appender appender = appenders.nextElement();
if (!(appender instanceof FileAppender)) {
continue;
}
FileAppender fileAppender = (FileAppender) appender;
Layout layout = fileAppender.getLayout();
if (null != layout) {
if (layout instanceof PatternLayout) {
PatternLayout patternLayout = (PatternLayout) fileAppender.getLayout();
attributes.put(LogProfileInfo.PATTERN, patternLayout.getConversionPattern());
} else if (layout instanceof HTMLLayout) {
attributes.put(LogProfileInfo.PATTERN, "HTMLLayout");
} else if (layout instanceof SimpleLayout) {
attributes.put(LogProfileInfo.PATTERN, "SimpleLayout");
} else if (layout instanceof TTCCLayout) {
attributes.put(LogProfileInfo.PATTERN, "TTCCLayout");
}
}
boolean useBuffIO = fileAppender.getBufferedIO();
if (useBuffIO == true) {
attributes.put(LogProfileInfo.BUFFER_SIZE, String.valueOf(fileAppender.getBufferSize()));
attributes.put(LogProfileInfo.BUFFRT_IO, String.valueOf(useBuffIO));
}
logProfileInfo.setFilePath(fileAppender.getFile());
logProfileInfo.setAttributes(attributes);
list.add(logProfileInfo);
}
}
use of org.apache.log4j.PatternLayout in project xian by happyyangyuan.
the class GelfLog4j1Init method addGelfAppender.
private static void addGelfAppender() {
GelfAppender appender = new GelfJsonAppender();
appender.setName(GELF_APPENDER_NAME);
if (EnvUtil.isLan()) {
appender.setGraylogHost(XianConfig.get("gelfInputLanUrl"));
} else {
appender.setGraylogHost(XianConfig.get("gelfInputInternetUrl"));
}
appender.setGraylogPort(XianConfig.getIntValue("gelfInputInternetUrl"));
appender.setFacility("gelf-java");
appender.setLayout(new PatternLayout() {
{
setConversionPattern("%p %m");
}
});
appender.setExtractStacktrace(true);
appender.setIncludeLocation(false);
JSONObject additionalFields = new JSONObject() {
{
put("environment", EnvUtil.getEnv());
put("application", EnvUtil.getApplication());
put("pid", JavaPIDUtil.getProcessName());
put("nodeId", LocalNodeManager.LOCAL_NODE_ID);
}
};
appender.setAddExtendedInformation(true);
appender.setAdditionalFields(additionalFields.toJSONString());
appender.setOriginHost(JavaPIDUtil.getHostname());
// 让以上设置生效
appender.activateOptions();
Logger.getRootLogger().addAppender(appender);
}
Aggregations