Search in sources :

Example 96 with Logger

use of ch.qos.logback.classic.Logger in project spring-boot by spring-projects.

the class LogbackLoggingSystemTests method testBasicConfigLocation.

@Test
public void testBasicConfigLocation() throws Exception {
    this.loggingSystem.beforeInitialize();
    ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory();
    LoggerContext context = (LoggerContext) factory;
    Logger root = context.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    assertThat(root.getAppender("CONSOLE")).isNotNull();
}
Also used : ILoggerFactory(org.slf4j.ILoggerFactory) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 97 with Logger

use of ch.qos.logback.classic.Logger in project sakuli by ConSol.

the class LoggerInitializerTest method testInitLoggerContextFromIncludeFolder.

@Test
public void testInitLoggerContextFromIncludeFolder() throws Throwable {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    Logger root = context.getLogger("root");
    Logger sakuliLogger = context.getLogger("org.sakuli");
    Appender<ILoggingEvent> stdout = root.getAppender("stdout");
    Appender<ILoggingEvent> sakuliAppender = root.getAppender("sakuli");
    //no log config in classpath
    Assert.assertNull(stdout);
    Assert.assertNull(sakuliAppender);
    Assert.assertNotNull(sakuliLogger);
    Assert.assertNotNull(root);
    when(sakuliProperties.getConfigFolder()).thenReturn(Paths.get(BaseTest.SAKULI_HOME_FOLDER_PATH + SakuliProperties.CONFIG_FOLDER_APPEDER));
    testling.initLoggerContext();
    verify(testling).getConfigFileFromClasspath();
    verify(testling).getConfigFile();
    //verify root logger
    context = (LoggerContext) LoggerFactory.getILoggerFactory();
    root = context.getLogger("root");
    sakuliLogger = context.getLogger("org.sakuli");
    stdout = root.getAppender("stdout");
    sakuliAppender = root.getAppender("sakuli");
    Assert.assertNotNull(stdout);
    Assert.assertNotNull(sakuliLogger);
    Assert.assertNotNull(sakuliAppender);
    Assert.assertNotNull(sakuliAppender);
}
Also used : Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) BaseTest(org.sakuli.BaseTest) Test(org.testng.annotations.Test)

Example 98 with Logger

use of ch.qos.logback.classic.Logger in project midpoint by Evolveum.

the class LoggingConfigurationManager method configure.

public static void configure(LoggingConfigurationType config, String version, OperationResult result) throws SchemaException {
    OperationResult res = result.createSubresult(LoggingConfigurationManager.class.getName() + ".configure");
    if (InternalsConfig.avoidLoggingChange) {
        LOGGER.info("IGNORING change of logging configuration (current config version: {}, new version {}) because avoidLoggingChange=true", currentlyUsedVersion, version);
        res.recordNotApplicableIfUnknown();
        return;
    }
    if (currentlyUsedVersion != null) {
        LOGGER.info("Applying logging configuration (currently applied version: {}, new version: {})", currentlyUsedVersion, version);
    } else {
        LOGGER.info("Applying logging configuration (version {})", version);
    }
    currentlyUsedVersion = version;
    // JUL Bridge initialization was here. (SLF4JBridgeHandler)
    // But it was moved to a later phase as suggested by http://jira.qos.ch/browse/LOGBACK-740
    // Initialize JUL bridge
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
    //Get current log configuration
    LoggerContext lc = (LoggerContext) TraceManager.getILoggerFactory();
    //Prepare configurator in current context
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    //Generate configuration file as string
    String configXml = prepareConfiguration(config);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("New logging configuration:");
        LOGGER.trace(configXml);
    }
    InputStream cis = new ByteArrayInputStream(configXml.getBytes());
    LOGGER.info("Resetting current logging configuration");
    lc.getStatusManager().clear();
    //Set all loggers to error
    for (Logger l : lc.getLoggerList()) {
        LOGGER.trace("Disable logger: {}", l);
        l.setLevel(Level.ERROR);
    }
    // Reset configuration
    lc.reset();
    //Switch to new logging configuration
    lc.setName("MidPoint");
    try {
        configurator.doConfigure(cis);
        LOGGER.info("New logging configuration applied");
    } catch (JoranException e) {
        System.out.println("Error during applying logging configuration: " + e.getMessage());
        LOGGER.error("Error during applying logging configuration: " + e.getMessage(), e);
        result.createSubresult("Applying logging configuration.").recordFatalError(e.getMessage(), e);
    } catch (NumberFormatException e) {
        System.out.println("Error during applying logging configuration: " + e.getMessage());
        LOGGER.error("Error during applying logging configuration: " + e.getMessage(), e);
        result.createSubresult("Applying logging configuration.").recordFatalError(e.getMessage(), e);
    }
    //Get messages if error occurred;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    StatusPrinter.setPrintStream(new PrintStream(baos));
    StatusPrinter.print(lc);
    String internalLog = null;
    try {
        internalLog = baos.toString("UTF8");
    } catch (UnsupportedEncodingException e) {
        // should never happen
        LOGGER.error("Woops?", e);
    }
    if (!StringUtils.isEmpty(internalLog)) {
        //Parse internal log
        res.recordSuccess();
        String[] internalLogLines = internalLog.split("\n");
        for (int i = 0; i < internalLogLines.length; i++) {
            if (internalLogLines[i].contains("|-ERROR"))
                res.recordPartialError(internalLogLines[i]);
            res.appendDetail(internalLogLines[i]);
        }
        LOGGER.trace("LogBack internal log:\n{}", internalLog);
    } else {
        res.recordSuccess();
    }
    // Initialize JUL bridge
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
    return;
}
Also used : PrintStream(java.io.PrintStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) ByteArrayInputStream(java.io.ByteArrayInputStream) JoranException(ch.qos.logback.core.joran.spi.JoranException) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator)

Example 99 with Logger

use of ch.qos.logback.classic.Logger in project indy by Commonjava.

the class DiagnosticsManager method getDiagnosticBundle.

public File getDiagnosticBundle() throws IOException {
    File out = File.createTempFile("indy-diags." + new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss.SSSZ").format(new Date()), ".zip");
    org.slf4j.Logger logger = LoggerFactory.getLogger(getClass());
    Logger rootLogger = (Logger) LoggerFactory.getLogger("ROOT");
    logger.info("Writing diagnostic bundle to: '{}'", out);
    Appender<ILoggingEvent> appender = rootLogger.getAppender(FILE_LOGGER);
    if (appender != null && (appender instanceof FileAppender)) {
        try (ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(out))) {
            File dir = new File(((FileAppender) appender).getFile()).getParentFile();
            for (File f : dir.listFiles(file -> file.getName().endsWith(".log"))) {
                String name = LOGS_DIR + "/" + f.getName();
                logger.info("Adding {} to bundle zip: {}", name, out);
                zip.putNextEntry(new ZipEntry(name));
                try (InputStream in = new FileInputStream(f)) {
                    IOUtils.copy(in, zip);
                }
            }
            logger.info("Adding thread dump to bundle zip: {}", out);
            zip.putNextEntry(new ZipEntry(THREAD_DUMP_FILE));
            zip.write(getThreadDumpString().getBytes());
            zip.flush();
            zip.close();
        }
    } else {
        return null;
    }
    return out;
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Date(java.util.Date) FileInputStream(java.io.FileInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Example 100 with Logger

use of ch.qos.logback.classic.Logger in project Alpha by alpha-asp.

the class MainTest method testLargeInputProgram.

@Test
@Ignore
public void testLargeInputProgram() {
    Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root.setLevel(Level.DEBUG);
    //main(new String[]{"-g", "naive", "-s", "default", "-n", "2", "-i", "./benchmarks/omiga/omiga-testcases/locstrat/locstrat-200.txt"});
    //main(new String[]{"-g", "naive", "-s", "default", "-n", "2", "-i", "./benchmarks/omiga/omiga-testcases/cutedge/cutedge-100-50.txt"});
    //main(new String[]{"-g", "naive", "-s", "default", "-n", "10", "-i", "./benchmarks/omiga/omiga-testcases/3col/3col-20-38.txt"});
    //main(new String[]{"-g", "naive", "-s", "naive", "-n", "10", "-i", "./benchmarks/omiga/omiga-testcases/reach/reach-1.txt"});
    main(new String[] { "-g", "naive", "-s", "default", "-n", "1", "-i", "./benchmarks/siemens/vehicle_normal_small.asp" });
}
Also used : Logger(ch.qos.logback.classic.Logger) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Logger (ch.qos.logback.classic.Logger)129 Test (org.junit.Test)43 LoggerContext (ch.qos.logback.classic.LoggerContext)38 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)35 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)14 Appender (ch.qos.logback.core.Appender)14 FileAppender (ch.qos.logback.core.FileAppender)14 File (java.io.File)12 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)10 ArrayList (java.util.ArrayList)9 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)8 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)8 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)7 PipeConfiguration (co.cask.cdap.filetailer.config.PipeConfiguration)6 Level (ch.qos.logback.classic.Level)5 Map (java.util.Map)5 Before (org.junit.Before)5 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)4 FileTailerQueue (co.cask.cdap.filetailer.queue.FileTailerQueue)3 IOException (java.io.IOException)3