Search in sources :

Example 21 with PatternLayout

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

the class Log4JLogger method createConsoleAppender.

/**
 * Creates console appender with some reasonable default logging settings.
 *
 * @param maxLevel Max logging level.
 * @return New console appender.
 */
private Appender createConsoleAppender(Level maxLevel) {
    String fmt = "[%d{ISO8601}][%-5p][%t][%c{1}] %m%n";
    // Configure output that should go to System.out
    Appender app = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
    LevelRangeFilter lvlFilter = new LevelRangeFilter();
    lvlFilter.setLevelMin(Level.TRACE);
    lvlFilter.setLevelMax(maxLevel);
    app.addFilter(lvlFilter);
    return app;
}
Also used : Appender(org.apache.log4j.Appender) ConsoleAppender(org.apache.log4j.ConsoleAppender) FileAppender(org.apache.log4j.FileAppender) ConsoleAppender(org.apache.log4j.ConsoleAppender) PatternLayout(org.apache.log4j.PatternLayout) LevelRangeFilter(org.apache.log4j.varia.LevelRangeFilter)

Example 22 with PatternLayout

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

the class GridLog4jCorrectFileNameTest method createAppender.

/**
 * Creates new GridLog4jRollingFileAppender.
 *
 * @return GridLog4jRollingFileAppender.
 * @throws Exception If error occurred.
 */
private static Log4jRollingFileAppender createAppender() throws Exception {
    Log4jRollingFileAppender appender = new Log4jRollingFileAppender();
    appender.setLayout(new PatternLayout("[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"));
    appender.setFile("work/log/ignite.log");
    appender.setName(Log4jRollingFileAppender.class.getSimpleName());
    LevelRangeFilter lvlFilter = new LevelRangeFilter();
    lvlFilter.setLevelMin(Level.DEBUG);
    lvlFilter.setLevelMax(Level.INFO);
    appender.addFilter(lvlFilter);
    return appender;
}
Also used : PatternLayout(org.apache.log4j.PatternLayout) LevelRangeFilter(org.apache.log4j.varia.LevelRangeFilter)

Example 23 with PatternLayout

use of org.apache.log4j.PatternLayout in project Lucee by lucee.

the class Log4jUtil method getLayout.

public static final Layout getLayout(ClassDefinition cd, Map<String, String> layoutArgs) {
    if (layoutArgs == null)
        layoutArgs = new HashMap<String, String>();
    // Layout
    Layout layout = null;
    if (cd != null && cd.hasClass()) {
        // Classic Layout
        if (ClassicLayout.class.getName().equalsIgnoreCase(cd.getClassName()))
            layout = new ClassicLayout();
        else // HTML Layout
        if (HTMLLayout.class.getName().equalsIgnoreCase(cd.getClassName())) {
            HTMLLayout html = new HTMLLayout();
            layout = html;
            // Location Info
            Boolean locInfo = Caster.toBoolean(layoutArgs.get("locationinfo"), null);
            if (locInfo != null)
                html.setLocationInfo(locInfo.booleanValue());
            else
                locInfo = Boolean.FALSE;
            layoutArgs.put("locationinfo", locInfo.toString());
            // Title
            String title = Caster.toString(layoutArgs.get("title"), "");
            if (!StringUtil.isEmpty(title, true))
                html.setTitle(title);
            layoutArgs.put("title", title);
        } else // XML Layout
        if (XMLLayout.class.getName().equalsIgnoreCase(cd.getClassName())) {
            XMLLayout xml = new XMLLayout();
            layout = xml;
            // Location Info
            Boolean locInfo = Caster.toBoolean(layoutArgs.get("locationinfo"), null);
            if (locInfo != null)
                xml.setLocationInfo(locInfo.booleanValue());
            else
                locInfo = Boolean.FALSE;
            layoutArgs.put("locationinfo", locInfo.toString());
            // Properties
            Boolean props = Caster.toBoolean(layoutArgs.get("properties"), null);
            if (props != null)
                xml.setProperties(props.booleanValue());
            else
                props = Boolean.FALSE;
            layoutArgs.put("properties", props.toString());
        } else // Pattern Layout
        if (PatternLayout.class.getName().equalsIgnoreCase(cd.getClassName())) {
            PatternLayout patt = new PatternLayout();
            layout = patt;
            // pattern
            String pattern = Caster.toString(layoutArgs.get("pattern"), null);
            if (!StringUtil.isEmpty(pattern, true))
                patt.setConversionPattern(pattern);
            else {
                patt.setConversionPattern(DEFAULT_PATTERN);
                layoutArgs.put("pattern", DEFAULT_PATTERN);
            }
        } else // class defintion
        {
            Object obj = ClassUtil.loadInstance(cd.getClazz(null), null, null);
            if (obj instanceof Layout) {
                layout = (Layout) obj;
                Iterator<Entry<String, String>> it = layoutArgs.entrySet().iterator();
                Entry<String, String> e;
                while (it.hasNext()) {
                    e = it.next();
                    try {
                        Reflector.callSetter(obj, e.getKey(), e.getValue());
                    } catch (PageException e1) {
                        // TODO log
                        SystemOut.printDate(e1);
                    }
                }
            }
        }
    }
    if (layout != null)
        return layout;
    return new ClassicLayout();
}
Also used : PageException(lucee.runtime.exp.PageException) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) HTMLLayout(org.apache.log4j.HTMLLayout) ClassicLayout(lucee.commons.io.log.log4j.layout.ClassicLayout) XMLLayout(org.apache.log4j.xml.XMLLayout) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout) HTMLLayout(org.apache.log4j.HTMLLayout) PatternLayout(org.apache.log4j.PatternLayout) ClassicLayout(lucee.commons.io.log.log4j.layout.ClassicLayout) Iterator(java.util.Iterator) XMLLayout(org.apache.log4j.xml.XMLLayout)

Example 24 with PatternLayout

use of org.apache.log4j.PatternLayout in project janusgraph by JanusGraph.

the class HBaseStoreManagerConfigTest method testShortCfNames.

@Test
public void testShortCfNames() throws Exception {
    Logger log = Logger.getLogger(HBaseStoreManager.class);
    Level savedLevel = log.getLevel();
    log.setLevel(Level.WARN);
    StringWriter writer = new StringWriter();
    Appender appender = new WriterAppender(new PatternLayout("%p: %m%n"), writer);
    log.addAppender(appender);
    // Open the HBaseStoreManager and store with default SHORT_CF_NAMES true.
    WriteConfiguration config = HBaseStorageSetup.getHBaseGraphConfiguration();
    HBaseStoreManager manager = new HBaseStoreManager(new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE));
    KeyColumnValueStore store = manager.openDatabase(GraphDatabaseConfiguration.SYSTEM_PROPERTIES_STORE_NAME);
    store.close();
    manager.close();
    // Open the HBaseStoreManager and store with SHORT_CF_NAMES false.
    config.set(ConfigElement.getPath(HBaseStoreManager.SHORT_CF_NAMES), false);
    manager = new HBaseStoreManager(new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE));
    writer.getBuffer().setLength(0);
    store = manager.openDatabase(GraphDatabaseConfiguration.SYSTEM_PROPERTIES_STORE_NAME);
    // Verify we get WARN.
    assertTrue(writer.toString(), writer.toString().startsWith("WARN: Configuration"));
    log.removeAppender(appender);
    log.setLevel(savedLevel);
    store.close();
    manager.close();
}
Also used : Appender(org.apache.log4j.Appender) WriterAppender(org.apache.log4j.WriterAppender) StringWriter(java.io.StringWriter) KeyColumnValueStore(org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore) PatternLayout(org.apache.log4j.PatternLayout) Level(org.apache.log4j.Level) WriterAppender(org.apache.log4j.WriterAppender) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) Logger(org.apache.log4j.Logger) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) Test(org.junit.Test)

Example 25 with PatternLayout

use of org.apache.log4j.PatternLayout in project scheduling by ow2-proactive.

the class RMNodeUpdater method initLogger.

private static Logger initLogger() {
    if (System.getProperty("log4j.configuration") == null) {
        // While logger is not configured and it not set with sys properties, use Console logger
        Logger.getRootLogger().getLoggerRepository().resetConfiguration();
        BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%m%n")));
        Logger.getRootLogger().setLevel(Level.INFO);
    }
    return Logger.getLogger(RMNodeUpdater.class);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) PatternLayout(org.apache.log4j.PatternLayout)

Aggregations

PatternLayout (org.apache.log4j.PatternLayout)106 ConsoleAppender (org.apache.log4j.ConsoleAppender)49 Logger (org.apache.log4j.Logger)30 IOException (java.io.IOException)20 Appender (org.apache.log4j.Appender)20 FileAppender (org.apache.log4j.FileAppender)17 File (java.io.File)14 Layout (org.apache.log4j.Layout)14 RollingFileAppender (org.apache.log4j.RollingFileAppender)12 Test (org.junit.Test)12 WriterAppender (org.apache.log4j.WriterAppender)9 CommandLineParser (org.apache.commons.cli.CommandLineParser)7 GnuParser (org.apache.commons.cli.GnuParser)7 ParseException (org.apache.commons.cli.ParseException)7 DailyRollingFileAppender (org.apache.log4j.DailyRollingFileAppender)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