Search in sources :

Example 86 with PatternLayout

use of org.apache.log4j.PatternLayout in project gerrit by GerritCodeReview.

the class ErrorLogFile method initLogSystem.

private static void initLogSystem(Path logdir, Config config, boolean consoleLog) {
    Logger root = LogManager.getRootLogger();
    root.removeAllAppenders();
    PatternLayout errorLogLayout = new PatternLayout("[%d{" + LogTimestampFormatter.TIMESTAMP_FORMAT + "}] [%t] %-5p %c %x: %m%n");
    if (consoleLog) {
        ConsoleAppender dst = new ConsoleAppender();
        dst.setLayout(errorLogLayout);
        dst.setTarget("System.err");
        dst.setThreshold(Level.INFO);
        dst.activateOptions();
        root.addAppender(dst);
    }
    boolean json = config.getBoolean("log", "jsonLogging", false);
    boolean text = config.getBoolean("log", "textLogging", true) || !(json || consoleLog);
    boolean rotate = config.getBoolean("log", "rotate", true);
    if (text) {
        root.addAppender(SystemLog.createAppender(logdir, LOG_NAME, errorLogLayout, rotate));
    }
    if (json) {
        root.addAppender(SystemLog.createAppender(logdir, LOG_NAME + JSON_SUFFIX, new ErrorLogJsonLayout(), rotate));
    }
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) PatternLayout(org.apache.log4j.PatternLayout) Logger(org.apache.log4j.Logger)

Example 87 with PatternLayout

use of org.apache.log4j.PatternLayout in project yacy_grid_mcp by yacy.

the class Data method init.

// public static Swagger swagger;
public static void init(File serviceData, Map<String, String> cc, boolean localStorage) {
    PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %p %c %x - %m%n");
    logger = Logger.getRootLogger();
    logger.removeAllAppenders();
    logAppender = new LogAppender(layout, 100000);
    logger.addAppender(logAppender);
    logger.addAppender(new ConsoleAppender(layout));
    config = cc;
    /*
        try {
            swagger = new Swagger(new File(new File(approot, "conf"), "swagger.json"));
        } catch (UnsupportedEncodingException | FileNotFoundException e) {
        }
        */
    // swagger.getServlets().forEach(path -> System.out.println(swagger.getServlet(path).toString()));
    gridServicePath = serviceData;
    if (!gridServicePath.exists())
        gridServicePath.mkdirs();
    // create databases
    File dbPath = new File(gridServicePath, "db");
    if (!dbPath.exists())
        dbPath.mkdirs();
    peerDB = new PeerDatabase(dbPath);
    peerJsonDB = new JSONDatabase(peerDB);
    // create broker
    File messagesPath = new File(gridServicePath, "messages");
    if (!messagesPath.exists())
        messagesPath.mkdirs();
    boolean lazy = config.containsKey("grid.broker.lazy") && config.get("grid.broker.lazy").equals("true");
    gridBroker = new GridBroker(lazy, localStorage ? messagesPath : null);
    // create storage
    File assetsPath = new File(gridServicePath, "assets");
    boolean deleteafterread = cc.containsKey("grid.assets.delete") && cc.get("grid.assets.delete").equals("true");
    gridStorage = new GridStorage(deleteafterread, localStorage ? assetsPath : null);
    // create index
    String elasticsearchAddress = config.getOrDefault("grid.elasticsearch.address", "");
    String elasticsearchClusterName = config.getOrDefault("grid.elasticsearch.clusterName", "");
    gridIndex = new GridIndex();
    gridIndex.connectElasticsearch(ElasticIndexFactory.PROTOCOL_PREFIX + elasticsearchAddress + "/" + elasticsearchClusterName);
    // connect outside services
    // first try to connect to the configured MCPs.
    // if that fails, try to make all connections self
    String gridMcpAddressl = config.containsKey("grid.mcp.address") ? config.get("grid.mcp.address") : "";
    String[] gridMcpAddress = gridMcpAddressl.split(",");
    boolean mcpConnected = false;
    for (String address : gridMcpAddress) {
        String host = getHost(address);
        int port = YaCyServices.mcp.getDefaultPort();
        if (address.length() > 0 && Data.gridBroker.connectMCP(host, port) && Data.gridStorage.connectMCP(host, port) && Data.gridIndex.connectMCP(host, port)) {
            Data.logger.info("Connected MCP at " + getHost(address));
            mcpConnected = true;
            break;
        }
    }
    if (!mcpConnected) {
        // try to connect to local services directly
        String[] gridBrokerAddress = (config.containsKey("grid.broker.address") ? config.get("grid.broker.address") : "").split(",");
        for (String address : gridBrokerAddress) {
            if (Data.gridBroker.connectRabbitMQ(getHost(address), getPort(address, "-1"), getUser(address, "anonymous"), getPassword(address, "yacy"))) {
                Data.logger.info("Connected Broker at " + getHost(address));
                break;
            }
        }
        if (!Data.gridBroker.isRabbitMQConnected()) {
            Data.logger.info("Connected to the embedded Broker");
        }
        String[] gridFtpAddress = (config.containsKey("grid.ftp.address") ? config.get("grid.ftp.address") : "").split(",");
        for (String address : gridFtpAddress) {
            if (address.length() > 0 && Data.gridStorage.connectFTP(getHost(address), getPort(address, "2121"), getUser(address, "anonymous"), getPassword(address, "yacy"))) {
                Data.logger.info("Connected Storage at " + getHost(address));
                break;
            }
        }
        if (!Data.gridStorage.isFTPConnected()) {
            Data.logger.info("Connected to the embedded Asset Storage");
        }
    }
    // init boosts from configuration
    Map<String, String> defaultBoosts = Service.readDoubleConfig("boost.properties");
    boostsFactory = new BoostsFactory(defaultBoosts);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) GridBroker(net.yacy.grid.io.messages.GridBroker) GridStorage(net.yacy.grid.io.assets.GridStorage) JSONDatabase(net.yacy.grid.io.db.JSONDatabase) PatternLayout(org.apache.log4j.PatternLayout) GridIndex(net.yacy.grid.io.index.GridIndex) PeerDatabase(net.yacy.grid.io.db.PeerDatabase) BoostsFactory(net.yacy.grid.io.index.BoostsFactory) File(java.io.File)

Example 88 with PatternLayout

use of org.apache.log4j.PatternLayout in project zeppelin by apache.

the class ZeppelinApplicationDevServer method setLogger.

void setLogger() {
    // create appender
    ConsoleAppender console = new ConsoleAppender();
    // configure the appender
    String PATTERN = "%d [%p|%c|%C{1}] %m%n";
    console.setLayout(new PatternLayout(PATTERN));
    console.setThreshold(Level.DEBUG);
    console.activateOptions();
    // add appender to any Logger (here is root)
    org.apache.log4j.Logger.getRootLogger().addAppender(console);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) PatternLayout(org.apache.log4j.PatternLayout)

Example 89 with PatternLayout

use of org.apache.log4j.PatternLayout in project zeppelin by apache.

the class HeliumBundleFactory method configureLogger.

private synchronized void configureLogger() {
    org.apache.log4j.Logger npmLogger = org.apache.log4j.Logger.getLogger("com.github.eirslett.maven.plugins.frontend.lib.DefaultYarnRunner");
    Enumeration appenders = org.apache.log4j.Logger.getRootLogger().getAllAppenders();
    if (appenders != null) {
        while (appenders.hasMoreElements()) {
            Appender appender = (Appender) appenders.nextElement();
            appender.addFilter(new Filter() {

                @Override
                public int decide(LoggingEvent loggingEvent) {
                    if (loggingEvent.getLoggerName().contains("DefaultYarnRunner")) {
                        return DENY;
                    } else {
                        return NEUTRAL;
                    }
                }
            });
        }
    }
    npmLogger.addAppender(new WriterAppender(new PatternLayout("%m%n"), out));
}
Also used : Appender(org.apache.log4j.Appender) WriterAppender(org.apache.log4j.WriterAppender) LoggingEvent(org.apache.log4j.spi.LoggingEvent) Enumeration(java.util.Enumeration) FilenameFilter(java.io.FilenameFilter) Filter(org.apache.log4j.spi.Filter) FileFilter(java.io.FileFilter) PatternLayout(org.apache.log4j.PatternLayout) WriterAppender(org.apache.log4j.WriterAppender)

Example 90 with PatternLayout

use of org.apache.log4j.PatternLayout in project SSM by Intel-bigdata.

the class HeliumVisualizationFactory method configureLogger.

private void configureLogger() {
    org.apache.log4j.Logger npmLogger = org.apache.log4j.Logger.getLogger("com.github.eirslett.maven.plugins.frontend.lib.DefaultNpmRunner");
    Enumeration appenders = org.apache.log4j.Logger.getRootLogger().getAllAppenders();
    if (appenders != null) {
        while (appenders.hasMoreElements()) {
            Appender appender = (Appender) appenders.nextElement();
            appender.addFilter(new Filter() {

                @Override
                public int decide(LoggingEvent loggingEvent) {
                    if (loggingEvent.getLoggerName().contains("DefaultNpmRunner")) {
                        return DENY;
                    } else {
                        return NEUTRAL;
                    }
                }
            });
        }
    }
    npmLogger.addAppender(new WriterAppender(new PatternLayout("%m%n"), out));
}
Also used : Appender(org.apache.log4j.Appender) WriterAppender(org.apache.log4j.WriterAppender) LoggingEvent(org.apache.log4j.spi.LoggingEvent) Filter(org.apache.log4j.spi.Filter) PatternLayout(org.apache.log4j.PatternLayout) WriterAppender(org.apache.log4j.WriterAppender)

Aggregations

PatternLayout (org.apache.log4j.PatternLayout)101 ConsoleAppender (org.apache.log4j.ConsoleAppender)51 Logger (org.apache.log4j.Logger)27 IOException (java.io.IOException)21 Appender (org.apache.log4j.Appender)18 FileAppender (org.apache.log4j.FileAppender)17 Layout (org.apache.log4j.Layout)15 File (java.io.File)14 RollingFileAppender (org.apache.log4j.RollingFileAppender)12 Test (org.junit.Test)8 CommandLineParser (org.apache.commons.cli.CommandLineParser)7 GnuParser (org.apache.commons.cli.GnuParser)7 ParseException (org.apache.commons.cli.ParseException)7 FileInputStream (java.io.FileInputStream)6 Properties (java.util.Properties)6 CommandLine (org.apache.commons.cli.CommandLine)6 Option (org.apache.commons.cli.Option)6 Options (org.apache.commons.cli.Options)6 DailyRollingFileAppender (org.apache.log4j.DailyRollingFileAppender)6 WriterAppender (org.apache.log4j.WriterAppender)6