use of com.axway.ats.agentapp.standalone.log.appenders.SizeRollingFileAppender in project ats-framework by Axway.
the class ContainerStarter method addAppender.
private static void addAppender() throws IOException {
Map<Object, Object> variables = System.getProperties();
Level logLevel = Level.INFO;
String pattern = (String) variables.get("logging.pattern");
String agentPort = (String) variables.get("ats.agent.default.port");
String agentSeverity = (String) variables.get("logging.severity");
// check agent logging severity and set the appropriate level
if ("INFO".equalsIgnoreCase(agentSeverity)) {
logLevel = Level.INFO;
} else if ("DEBUG".equalsIgnoreCase(agentSeverity)) {
logLevel = Level.DEBUG;
} else if ("WARN".equalsIgnoreCase(agentSeverity)) {
logLevel = Level.WARN;
} else if ("ERROR".equalsIgnoreCase(agentSeverity)) {
logLevel = Level.ERROR;
} else if ("FATAL".equalsIgnoreCase(agentSeverity)) {
logLevel = Level.FATAL;
} else {
log.info("Unknown severity level is set: " + agentSeverity + ". Possible values are: DEBUG, INFO, WARN, ERROR, FATAL.");
}
String logPath = "./logs/ATSAgentAudit_" + agentPort + ".log";
PatternLayout layout = new PatternLayout("%d{ISO8601} - {%p} [%t] %c{2}: %x %m%n");
Logger rootLogger = Logger.getRootLogger();
FileAppender attachedAppender = null;
if (pattern != null && !pattern.trim().isEmpty()) {
pattern = pattern.trim().toLowerCase();
if ("day".equals(pattern)) {
attachedAppender = new DailyRollingFileAppender(layout, logPath, "'.'MM-dd'.log'");
} else if ("hour".equals(pattern)) {
attachedAppender = new DailyRollingFileAppender(layout, logPath, "'.'MM-dd-HH'.log'");
} else if ("minute".equals(pattern)) {
attachedAppender = new DailyRollingFileAppender(layout, logPath, "'.'MM-dd-HH-mm'.log'");
} else if (pattern.endsWith("kb") || pattern.endsWith("mb") || pattern.endsWith("gb")) {
attachedAppender = new SizeRollingFileAppender(layout, logPath, true);
((SizeRollingFileAppender) attachedAppender).setMaxFileSize(pattern);
((SizeRollingFileAppender) attachedAppender).setMaxBackupIndex(10);
} else {
System.err.println("ERROR: '" + pattern + "' is invalid pattern for log4j rolling file appender");
System.exit(1);
}
}
if (attachedAppender == null) {
attachedAppender = new FileAppender();
attachedAppender.setFile(logPath);
attachedAppender.setLayout(layout);
attachedAppender.setAppend(false);
}
attachedAppender.activateOptions();
rootLogger.setLevel(logLevel);
rootLogger.addAppender(attachedAppender);
// adding filter for Jetty messages
Logger mortbayLogger = Logger.getLogger("org.mortbay");
mortbayLogger.setAdditivity(false);
mortbayLogger.setLevel(Level.ERROR);
mortbayLogger.addAppender(attachedAppender);
}
Aggregations