Search in sources :

Example 11 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project sling by apache.

the class SlingConfigurationPrinter method dumpLogFileSummary.

private void dumpLogFileSummary(PrintWriter pw, Collection<Appender<ILoggingEvent>> appenders) {
    pw.println("Summary");
    pw.println("=======");
    pw.println();
    int counter = 0;
    final String rootDir = logbackManager.getRootDir();
    for (Appender<ILoggingEvent> appender : appenders) {
        if (appender instanceof FileAppender) {
            File file = new File(((FileAppender) appender).getFile());
            final File dir = file.getParentFile();
            final String baseName = file.getName();
            String absolutePath = dir.getAbsolutePath();
            String displayName = ((FileAppender) appender).getFile();
            if (absolutePath.startsWith(rootDir)) {
                displayName = baseName;
            }
            pw.printf("%d. %s %n", ++counter, displayName);
            final File[] files = getRotatedFiles((FileAppender) appender, -1);
            for (File f : files) {
                pw.printf("  - %s, %s, %s %n", f.getName(), humanReadableByteCount(f.length()), getModifiedDate(f));
            }
        }
    }
    pw.println();
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) File(java.io.File)

Example 12 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project sling by apache.

the class SlingConfigurationPrinter method printConfiguration.

/**
     * @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
     */
@SuppressWarnings("UnusedDeclaration")
public void printConfiguration(PrintWriter printWriter, String mode) {
    LogbackManager.LoggerStateContext ctx = logbackManager.determineLoggerState();
    int numOfLines = getNumOfLines();
    Tailer tailer = new Tailer(printWriter, numOfLines);
    dumpLogFileSummary(printWriter, ctx.getAllAppenders());
    if (!MODE_ZIP.equals(mode)) {
        for (Appender<ILoggingEvent> appender : ctx.getAllAppenders()) {
            if (appender instanceof FileAppender) {
                final File file = new File(((FileAppender) appender).getFile());
                if (file.exists()) {
                    printWriter.print("Log file ");
                    printWriter.println(file.getAbsolutePath());
                    printWriter.println("--------------------------------------------------");
                    if (numOfLines < 0) {
                        includeWholeFile(printWriter, file);
                    } else {
                        try {
                            tailer.tail(file);
                        } catch (IOException e) {
                            logbackManager.getLogConfigManager().internalFailure("Error occurred " + "while processing log file " + file, e);
                        }
                    }
                    printWriter.println();
                }
            }
        }
    }
    dumpLogbackStatus(logbackManager, printWriter);
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) IOException(java.io.IOException) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) File(java.io.File)

Example 13 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project sling by apache.

the class SlingConfigurationPrinter method getAttachments.

/**
     * Attempts to determine all log files created even via rotation.
     * if some complex rotation logic is used where rotated file get different names
     * or get created in different directory then those files would not be
     * included
     *
     * @see org.apache.felix.webconsole.AttachmentProvider#getAttachments(String)
     */
@SuppressWarnings("UnusedDeclaration")
public URL[] getAttachments(String mode) {
    // we only provide urls for mode zip
    if (MODE_ZIP.equals(mode)) {
        final List<URL> urls = new ArrayList<URL>();
        LogbackManager.LoggerStateContext ctx = logbackManager.determineLoggerState();
        for (Appender<ILoggingEvent> appender : ctx.getAllAppenders()) {
            if (appender instanceof FileAppender) {
                final File[] files = getRotatedFiles((FileAppender) appender, getMaxOldFileCount());
                for (File f : files) {
                    try {
                        urls.add(f.toURI().toURL());
                    } catch (MalformedURLException mue) {
                    // we just ignore this file then
                    }
                }
            }
        }
        if (urls.size() > 0) {
            return urls.toArray(new URL[urls.size()]);
        }
    }
    return null;
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) File(java.io.File) URL(java.net.URL)

Example 14 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project jadx by skylot.

the class JadxCLIArgs method process.

private boolean process() {
    if (isPrintHelp()) {
        printUsage();
        return false;
    }
    try {
        if (threadsCount <= 0) {
            throw new JadxException("Threads count must be positive");
        }
        if (files != null) {
            for (String fileName : files) {
                File file = new File(fileName);
                if (file.exists()) {
                    input.add(file);
                } else {
                    throw new JadxException("File not found: " + file);
                }
            }
        }
        if (input.size() > 1) {
            throw new JadxException("Only one input file is supported");
        }
        if (outDirName != null) {
            outputDir = new File(outDirName);
        }
        if (isVerbose()) {
            ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
            // remove INFO ThresholdFilter
            Appender<ILoggingEvent> appender = rootLogger.getAppender("STDOUT");
            if (appender != null) {
                appender.clearAllFilters();
            }
        }
    } catch (JadxException e) {
        System.err.println("ERROR: " + e.getMessage());
        printUsage();
        return false;
    }
    return true;
}
Also used : JadxException(jadx.core.utils.exceptions.JadxException) Logger(org.slf4j.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) File(java.io.File)

Example 15 with ILoggingEvent

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

the class LevelRemappingAppenderTests method mockLogEvent.

private ILoggingEvent mockLogEvent(Level level) {
    ILoggingEvent event = mock(ILoggingEvent.class);
    given(event.getLevel()).willReturn(level);
    return event;
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Aggregations

ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)300 Test (org.junit.Test)111 Logger (ch.qos.logback.classic.Logger)90 LoggerContext (ch.qos.logback.classic.LoggerContext)85 Appender (ch.qos.logback.core.Appender)48 Test (org.junit.jupiter.api.Test)47 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)44 FileAppender (ch.qos.logback.core.FileAppender)40 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)35 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)30 File (java.io.File)26 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)22 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)21 Logger (org.slf4j.Logger)20 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)17 AsyncAppender (ch.qos.logback.classic.AsyncAppender)16 ArrayList (java.util.ArrayList)16 ListAppender (ch.qos.logback.core.read.ListAppender)15 OnMarkerEvaluator (ch.qos.logback.classic.boolex.OnMarkerEvaluator)13 EvaluatorFilter (ch.qos.logback.core.filter.EvaluatorFilter)13