Search in sources :

Example 1 with PatternLayout

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

the class LogDumper method createLayout.

private static PatternLayout createLayout() {
    PatternLayout pl = new PatternLayout();
    pl.setPattern(DEFAULT_PATTERN);
    pl.setOutputPatternAsHeader(false);
    pl.setContext(getContext());
    pl.start();
    return pl;
}
Also used : PatternLayout(ch.qos.logback.classic.PatternLayout)

Example 2 with PatternLayout

use of ch.qos.logback.classic.PatternLayout 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 3 with PatternLayout

use of ch.qos.logback.classic.PatternLayout in project coffeenet-starter by coffeenet.

the class CoffeeNetLoggingAutoConfiguration method gelfAppender.

private GelfAppender gelfAppender(LoggerContext loggerContext) {
    GelfAppender gelfAppender = new GelfAppender();
    gelfAppender.setContext(loggerContext);
    gelfAppender.setName(COFFEENET_GELF);
    gelfAppender.setServer(coffeeNetLoggingGelfProperties.getServer());
    gelfAppender.setProtocol(coffeeNetLoggingGelfProperties.getProtocol());
    gelfAppender.setPort(coffeeNetLoggingGelfProperties.getPort());
    gelfAppender.addAdditionalField("application", coffeeNetConfigurationProperties.getApplicationName());
    gelfAppender.addAdditionalField("environment", coffeeNetLoggingGelfProperties.getEnvironment());
    PatternLayout patternLayout = new PatternLayout();
    patternLayout.setContext(loggerContext);
    patternLayout.setPattern(coffeeNetLoggingGelfProperties.getLayout());
    patternLayout.start();
    gelfAppender.setLayout(patternLayout);
    gelfAppender.start();
    return gelfAppender;
}
Also used : PatternLayout(ch.qos.logback.classic.PatternLayout) GelfAppender(de.appelgriepsch.logback.GelfAppender)

Example 4 with PatternLayout

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

the class BroadcastTest method listen.

private static void listen() throws InterruptedException {
    String config = "key 123";
    ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<ILoggingEvent>();
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    ca.setContext(lc);
    PatternLayout pl = new PatternLayout();
    pl.setPattern("%msg%n");
    pl.setContext(lc);
    pl.start();
    ca.setLayout(pl);
    ca.start();
    ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(TCPBroadcaster.class);
    logger.addAppender(ca);
    logger.setLevel(Level.DEBUG);
    TCPBroadcaster receiver = new TCPBroadcaster(config);
    receiver.addListener(new Broadcaster.Listener() {

        @Override
        public void receive(ByteBuffer buff) {
            int end = buff.position();
            StringBuilder sb = new StringBuilder();
            while (buff.remaining() > 0) {
                char c = (char) buff.get();
                if (c >= ' ' && c < 128) {
                    sb.append(c);
                } else if (c <= 9) {
                    sb.append((char) ('0' + c));
                } else {
                    sb.append('.');
                }
            }
            String dateTime = new Timestamp(System.currentTimeMillis()).toString().substring(0, 19);
            System.out.println(dateTime + " Received " + sb);
            buff.position(end);
        }
    });
    Random r = new Random();
    int x = r.nextInt();
    System.out.println("Sending " + x);
    for (int i = 0; i < 10; i++) {
        Thread.sleep(10);
        ByteBuffer buff = ByteBuffer.allocate(1024);
        buff.putInt(0);
        buff.putInt(x);
        buff.put(new byte[100]);
        buff.flip();
        receiver.send(buff);
        if (!receiver.isRunning()) {
            System.out.println("Did not start or already stopped");
            break;
        }
    }
    Thread.sleep(Integer.MAX_VALUE);
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) TCPBroadcaster(org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.TCPBroadcaster) PatternLayout(ch.qos.logback.classic.PatternLayout) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) ByteBuffer(java.nio.ByteBuffer) Timestamp(java.sql.Timestamp) Random(java.util.Random) Broadcaster(org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.Broadcaster) TCPBroadcaster(org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.TCPBroadcaster)

Example 5 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)

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