Search in sources :

Example 76 with PatternLayout

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

the class CombinerTest method runDeleteHandlingTest.

private void runDeleteHandlingTest(TreeMap<Key, Value> input, TreeMap<Key, Value> expected, Boolean rofco, IteratorEnvironment env, String expectedLog, boolean clearLogMsgCache) throws Exception {
    boolean deepCopy = expected == null;
    if (clearLogMsgCache) {
        CombinerTestUtil.clearLogCache();
    }
    StringWriter writer = new StringWriter();
    WriterAppender appender = new WriterAppender(new PatternLayout("%p, %m%n"), writer);
    Logger logger = Logger.getLogger(Combiner.class);
    boolean additivity = logger.getAdditivity();
    try {
        logger.addAppender(appender);
        logger.setAdditivity(false);
        Combiner ai = new SummingCombiner();
        IteratorSetting is = new IteratorSetting(1, SummingCombiner.class);
        SummingCombiner.setEncodingType(is, LongCombiner.StringEncoder.class);
        Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
        if (rofco != null) {
            Combiner.setReduceOnFullCompactionOnly(is, rofco);
        }
        ai.init(new SortedMapIterator(input), is.getOptions(), env);
        if (deepCopy)
            assertEquals(expected, readAll(ai.deepCopy(env)));
        assertEquals(expected, readAll(ai));
    } finally {
        logger.removeAppender(appender);
        logger.setAdditivity(additivity);
    }
    String logMsgs = writer.toString();
    if (expectedLog == null) {
        Assert.assertTrue("Expected 0 length log message, but got : " + logMsgs, logMsgs.length() == 0);
    } else {
        logMsgs = logMsgs.replace('\n', ' ');
        Assert.assertTrue("Did not match pattern [" + expectedLog + "] in [" + logMsgs + "]", logMsgs.matches(expectedLog));
    }
}
Also used : StringWriter(java.io.StringWriter) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) PatternLayout(org.apache.log4j.PatternLayout) LongCombiner(org.apache.accumulo.core.iterators.LongCombiner) LongCombiner(org.apache.accumulo.core.iterators.LongCombiner) TypedValueCombiner(org.apache.accumulo.core.iterators.TypedValueCombiner) Combiner(org.apache.accumulo.core.iterators.Combiner) WriterAppender(org.apache.log4j.WriterAppender) Logger(org.apache.log4j.Logger) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator)

Example 77 with PatternLayout

use of org.apache.log4j.PatternLayout in project lvm4j by dirmeier.

the class TestSuite method setup.

@BeforeClass
public static void setup() {
    ConsoleAppender appender = new ConsoleAppender();
    appender.setWriter(new OutputStreamWriter(java.lang.System.out));
    appender.setLayout(new PatternLayout("%-5p [%t]: %m%n"));
    Logger.getRootLogger().addAppender(appender);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) PatternLayout(org.apache.log4j.PatternLayout) OutputStreamWriter(java.io.OutputStreamWriter) BeforeClass(org.junit.BeforeClass)

Example 78 with PatternLayout

use of org.apache.log4j.PatternLayout in project wring by yegor256.

the class Exec method log.

/**
 * Push and collect logs.
 * @return Logs
 * @throws IOException If fails
 */
private String log() throws IOException {
    final org.apache.log4j.Logger root = org.apache.log4j.Logger.getRootLogger();
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final Appender appender = new ThreadAppender(new PatternLayout("%t %p %m\n"), baos);
    root.addAppender(appender);
    try {
        this.pipe.status(this.agent.push(this.events));
        return baos.toString();
    } finally {
        root.removeAppender(appender);
    }
}
Also used : Appender(org.apache.log4j.Appender) PatternLayout(org.apache.log4j.PatternLayout) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 79 with PatternLayout

use of org.apache.log4j.PatternLayout in project presto by prestodb.

the class AccumuloModule method configure.

@Override
public void configure(Binder binder) {
    // Add appender to Log4J root logger
    // create appender
    JulAppender appender = new JulAppender();
    appender.setLayout(new PatternLayout("%d %-5p %c - %m%n"));
    appender.setThreshold(Level.INFO);
    appender.activateOptions();
    org.apache.log4j.Logger.getRootLogger().addAppender(appender);
    binder.bind(TypeManager.class).toInstance(typeManager);
    binder.bind(AccumuloConnector.class).in(Scopes.SINGLETON);
    binder.bind(AccumuloConnectorId.class).toInstance(new AccumuloConnectorId(connectorId));
    binder.bind(AccumuloMetadata.class).in(Scopes.SINGLETON);
    binder.bind(AccumuloMetadataFactory.class).in(Scopes.SINGLETON);
    binder.bind(AccumuloClient.class).in(Scopes.SINGLETON);
    binder.bind(AccumuloSplitManager.class).in(Scopes.SINGLETON);
    binder.bind(AccumuloRecordSetProvider.class).in(Scopes.SINGLETON);
    binder.bind(AccumuloPageSinkProvider.class).in(Scopes.SINGLETON);
    binder.bind(AccumuloHandleResolver.class).in(Scopes.SINGLETON);
    binder.bind(AccumuloSessionProperties.class).in(Scopes.SINGLETON);
    binder.bind(AccumuloTableProperties.class).in(Scopes.SINGLETON);
    binder.bind(ZooKeeperMetadataManager.class).in(Scopes.SINGLETON);
    binder.bind(AccumuloTableManager.class).in(Scopes.SINGLETON);
    binder.bind(IndexLookup.class).in(Scopes.SINGLETON);
    binder.bind(ColumnCardinalityCache.class).in(Scopes.SINGLETON);
    binder.bind(Connector.class).toProvider(ConnectorProvider.class);
    configBinder(binder).bindConfig(AccumuloConfig.class);
    jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class);
    jsonCodecBinder(binder).bindMapJsonCodec(String.class, JsonCodec.listJsonCodec(AccumuloTable.class));
}
Also used : Connector(org.apache.accumulo.core.client.Connector) ColumnCardinalityCache(com.facebook.presto.accumulo.index.ColumnCardinalityCache) PatternLayout(org.apache.log4j.PatternLayout) AccumuloTableProperties(com.facebook.presto.accumulo.conf.AccumuloTableProperties) IndexLookup(com.facebook.presto.accumulo.index.IndexLookup) AccumuloTable(com.facebook.presto.accumulo.metadata.AccumuloTable) AccumuloPageSinkProvider(com.facebook.presto.accumulo.io.AccumuloPageSinkProvider) Type(com.facebook.presto.common.type.Type) AccumuloSessionProperties(com.facebook.presto.accumulo.conf.AccumuloSessionProperties) ZooKeeperMetadataManager(com.facebook.presto.accumulo.metadata.ZooKeeperMetadataManager) TypeManager(com.facebook.presto.common.type.TypeManager) JulAppender(org.apache.log4j.JulAppender) AccumuloRecordSetProvider(com.facebook.presto.accumulo.io.AccumuloRecordSetProvider)

Example 80 with PatternLayout

use of org.apache.log4j.PatternLayout in project apex-core by apache.

the class LogFileInformationTest method beforeClass.

@BeforeClass
public static void beforeClass() throws IOException {
    String logFileDir = new File("target" + File.separator + "logDir").getAbsolutePath();
    logFileName = logFileDir + File.separator + "appTest.log";
    RollingFileAppender rfa = new RollingFileAppender(new PatternLayout("%d{ISO8601} [%t] %-5p %c{2} %M - %m%n"), logFileName);
    rfa.setName(APPENDER_NAME);
    logger.addAppender(rfa);
}
Also used : RollingFileAppender(org.apache.log4j.RollingFileAppender) PatternLayout(org.apache.log4j.PatternLayout) File(java.io.File) BeforeClass(org.junit.BeforeClass)

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