Search in sources :

Example 6 with PatternLayout

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

the class LogCollector method register.

public static void register() {
    Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    LoggerContext loggerContext = rootLogger.getLoggerContext();
    PatternLayout layout = new PatternLayout();
    layout.setContext(loggerContext);
    layout.setPattern("%-5level: %msg%n");
    layout.start();
    instance.setContext(loggerContext);
    instance.setLayout(layout);
    instance.start();
    rootLogger.addAppender(instance);
}
Also used : PatternLayout(ch.qos.logback.classic.PatternLayout) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 7 with PatternLayout

use of ch.qos.logback.classic.PatternLayout in project jackrabbit-oak by apache.

the class LogDumper method getLogs.

private String getLogs() {
    if (appender == null) {
        return "<Logs cannot be determined>";
    }
    PatternLayout layout = createLayout();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < appender.getLength(); i++) {
        sb.append(layout.doLayout(appender.get(i)));
    }
    return sb.toString();
}
Also used : PatternLayout(ch.qos.logback.classic.PatternLayout)

Example 8 with PatternLayout

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

the class LogConfig method createLayout.

public PatternLayout createLayout() {
    // The java.util.MessageFormat pattern to use for formatting log
    // messages with the root logger.
    // This is a java.util.MessageFormat pattern supporting up to six
    // arguments:
    // {0} The timestamp of type java.util.Date,
    // {1} the log marker,
    // {2} the name of the current thread,
    // {3} the name of the logger,
    // {4} the debug level and
    // {5} the actual debug message
    Pattern date = Pattern.compile("\\{0,date,(.+?)\\}");
    Matcher m = date.matcher(pattern);
    String logBackPattern = pattern;
    if (m.matches()) {
        // If legacy pattern then transform the date format
        logBackPattern = m.replaceAll("%d'{'$1'}'");
    }
    boolean legacyPattern = false;
    for (String marker : LEGACY_MARKERS) {
        if (logBackPattern.contains(marker)) {
            legacyPattern = true;
            break;
        }
    }
    if (legacyPattern) {
        // [%thread] %logger %msg%n
        try {
            logBackPattern = MessageFormat.format(logBackPattern, "zero", "%marker", "%thread", "%logger", "%level", "%message") + "%n";
        } catch (IllegalArgumentException e) {
            log.warn("Invalid message format provided [{}]. Would use the default pattern", logBackPattern, e);
            logBackPattern = LogConfigManager.LOG_PATTERN_DEFAULT;
        }
    }
    PatternLayout pl = new PatternLayout();
    pl.setPattern(logBackPattern);
    pl.setOutputPatternAsHeader(false);
    pl.setContext(loggerContext);
    pl.start();
    return pl;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PatternLayout(ch.qos.logback.classic.PatternLayout)

Example 9 with PatternLayout

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

the class TestLogServlet method createLayout.

private void createLayout(Map<String, ?> config) {
    String pattern = PropertiesUtil.toString(config.get(PROP_MSG_PATTERN), DEFAULT_PATTERN);
    PatternLayout pl = new PatternLayout();
    pl.setPattern(pattern);
    pl.setOutputPatternAsHeader(false);
    pl.setContext(getContext());
    pl.start();
    layout = pl;
}
Also used : PatternLayout(ch.qos.logback.classic.PatternLayout)

Example 10 with PatternLayout

use of ch.qos.logback.classic.PatternLayout in project MantaroBot by Mantaro.

the class DiscordLogBack method start.

@Override
public void start() {
    patternLayout = new PatternLayout();
    patternLayout.setContext(getContext());
    patternLayout.setPattern("[`%d{HH:mm:ss}`] [`%t/%level`] [`%logger{0}`]: %msg");
    patternLayout.start();
    super.start();
}
Also used : PatternLayout(ch.qos.logback.classic.PatternLayout)

Aggregations

PatternLayout (ch.qos.logback.classic.PatternLayout)13 LoggerContext (ch.qos.logback.classic.LoggerContext)3 Logger (ch.qos.logback.classic.Logger)2 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)2 GelfAppender (de.appelgriepsch.logback.GelfAppender)2 HTMLLayout (ch.qos.logback.classic.html.HTMLLayout)1 TTLLLayout (ch.qos.logback.classic.layout.TTLLLayout)1 XMLLayout (ch.qos.logback.classic.log4j.XMLLayout)1 Appender (ch.qos.logback.core.Appender)1 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)1 FileAppender (ch.qos.logback.core.FileAppender)1 LayoutWrappingEncoder (ch.qos.logback.core.encoder.LayoutWrappingEncoder)1 LogProfileInfo (com.creditease.uav.profiling.handlers.log.LogProfileInfo)1 ByteBuffer (java.nio.ByteBuffer)1 Timestamp (java.sql.Timestamp)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Broadcaster (org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.Broadcaster)1