Search in sources :

Example 1 with RotatingFileOutputStreamSupplier

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();
        }
    };
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) FormattedLog(org.neo4j.logging.FormattedLog) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Log(org.neo4j.logging.Log) FormattedLog(org.neo4j.logging.FormattedLog) Config(org.neo4j.kernel.configuration.Config) Closeable(java.io.Closeable) OutputStream(java.io.OutputStream) LifecycleAdapter(org.neo4j.kernel.lifecycle.LifecycleAdapter) RotatingFileOutputStreamSupplier(org.neo4j.logging.RotatingFileOutputStreamSupplier) Monitors(org.neo4j.kernel.monitoring.Monitors) File(java.io.File)

Aggregations

Closeable (java.io.Closeable)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1 Config (org.neo4j.kernel.configuration.Config)1 JobScheduler (org.neo4j.kernel.impl.util.JobScheduler)1 LifecycleAdapter (org.neo4j.kernel.lifecycle.LifecycleAdapter)1 Monitors (org.neo4j.kernel.monitoring.Monitors)1 FormattedLog (org.neo4j.logging.FormattedLog)1 Log (org.neo4j.logging.Log)1 RotatingFileOutputStreamSupplier (org.neo4j.logging.RotatingFileOutputStreamSupplier)1