Search in sources :

Example 6 with ConsoleAppender

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");
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) CheckpointPersistenceStaticConfigBuilder(com.linkedin.databus.client.DatabusHttpClientImpl.CheckpointPersistenceStaticConfigBuilder) ConfigLoader(com.linkedin.databus.core.util.ConfigLoader) CheckpointPersistenceStaticConfig(com.linkedin.databus.client.DatabusHttpClientImpl.CheckpointPersistenceStaticConfig) PatternLayout(org.apache.log4j.PatternLayout) CheckpointPersistenceStaticConfig(com.linkedin.databus.client.DatabusHttpClientImpl.CheckpointPersistenceStaticConfig) DatabusHttpClientImpl(com.linkedin.databus.client.DatabusHttpClientImpl) FileSystemCheckpointPersistenceProvider(com.linkedin.databus.client.pub.FileSystemCheckpointPersistenceProvider) CheckpointPersistenceProvider(com.linkedin.databus.client.pub.CheckpointPersistenceProvider) Checkpoint(com.linkedin.databus.core.Checkpoint) DatabusRuntimeException(com.linkedin.databus.core.DatabusRuntimeException) FileSystemCheckpointPersistenceProvider(com.linkedin.databus.client.pub.FileSystemCheckpointPersistenceProvider) CheckpointPersistenceStaticConfig(com.linkedin.databus.client.DatabusHttpClientImpl.CheckpointPersistenceStaticConfig)

Example 7 with ConsoleAppender

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");
    }
}
Also used : FileAppender(org.apache.log4j.FileAppender) ConsoleAppender(org.apache.log4j.ConsoleAppender) Log(org.apache.commons.logging.Log) IOException(java.io.IOException)

Example 8 with ConsoleAppender

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);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) FileAppender(org.apache.log4j.FileAppender) PatternLayout(org.apache.log4j.PatternLayout) IOException(java.io.IOException) Logger(org.apache.log4j.Logger)

Example 9 with ConsoleAppender

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);
        }
    }
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) FileAppender(org.apache.log4j.FileAppender) PatternLayout(org.apache.log4j.PatternLayout) IOException(java.io.IOException) Logger(org.apache.log4j.Logger)

Example 10 with ConsoleAppender

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();
}
Also used : Appender(org.apache.log4j.Appender) ConsoleAppender(org.apache.log4j.ConsoleAppender) ConsoleAppender(org.apache.log4j.ConsoleAppender) Enumeration(java.util.Enumeration) Logger(org.apache.log4j.Logger)

Aggregations

ConsoleAppender (org.apache.log4j.ConsoleAppender)32 PatternLayout (org.apache.log4j.PatternLayout)23 ParseException (org.apache.commons.cli.ParseException)9 FileAppender (org.apache.log4j.FileAppender)9 Logger (org.apache.log4j.Logger)9 IOException (java.io.IOException)8 CommandLineParser (org.apache.commons.cli.CommandLineParser)8 Appender (org.apache.log4j.Appender)8 FileInputStream (java.io.FileInputStream)7 CommandLine (org.apache.commons.cli.CommandLine)7 GnuParser (org.apache.commons.cli.GnuParser)7 Options (org.apache.commons.cli.Options)7 Properties (java.util.Properties)6 Option (org.apache.commons.cli.Option)6 Enumeration (java.util.Enumeration)4 LevelRangeFilter (org.apache.log4j.varia.LevelRangeFilter)4 IgniteLogger (org.apache.ignite.IgniteLogger)3 GridTestLog4jLogger (org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)3 RollingFileAppender (org.apache.log4j.RollingFileAppender)3 ConfigLoader (com.linkedin.databus.core.util.ConfigLoader)2