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;
}
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);
}
}
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;
}
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);
}
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);
}
Aggregations