Search in sources :

Example 6 with FileAppender

use of ch.qos.logback.core.FileAppender 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 7 with FileAppender

use of ch.qos.logback.core.FileAppender in project uavstack by uavorg.

the class LogBackHookProxy method figureoutLogConfiguration.

private void figureoutLogConfiguration(Logger Logger, LinkedList<LogProfileInfo> list, String appid) {
    Iterator<Appender<ILoggingEvent>> appenders = Logger.iteratorForAppenders();
    while (appenders != null && appenders.hasNext()) {
        LogProfileInfo logProfileInfo = new LogProfileInfo();
        if (appid != null) {
            logProfileInfo.setAppId(appid);
        }
        logProfileInfo.setLogType(LogProfileInfo.LogType.Log4j);
        Map<String, String> attributes = new HashMap<String, String>();
        attributes.put(LogProfileInfo.ENGINE, "logback");
        Appender<ILoggingEvent> appender = appenders.next();
        if (!(appender instanceof FileAppender<?>)) {
            continue;
        }
        FileAppender<ILoggingEvent> fileAppender = (FileAppender<ILoggingEvent>) appender;
        @SuppressWarnings("rawtypes") LayoutWrappingEncoder encoder = (LayoutWrappingEncoder) fileAppender.getEncoder();
        Layout<?> layout = encoder.getLayout();
        if (null != layout) {
            if (layout instanceof PatternLayout) {
                PatternLayout patternLayout = (PatternLayout) encoder.getLayout();
                attributes.put(LogProfileInfo.PATTERN, patternLayout.getPattern());
            } else if (layout instanceof HTMLLayout) {
                attributes.put(LogProfileInfo.PATTERN, "HTMLLayout");
            } else if (layout instanceof XMLLayout) {
                attributes.put(LogProfileInfo.PATTERN, "XMLLayout");
            } else if (layout instanceof TTLLLayout) {
                attributes.put(LogProfileInfo.PATTERN, "TTCCLayout");
            }
        }
        logProfileInfo.setFilePath(fileAppender.getFile());
        logProfileInfo.setAttributes(attributes);
        list.add(logProfileInfo);
    }
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) FileAppender(ch.qos.logback.core.FileAppender) HashMap(java.util.HashMap) HTMLLayout(ch.qos.logback.classic.html.HTMLLayout) PatternLayout(ch.qos.logback.classic.PatternLayout) TTLLLayout(ch.qos.logback.classic.layout.TTLLLayout) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LogProfileInfo(com.creditease.uav.profiling.handlers.log.LogProfileInfo) XMLLayout(ch.qos.logback.classic.log4j.XMLLayout) LayoutWrappingEncoder(ch.qos.logback.core.encoder.LayoutWrappingEncoder)

Example 8 with FileAppender

use of ch.qos.logback.core.FileAppender in project BIMserver by opensourceBIM.

the class JarBimServer method fixLogging.

/**
 * Add a file appender to every logger we can find (the loggers should already have been configured via logback.xml)
 *
 * @throws IOException
 */
private void fixLogging(BimServerConfig config) throws IOException {
    Path logFolder = config.getHomeDir().resolve("logs");
    if (!Files.isDirectory(logFolder)) {
        Files.createDirectories(logFolder);
    }
    Path file = logFolder.resolve("bimserver.log");
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    PatternLayoutEncoder ple = new PatternLayoutEncoder();
    ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
    ple.setContext(lc);
    ple.start();
    FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>();
    String filename = file.toAbsolutePath().toString();
    if (lc instanceof LoggerContext) {
        if (!lc.isStarted()) {
            lc.start();
        }
    }
    System.out.println("Logging to " + filename);
    fileAppender.setFile(filename);
    fileAppender.setEncoder(ple);
    fileAppender.setContext(lc);
    fileAppender.start();
    for (ch.qos.logback.classic.Logger log : lc.getLoggerList()) {
        if (log.getLevel() != null) {
            log.addAppender(fileAppender);
        }
    }
}
Also used : Path(java.nio.file.Path) PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) FileAppender(ch.qos.logback.core.FileAppender) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 9 with FileAppender

use of ch.qos.logback.core.FileAppender in project BIMserver by opensourceBIM.

the class LocalDevBimServerStarter method fixLogging.

/**
 * Add a file appender to every logger we can find (the loggers should already have been configured via logback.xml)
 *
 * @throws IOException
 */
private void fixLogging(BimServerConfig config) throws IOException {
    Path logFolder = config.getHomeDir().resolve("logs");
    if (!Files.isDirectory(logFolder)) {
        Files.createDirectories(logFolder);
    }
    Path file = logFolder.resolve("bimserver.log");
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    PatternLayoutEncoder ple = new PatternLayoutEncoder();
    ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
    ple.setContext(lc);
    ple.start();
    FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>();
    String filename = file.toAbsolutePath().toString();
    if (lc instanceof LoggerContext) {
        if (!lc.isStarted()) {
            lc.start();
        }
    }
    System.out.println("Logging to " + filename);
    fileAppender.setFile(filename);
    fileAppender.setEncoder(ple);
    fileAppender.setContext(lc);
    fileAppender.start();
    for (ch.qos.logback.classic.Logger log : lc.getLoggerList()) {
        if (log.getLevel() != null) {
            log.addAppender(fileAppender);
        }
    }
}
Also used : Path(java.nio.file.Path) PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) FileAppender(ch.qos.logback.core.FileAppender) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 10 with FileAppender

use of ch.qos.logback.core.FileAppender in project BIMserver by opensourceBIM.

the class WarServerInitializer method fixLogging.

/**
 * Add a file appender to every logger we can find (the loggers should already have been configured via logback.xml)
 *
 * @throws IOException
 */
private void fixLogging(BimServerConfig config) throws IOException {
    Path logFolder = config.getHomeDir().resolve("logs");
    if (!Files.isDirectory(logFolder)) {
        Files.createDirectories(logFolder);
    }
    Path file = logFolder.resolve("bimserver.log");
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    PatternLayoutEncoder ple = new PatternLayoutEncoder();
    ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
    ple.setContext(lc);
    ple.start();
    FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>();
    String filename = file.toAbsolutePath().toString();
    if (lc instanceof LoggerContext) {
        if (!lc.isStarted()) {
            lc.start();
        }
    }
    System.out.println("Logging to " + filename);
    fileAppender.setFile(filename);
    fileAppender.setEncoder(ple);
    fileAppender.setContext(lc);
    fileAppender.start();
    for (ch.qos.logback.classic.Logger log : lc.getLoggerList()) {
        if (log.getLevel() != null) {
            log.addAppender(fileAppender);
        }
    }
}
Also used : Path(java.nio.file.Path) PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) FileAppender(ch.qos.logback.core.FileAppender) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext)

Aggregations

FileAppender (ch.qos.logback.core.FileAppender)44 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)31 LoggerContext (ch.qos.logback.classic.LoggerContext)25 File (java.io.File)22 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)19 Logger (ch.qos.logback.classic.Logger)15 Appender (ch.qos.logback.core.Appender)14 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)11 Test (org.junit.Test)9 Path (java.nio.file.Path)6 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)5 OutputStreamAppender (ch.qos.logback.core.OutputStreamAppender)5 FixedWindowRollingPolicy (ch.qos.logback.core.rolling.FixedWindowRollingPolicy)4 SizeBasedTriggeringPolicy (ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy)4 FileSize (ch.qos.logback.core.util.FileSize)4 IOException (java.io.IOException)4 Field (java.lang.reflect.Field)4 SyslogAppender (ch.qos.logback.classic.net.SyslogAppender)3 SizeAndTimeBasedRollingPolicy (ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy)3 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)3