use of ch.qos.logback.core.FileAppender in project sonarqube by SonarSource.
the class LogbackHelperTest method createRollingPolicy_defaults.
@Test
public void createRollingPolicy_defaults() {
LoggerContext ctx = underTest.getRootContext();
LogbackHelper.RollingPolicy policy = underTest.createRollingPolicy(ctx, props, "sonar");
FileAppender appender = policy.createAppender("SONAR_FILE");
assertThat(appender).isInstanceOf(RollingFileAppender.class);
// max 5 daily files
RollingFileAppender fileAppender = (RollingFileAppender) appender;
TimeBasedRollingPolicy triggeringPolicy = (TimeBasedRollingPolicy) fileAppender.getTriggeringPolicy();
assertThat(triggeringPolicy.getMaxHistory()).isEqualTo(7);
assertThat(triggeringPolicy.getFileNamePattern()).endsWith("sonar.%d{yyyy-MM-dd}.log");
}
use of ch.qos.logback.core.FileAppender in project sonarqube by SonarSource.
the class WebServerProcessLoggingTest method log_to_web_file.
@Test
public void log_to_web_file() {
LoggerContext ctx = underTest.configure(props);
Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
Appender<ILoggingEvent> appender = root.getAppender("file_web");
assertThat(appender).isInstanceOf(FileAppender.class);
FileAppender fileAppender = (FileAppender) appender;
assertThat(fileAppender.getFile()).isEqualTo(new File(logDir, "web.log").getAbsolutePath());
assertThat(fileAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class);
PatternLayoutEncoder encoder = (PatternLayoutEncoder) fileAppender.getEncoder();
assertThat(encoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level web[%X{HTTP_REQUEST_ID}][%logger{20}] %msg%n");
}
use of ch.qos.logback.core.FileAppender in project openhab1-addons by openhab.
the class LoggingPersistenceService method createNewAppender.
protected FileAppender<ILoggingEvent> createNewAppender(String alias) {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(context);
encoder.setPattern(pattern);
encoder.start();
FileAppender<ILoggingEvent> appender = new FileAppender<ILoggingEvent>();
appender.setAppend(true);
appender.setFile(LOG_FOLDER + File.separator + alias + LOG_FILEEXT);
appender.setEncoder(encoder);
appender.setContext(context);
appender.start();
return appender;
}
use of ch.qos.logback.core.FileAppender in project sling by apache.
the class SlingConfigurationPrinter method dumpLogFileSummary.
private void dumpLogFileSummary(PrintWriter pw, Collection<Appender<ILoggingEvent>> appenders) {
pw.println("Summary");
pw.println("=======");
pw.println();
int counter = 0;
final String rootDir = logbackManager.getRootDir();
for (Appender<ILoggingEvent> appender : appenders) {
if (appender instanceof FileAppender) {
File file = new File(((FileAppender) appender).getFile());
final File dir = file.getParentFile();
final String baseName = file.getName();
String absolutePath = dir.getAbsolutePath();
String displayName = ((FileAppender) appender).getFile();
if (absolutePath.startsWith(rootDir)) {
displayName = baseName;
}
pw.printf("%d. %s %n", ++counter, displayName);
final File[] files = getRotatedFiles((FileAppender) appender, -1);
for (File f : files) {
pw.printf(" - %s, %s, %s %n", f.getName(), humanReadableByteCount(f.length()), getModifiedDate(f));
}
}
}
pw.println();
}
use of ch.qos.logback.core.FileAppender in project sling by apache.
the class SlingConfigurationPrinter method printConfiguration.
/**
* @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
*/
@SuppressWarnings("UnusedDeclaration")
public void printConfiguration(PrintWriter printWriter, String mode) {
LogbackManager.LoggerStateContext ctx = logbackManager.determineLoggerState();
int numOfLines = getNumOfLines();
Tailer tailer = new Tailer(printWriter, numOfLines);
dumpLogFileSummary(printWriter, ctx.getAllAppenders());
if (!MODE_ZIP.equals(mode)) {
for (Appender<ILoggingEvent> appender : ctx.getAllAppenders()) {
if (appender instanceof FileAppender) {
final File file = new File(((FileAppender) appender).getFile());
if (file.exists()) {
printWriter.print("Log file ");
printWriter.println(file.getAbsolutePath());
printWriter.println("--------------------------------------------------");
if (numOfLines < 0) {
includeWholeFile(printWriter, file);
} else {
try {
tailer.tail(file);
} catch (IOException e) {
logbackManager.getLogConfigManager().internalFailure("Error occurred " + "while processing log file " + file, e);
}
}
printWriter.println();
}
}
}
}
dumpLogbackStatus(logbackManager, printWriter);
}
Aggregations