use of org.apache.log4j.Appender in project honeycomb by altamiracorp.
the class Bootstrap method ensureLoggingPathsCorrect.
private static void ensureLoggingPathsCorrect() {
Enumeration<?> allAppenders = Logger.getRootLogger().getAllAppenders();
while (allAppenders.hasMoreElements()) {
Appender appender = (Appender) allAppenders.nextElement();
if (appender instanceof FileAppender) {
FileAppender fileAppender = (FileAppender) appender;
String file = fileAppender.getFile();
if (file == null) {
continue;
}
File f = new File(file);
System.err.println("Testing: " + f.getName());
if (f.exists()) {
if (!f.canWrite()) {
System.err.println("Cannot write to " + f.getName());
}
} else {
String createFailure = "Could not create logging file " + f.getName();
try {
if (!f.createNewFile()) {
System.err.println(createFailure);
throw new RuntimeException(createFailure);
}
} catch (IOException e) {
System.err.println(createFailure);
throw new RuntimeException(createFailure, e);
}
}
}
}
}
use of org.apache.log4j.Appender in project databus by linkedin.
the class TestFilterToSQL method setUp.
@BeforeClass
public void setUp() throws IOException, DatabusException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
Logger.getRootLogger().removeAllAppenders();
Appender defApp = new ConsoleAppender(new SimpleLayout());
Logger.getRootLogger().addAppender(defApp);
Logger.getRootLogger().setLevel(Level.INFO);
BootstrapServerConfig configBuilder = new BootstrapServerConfig();
BootstrapServerStaticConfig staticConfig = configBuilder.build();
processor = new BootstrapProcessor(staticConfig, null);
partConf = new KeyFilterConfigHolder.Config();
}
use of org.apache.log4j.Appender in project gocd by gocd.
the class AgentConsoleLogThread method run.
public void run() {
BufferedReader reader = new BufferedReader(new InputStreamReader(consoleError));
Appender consoleFileAppender = LoggingHelper.createConsoleFileAppender(ndc, consoleFileName);
Logger.getRootLogger().addAppender(consoleFileAppender);
NDC.push(ndc.toString());
while (true) {
if (!keepRunning && flushedAfterStop) {
break;
}
try {
logConsoleError(reader);
Thread.sleep(1000);
} catch (Exception e) {
LOG.error("Error occured while capturing console output from agent process: ", e);
break;
}
}
NDC.pop();
Logger.getRootLogger().removeAppender(consoleFileAppender);
}
use of org.apache.log4j.Appender in project gocd by gocd.
the class FileLocationProvider method asJson.
@Override
public Map<String, Object> asJson() {
LinkedHashMap<String, Object> json = new LinkedHashMap<>();
json.put("loc.config.dir", systemEnvironment.configDir().getAbsolutePath());
List<Logger> loggers = new ArrayList<>();
Logger rootLogger = Logger.getRootLogger();
loggers.add(rootLogger);
Enumeration currentLoggers = rootLogger.getLoggerRepository().getCurrentLoggers();
while (currentLoggers.hasMoreElements()) {
loggers.add((Logger) currentLoggers.nextElement());
}
int index = 0;
for (Logger logger : loggers) {
Enumeration appenders = logger.getAllAppenders();
while (appenders.hasMoreElements()) {
Appender appender = (Appender) appenders.nextElement();
if (!isFileAppender(appender)) {
continue;
}
FileAppender fileAppender = (FileAppender) appender;
File logFile = new File(fileAppender.getFile());
json.put("loc.log.root." + index, new File(logFile.getAbsolutePath()).getParent());
json.put("loc.log.basename." + index, logFile.getName());
++index;
}
}
return json;
}
use of org.apache.log4j.Appender in project symmetric-ds by JumpMind.
the class AbstractCommandLauncher method configureLogging.
protected void configureLogging(CommandLine line) throws MalformedURLException {
/* Optionally remove existing handlers attached to j.u.l root logger */
SLF4JBridgeHandler.removeHandlersForRootLogger();
/*
* Add SLF4JBridgeHandler to j.u.l's root logger, should be done once
* during the initialization phase of your application
*/
SLF4JBridgeHandler.install();
URL log4jUrl = new URL(System.getProperty("log4j.configuration", "file:" + AppUtils.getSymHome() + "/conf/log4j-blank.xml"));
File log4jFile = new File(new File(log4jUrl.getFile()).getParent(), "log4j.xml");
if (line.hasOption(OPTION_DEBUG)) {
log4jFile = new File(log4jFile.getParent(), "log4j-debug.xml");
}
if (log4jFile.exists()) {
DOMConfigurator.configure(log4jFile.getAbsolutePath());
}
if (line.hasOption(OPTION_VERBOSE_CONSOLE)) {
Appender consoleAppender = org.apache.log4j.Logger.getRootLogger().getAppender("CONSOLE");
if (consoleAppender != null) {
Layout layout = consoleAppender.getLayout();
if (layout instanceof PatternLayout) {
((PatternLayout) layout).setConversionPattern("%d %-5p [%c{2}] [%t] %m%n");
}
}
}
if (line.hasOption(OPTION_NO_LOG_CONSOLE)) {
org.apache.log4j.Logger.getRootLogger().removeAppender("CONSOLE");
}
if (line.hasOption(OPTION_NO_LOG_FILE)) {
org.apache.log4j.Logger.getRootLogger().removeAppender("ROLLING");
} else {
Appender appender = org.apache.log4j.Logger.getRootLogger().getAppender("ROLLING");
if (appender instanceof FileAppender) {
FileAppender fileAppender = (FileAppender) appender;
if (line.hasOption(OPTION_PROPERTIES_FILE)) {
File file = new File(line.getOptionValue(OPTION_PROPERTIES_FILE));
String name = file.getName();
int index = name.lastIndexOf(".");
if (index > 0) {
name = name.substring(0, index);
}
fileAppender.setFile(fileAppender.getFile().replace("symmetric.log", name + ".log"));
fileAppender.activateOptions();
}
System.err.println(String.format("Log output will be written to %s", fileAppender.getFile()));
}
}
}
Aggregations