Search in sources :

Example 51 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project logging-log4j2 by apache.

the class ConsoleAppenderAnsiStyleJira180Main method main.

public static void main(final String[] args) {
    // System.out.println(System.getProperty("java.class.path"));
    final String config = args.length == 0 ? "target/test-classes/log4j2-180.xml" : args[0];
    try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config)) {
        LOG.fatal("Fatal message.");
        LOG.error("Error message.");
        LOG.warn("Warning message.");
        LOG.info("Information message.");
        LOG.debug("Debug message.");
        LOG.trace("Trace message.");
        try {
            throw new NullPointerException();
        } catch (final Exception e) {
            LOG.error("Error message.", e);
            LOG.catching(Level.ERROR, e);
        }
    }
}
Also used : LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 52 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project logging-log4j2 by apache.

the class ConsoleAppenderAnsiStyleJira319Main method main.

public static void main(final String[] args) {
    // System.out.println(System.getProperty("java.class.path"));
    final String config = args.length == 0 ? "target/test-classes/log4j2-319.xml" : args[0];
    try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config)) {
        LOG.fatal("Fatal message.");
        LOG.error("Error message.");
        LOG.warn("Warning message.");
        LOG.info("Information message.");
        LOG.debug("Debug message.");
        LOG.trace("Trace message.");
        try {
            throw new NullPointerException();
        } catch (final Exception e) {
            LOG.error("Error message.", e);
            LOG.catching(Level.ERROR, e);
        }
        LOG.warn("this is ok \n And all \n this have only\t\tblack colour \n and here is colour again?");
        LOG.info("Information message.");
    }
}
Also used : LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 53 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project logging-log4j2 by apache.

the class ConsoleAppenderAnsiStyleNameLayoutMain method main.

public static void main(final String[] args) {
    try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), "target/test-classes/log4j2-console-style-name-ansi.xml")) {
        LOG.fatal("Fatal message.");
        LOG.error("Error message.");
        LOG.warn("Warning message.");
        LOG.info("Information message.");
        LOG.debug("Debug message.");
        LOG.trace("Trace message.");
        LOG.error("Error message.", new IOException("test"));
    }
}
Also used : IOException(java.io.IOException) LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 54 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project logging-log4j2 by apache.

the class XmlConfigurationPropsTest method testDefaultStatus.

@Test
public void testDefaultStatus() {
    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG1);
    System.setProperty(Constants.LOG4J_DEFAULT_STATUS_LEVEL, "WARN");
    try {
        final LoggerContext ctx = LoggerContext.getContext();
        ctx.reconfigure();
        final Configuration config = ctx.getConfiguration();
        assertTrue("Configuration is not an XmlConfiguration", config instanceof XmlConfiguration);
    } finally {
        System.clearProperty(Constants.LOG4J_DEFAULT_STATUS_LEVEL);
    }
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) LoggerContext(org.apache.logging.log4j.core.LoggerContext) Test(org.junit.Test)

Example 55 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project logging-log4j2 by apache.

the class XmlConfigurationPropsTest method cleanupClass.

@AfterClass
public static void cleanupClass() {
    System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
    final LoggerContext ctx = LoggerContext.getContext();
    ctx.reconfigure();
    StatusLogger.getLogger().reset();
}
Also used : LoggerContext(org.apache.logging.log4j.core.LoggerContext) AfterClass(org.junit.AfterClass)

Aggregations

LoggerContext (org.apache.logging.log4j.core.LoggerContext)163 Configuration (org.apache.logging.log4j.core.config.Configuration)57 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)36 Test (org.junit.Test)33 Appender (org.apache.logging.log4j.core.Appender)18 File (java.io.File)12 IOException (java.io.IOException)12 Logger (org.apache.logging.log4j.Logger)11 BeforeClass (org.junit.BeforeClass)11 Map (java.util.Map)10 Level (org.apache.logging.log4j.Level)8 LogEvent (org.apache.logging.log4j.core.LogEvent)8 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)7 PatternLayout (org.apache.logging.log4j.core.layout.PatternLayout)7 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)7 Logger (org.apache.logging.log4j.core.Logger)6 AbstractConfiguration (org.apache.logging.log4j.core.config.AbstractConfiguration)5 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)4 RoutingAppender (org.apache.logging.log4j.core.appender.routing.RoutingAppender)4 BuiltConfiguration (org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration)4