use of org.apache.log4j.FileAppender in project databus by linkedin.
the class TestUtil method setupLogging.
public static void setupLogging(boolean logToConsole, String fileLogPath, Level logLevel) {
PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} [%t] (%p) {%c{1}} %m%n");
Logger.getRootLogger().removeAllAppenders();
if (logToConsole) {
ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);
Logger.getRootLogger().addAppender(defaultAppender);
}
if (null != fileLogPath && 0 < fileLogPath.length()) {
File logFile = new File(fileLogPath);
if (null != logFile.getParentFile() && !logFile.getParentFile().exists()) {
if (!logFile.getParentFile().mkdirs()) {
Logger.getRootLogger().error("unable to create parent directory for log file: " + logFile);
}
}
FileAppender fileAppender = null;
try {
fileAppender = new FileAppender(defaultLayout, fileLogPath);
} catch (IOException io) {
Logger.getRootLogger().error(io);
}
if (null != fileAppender)
Logger.getRootLogger().addAppender(fileAppender);
}
Logger.getRootLogger().setLevel(logLevel);
}
use of org.apache.log4j.FileAppender in project smscgateway by RestComm.
the class TestHarness method init.
public void init() {
try {
Properties tckProperties = new Properties();
InputStream inStreamLog4j = TestHarness.class.getResourceAsStream("/log4j.properties");
System.out.println("Input Stream = " + inStreamLog4j);
Properties propertiesLog4j = new Properties();
try {
propertiesLog4j.load(inStreamLog4j);
PropertyConfigurator.configure(propertiesLog4j);
} catch (IOException e) {
e.printStackTrace();
BasicConfigurator.configure();
}
logger.debug("log4j configured");
String lf = System.getProperties().getProperty(LOG_FILE_NAME);
if (lf != null) {
logFileName = lf;
}
// If already created a print writer then just use it.
try {
logger.addAppender(new FileAppender(new SimpleLayout(), logFileName));
} catch (FileNotFoundException fnfe) {
}
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
use of org.apache.log4j.FileAppender in project smscgateway by RestComm.
the class SMPPp method initLog4J.
private void initLog4J(Properties props) {
try {
String log4jProps = props.getProperty("smppp.log4jPropsFilePath");
if (log4jProps != null) {
InputStream inStreamLog4j = new FileInputStream(new File(log4jProps));
Properties propertiesLog4j = new Properties();
propertiesLog4j.load(inStreamLog4j);
PropertyConfigurator.configure(propertiesLog4j);
} else {
BasicConfigurator.configure();
}
String lf = props.getProperty("smppp.logFilePath");
if (lf != null) {
ctx.logger.addAppender(new FileAppender(new SimpleLayout(), lf));
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
Aggregations