use of org.apache.log4j.ConsoleAppender in project databus by linkedin.
the class CheckpointSerializerMain method main.
public static void main(String[] args) throws Exception {
parseArgs(args);
PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c{1}} %m%n");
ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);
Logger.getRootLogger().removeAllAppenders();
Logger.getRootLogger().addAppender(defaultAppender);
Logger.getRootLogger().setLevel(Level.INFO);
Logger.getRootLogger().info("NOTE. This tool works only with V2/V1 checkpoints");
CheckpointPersistenceProvider cp3 = null;
if (null != _cp3Props) {
CheckpointPersistenceStaticConfigBuilder cp3ConfBuilder = new CheckpointPersistenceStaticConfigBuilder();
ConfigLoader<CheckpointPersistenceStaticConfig> configLoader = new ConfigLoader<DatabusHttpClientImpl.CheckpointPersistenceStaticConfig>(_propPrefix, cp3ConfBuilder);
configLoader.loadConfig(_cp3Props);
CheckpointPersistenceStaticConfig cp3Conf = cp3ConfBuilder.build();
if (cp3Conf.getType() != CheckpointPersistenceStaticConfig.ProviderType.FILE_SYSTEM) {
throw new RuntimeException("don't know what to do with cp3 type:" + cp3Conf.getType());
}
cp3 = new FileSystemCheckpointPersistenceProvider(cp3Conf.getFileSystem(), 2);
} else if (null != _clientProps) {
DatabusHttpClientImpl.Config clientConfBuilder = new DatabusHttpClientImpl.Config();
ConfigLoader<DatabusHttpClientImpl.StaticConfig> configLoader = new ConfigLoader<DatabusHttpClientImpl.StaticConfig>(_propPrefix, clientConfBuilder);
configLoader.loadConfig(_clientProps);
DatabusHttpClientImpl.StaticConfig clientConf = clientConfBuilder.build();
if (clientConf.getCheckpointPersistence().getType() != CheckpointPersistenceStaticConfig.ProviderType.FILE_SYSTEM) {
throw new RuntimeException("don't know what to do with cp3 type:" + clientConf.getCheckpointPersistence().getType());
}
cp3 = new FileSystemCheckpointPersistenceProvider(clientConf.getCheckpointPersistence().getFileSystem(), 2);
}
List<String> sourceList = Arrays.asList(_sources);
Checkpoint cpOld = null != cp3 ? cp3.loadCheckpoint(sourceList) : new Checkpoint();
Checkpoint cpNew;
if (Action.PRINT == _action) {
cpNew = updateCheckpoint(cpOld);
} else if (Action.CHANGE == _action) {
cpNew = updateCheckpoint(cpOld);
cp3.storeCheckpoint(sourceList, cpNew);
//reread as a sanity check
cpNew = cp3.loadCheckpoint(sourceList);
} else if (Action.DELETE == _action) {
cp3.removeCheckpoint(sourceList);
cpNew = cp3.loadCheckpoint(sourceList);
} else {
throw new RuntimeException("don't know what to do with action: " + _action);
}
if (null != cpOld)
System.out.println("old: " + cpOld.toString());
else
System.out.println("old: null");
if (null != cpNew)
System.out.println("new: " + cpNew.toString());
else
System.out.println("new: null");
}
use of org.apache.log4j.ConsoleAppender in project gocd by gocd.
the class BootstrapperLoggingHelper method setupDefaultLog4j.
private static void setupDefaultLog4j() {
String logFile = System.getenv("LOG_FILE");
System.out.println("logFile Environment Variable= " + logFile);
try {
if (logFile == null) {
logFile = "go-agent-bootstrapper.log";
}
System.out.println("Logging to " + logFile);
BasicConfigurator.configure(new FileAppender(LOG4J_PATTERN, logFile));
Logger.getRootLogger().setLevel(Level.INFO);
} catch (IOException e) {
BasicConfigurator.configure(new ConsoleAppender(LOG4J_PATTERN));
Logger.getRootLogger().setLevel(Level.INFO);
Log LOG = LogFactory.getLog(BootstrapperLoggingHelper.class);
LOG.warn("Unable to initialize log4j file-appender: " + logFile, e);
LOG.warn("Using console-appender instead");
}
}
use of org.apache.log4j.ConsoleAppender 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) {
sLogger.fatal("Unable to configure logging, reason: " + e.getMessage(), e);
}
}
if (!debug)
root.setLevel(Level.INFO);
}
use of org.apache.log4j.ConsoleAppender in project cpsolver by UniTime.
the class Test method setupLogging.
/**
* Setup log4j logging
*
* @param logFile log file
*/
public static void setupLogging(File logFile) {
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);
}
}
}
use of org.apache.log4j.ConsoleAppender in project zm-mailbox by Zimbra.
the class PlaybackUtil method setup.
private static void setup() throws ServiceException {
// set up log4j
ZimbraLog.toolSetupLog4j("INFO", LC.zimbra_log4j_properties.value());
// remove the console appender if any
Logger rootLogger = Logger.getRootLogger();
Appender consoleAppender = null;
Enumeration appenders = rootLogger.getAllAppenders();
while (appenders.hasMoreElements()) {
Appender appender = (Appender) appenders.nextElement();
if (appender instanceof ConsoleAppender) {
consoleAppender = appender;
}
}
if (consoleAppender != null)
rootLogger.removeAppender(consoleAppender);
DbPool.startup();
Zimbra.startupCLI();
}
Aggregations