use of ch.qos.logback.core.FileAppender in project gocd by gocd.
the class DefaultPluginLoggingService method getCurrentLogDirectory.
String getCurrentLogDirectory() {
try {
FileAppender fileAppender = getGoServerLogFileAppender();
String fileName = fileAppender.rawFileProperty();
return new File(fileName).getAbsoluteFile().getParent();
} catch (Exception e) {
return ".";
}
}
use of ch.qos.logback.core.FileAppender in project gocd by gocd.
the class FileLocationProvider method asJson.
@Override
public Map<String, Object> asJson() {
LinkedHashMap<String, Object> json = new LinkedHashMap<>();
json.put("loc.config.dir", systemEnvironment.configDir().getAbsolutePath());
List<Logger> loggers = LOGGER_CONTEXT.getLoggerList();
Appender[] appenders = getAppenders(loggers);
for (int i = 0; i < appenders.length; i++) {
Appender appender = appenders[i];
if (!isFileAppender(appender)) {
continue;
}
FileAppender fileAppender = (FileAppender) appender;
File logFile = new File(fileAppender.rawFileProperty());
json.put("loc.log.root." + i, new File(logFile.getAbsolutePath()).getParent());
json.put("loc.log.basename." + i, logFile.getName());
}
return json;
}
use of ch.qos.logback.core.FileAppender in project jmxtrans by jmxtrans.
the class NagiosWriter method initLogger.
/**
* Initializes the logger. This is called when we need to create a new
* logger for the given file name.
*
* @param fileStr
* @return a new Logger instance for the given fileStr
* @throws IOException
*/
protected Logger initLogger(String fileStr) throws IOException {
String loggerName = "NagiosWriter" + this.hashCode();
final PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(loggerContext);
encoder.setPattern(LOG_PATTERN);
encoder.start();
final FileAppender appender = new FileAppender();
appender.setContext(loggerContext);
appender.setName(loggerName + "File");
appender.setAppend(true);
appender.setBufferSize(new FileSize(LOG_IO_BUFFER_SIZE_BYTES));
appender.setFile(fileStr);
appender.setEncoder(encoder);
appender.start();
Logger logger = loggerContext.getLogger(loggerName);
logger.addAppender(appender);
logger.setLevel(Level.INFO);
logger.setAdditive(false);
return logger;
}
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");
}
Aggregations