use of ch.qos.logback.core.ConsoleAppender in project sling by apache.
the class LogConfigManager method getDefaultAppender.
public Appender<ILoggingEvent> getDefaultAppender() {
OutputStreamAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
appender.setName(DEFAULT_CONSOLE_APPENDER_NAME);
appender.setContext(loggerContext);
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setPattern(LOG_PATTERN_DEFAULT);
encoder.setContext(loggerContext);
encoder.start();
appender.setEncoder(encoder);
appender.start();
return appender;
}
use of ch.qos.logback.core.ConsoleAppender in project UniversalMediaServer by UniversalMediaServer.
the class LoggingConfig method forceVerboseFileEncoder.
public static synchronized void forceVerboseFileEncoder() {
final String timeStampFormat = "yyyy-MM-dd HH:mm:ss.SSS";
if (loggerContext == null) {
LOGGER.error("Unknown loggerContext, aborting buffered logging. Make sure that loadFile() has been called first.");
return;
}
// Build iterator
Iterators<Appender<ILoggingEvent>> iterators = new Iterators<>();
// Add CacheLogger or rootLogger appenders depending on whether CacheLogger is active.
if (CacheLogger.isActive()) {
iterators.addIterator(CacheLogger.iteratorForAppenders());
} else {
iterators.addIterator(rootLogger.iteratorForAppenders());
}
// If syslog is active there probably are detached appenders there as well
if (!syslogDetachedAppenders.isEmpty()) {
iterators.addList(syslogDetachedAppenders);
}
// Iterate
Iterator<Appender<ILoggingEvent>> it = iterators.combinedIterator();
while (it.hasNext()) {
Appender<ILoggingEvent> appender = it.next();
if (appender instanceof OutputStreamAppender && !(appender instanceof ConsoleAppender<?>)) {
// Appender has Encoder property
Encoder<ILoggingEvent> encoder = ((OutputStreamAppender<ILoggingEvent>) appender).getEncoder();
if (encoder instanceof PatternLayoutEncoder) {
// Encoder has pattern
PatternLayoutEncoder patternEncoder = (PatternLayoutEncoder) encoder;
String logPattern = patternEncoder.getPattern();
// Set timestamp format
Pattern pattern = Pattern.compile("%((date|d)(\\{([^\\}]*)\\})?)(?=\\s)");
Matcher matcher = pattern.matcher(logPattern);
if (matcher.find()) {
boolean replace = true;
if (matcher.group(4) != null && matcher.group(4).equals(timeStampFormat)) {
replace = false;
}
if (replace) {
logPattern = logPattern.replaceFirst(pattern.pattern(), "%d{" + timeStampFormat + "}");
}
} else {
if (logPattern.startsWith("%-5level")) {
logPattern = logPattern.substring(0, 8) + " %d{" + timeStampFormat + "}" + logPattern.substring(8);
} else {
logPattern = "d%{" + timeStampFormat + "} " + logPattern;
}
}
// Make sure %logger is included
pattern = Pattern.compile("((%logger|%lo|%c)(\\{\\d+\\})?)(?=\\s)");
matcher = pattern.matcher(logPattern);
if (matcher.find()) {
boolean replace = true;
if (matcher.group().equals("%logger")) {
replace = false;
}
if (replace) {
logPattern = logPattern.replaceFirst(pattern.pattern(), "%logger");
}
} else {
if (logPattern.contains("%msg")) {
logPattern = logPattern.substring(0, logPattern.indexOf("%msg")) + "%logger " + logPattern.substring(logPattern.indexOf("%msg"));
} else {
logPattern = "%logger " + logPattern;
}
}
// Activate changes
patternEncoder.setPattern(logPattern);
patternEncoder.start();
}
}
}
LOGGER.info("Verbose file logging pattern enforced");
}
use of ch.qos.logback.core.ConsoleAppender in project pom-manipulation-ext by release-engineering.
the class TestUtils method runCli.
/**
* Run pom-manipulation-cli via run() with java params (-D arguments) in workingDir directory.
*
* @param args - List of additional command line arguments
* @param params - Map of String keys and String values representing -D arguments
* @param workingDir - Working directory in which you want the cli to be run.
* @return Exit value
* @throws Exception if an error occurs
*/
public static Integer runCli(List<String> args, Map<String, String> params, String workingDir) throws Exception {
ArrayList<String> arguments = new ArrayList<>(args);
Collections.addAll(arguments, toJavaParams(params).split("\\s+"));
boolean argsContainsFile = false;
for (String s : args) {
if (s.startsWith("--file")) {
argsContainsFile = true;
}
}
if (!argsContainsFile) {
arguments.add("--log=" + workingDir + File.separator + "build.log");
arguments.add("--file=" + workingDir + File.separator + "pom.xml");
}
logger.info("Invoking CLI with {} ", arguments);
int result = new Cli().run(arguments.toArray(new String[arguments.size()]));
// This is a bit of a hack. The CLI, if log-to-file is enabled resets the logging. As we don't fork and run
// in the same process this means we need to reset it back again. The benefit of not forking is a simpler test
// harness and it saves time when running the tests.
final ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.reset();
PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setPattern("[%t] %level %logger{32} - %msg%n");
ple.setContext(loggerContext);
ple.start();
ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>();
consoleAppender.setEncoder(ple);
consoleAppender.setContext(loggerContext);
consoleAppender.start();
root.addAppender(consoleAppender);
root.setLevel(Level.DEBUG);
return result;
}
use of ch.qos.logback.core.ConsoleAppender in project ANNIS by korpling.
the class AnnisBaseRunner method setupLogging.
// configure logging
public static void setupLogging(boolean console) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator jc = new JoranConfigurator();
jc.setContext(loggerContext);
loggerContext.reset();
try {
jc.doConfigure(System.getProperty("annis.home") + "/conf/logback.xml");
} catch (JoranException ex) {
System.out.println(ex.getMessage());
}
ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>();
consoleAppender.setContext(loggerContext);
consoleAppender.setName("CONSOLE");
consoleAppender.setLayout(new ConsoleLayout());
ThresholdFilter consoleFilter = new ConsoleFilter();
consoleFilter.setLevel(console ? "DEBUG" : "WARN");
consoleFilter.start();
consoleAppender.addFilter(consoleFilter);
consoleAppender.setTarget("System.err");
consoleAppender.start();
ch.qos.logback.classic.Logger logbackLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
logbackLogger.addAppender(consoleAppender);
SLF4JBridgeHandler.removeHandlersForRootLogger();
;
SLF4JBridgeHandler.install();
}
use of ch.qos.logback.core.ConsoleAppender in project kie-wb-common by kiegroup.
the class LogbackConfig method setConsoleAppender.
private ConsoleAppender setConsoleAppender(LoggerContext loggerContext, PatternLayoutEncoder pl) {
ConsoleAppender consoleAppender = new ConsoleAppender<>();
consoleAppender.setName("consoleAppender");
consoleAppender.setContext(loggerContext);
consoleAppender.setEncoder(pl);
consoleAppender.start();
return consoleAppender;
}
Aggregations