use of org.neo4j.logging.RotatingFileOutputStreamSupplier in project neo4j by neo4j.
the class QueryLoggerKernelExtension method newInstance.
@Override
public Lifecycle newInstance(@SuppressWarnings("unused") KernelContext context, final Dependencies dependencies) throws Throwable {
final Config config = dependencies.config();
boolean queryLogEnabled = config.get(GraphDatabaseSettings.log_queries);
final File queryLogFile = config.get(GraphDatabaseSettings.log_queries_filename);
final FileSystemAbstraction fileSystem = dependencies.fileSystem();
final JobScheduler jobScheduler = dependencies.jobScheduler();
final Monitors monitoring = dependencies.monitoring();
if (!queryLogEnabled) {
return createEmptyAdapter();
}
return new LifecycleAdapter() {
Closeable closable;
@Override
public void init() throws Throwable {
Long thresholdMillis = config.get(GraphDatabaseSettings.log_queries_threshold);
Long rotationThreshold = config.get(GraphDatabaseSettings.log_queries_rotation_threshold);
int maxArchives = config.get(GraphDatabaseSettings.log_queries_max_archives);
boolean logQueryParameters = config.get(GraphDatabaseSettings.log_queries_parameter_logging_enabled);
FormattedLog.Builder logBuilder = FormattedLog.withUTCTimeZone();
Log log;
if (rotationThreshold == 0) {
OutputStream logOutputStream = createOrOpenAsOuputStream(fileSystem, queryLogFile, true);
log = logBuilder.toOutputStream(logOutputStream);
closable = logOutputStream;
} else {
RotatingFileOutputStreamSupplier rotatingSupplier = new RotatingFileOutputStreamSupplier(fileSystem, queryLogFile, rotationThreshold, 0, maxArchives, jobScheduler.executor(JobScheduler.Groups.queryLogRotation));
log = logBuilder.toOutputStream(rotatingSupplier);
closable = rotatingSupplier;
}
QueryLogger logger = new QueryLogger(Clocks.systemClock(), log, thresholdMillis, logQueryParameters);
monitoring.addMonitorListener(logger);
}
@Override
public void shutdown() throws Throwable {
closable.close();
}
};
}
Aggregations