/** * Creates a {@link FormattedLog} instance that writes messages to a {@link Writer}. * * @param writer A {@link Writer} to write to * @return A {@link FormattedLog} instance that writes to the specified Writer */ public FormattedLog toWriter( Writer writer ) { return toPrintWriter( new PrintWriter( writer ) ); }
private static FormattedLog newFormattedLog( StringWriter writer, Level level ) { return FormattedLog .withUTCTimeZone() .withCategory( "test" ) .withLogLevel( level ) .withTimeSupplier( DATE_TIME_SUPPLIER ) .toPrintWriter( Suppliers.singleton( new PrintWriter( writer ) ) ); }
/** * Start creating a {@link FormattedLog} with the specified zoneId from timezone for datestamps in the log * * @param timezone to use * @return a builder for a {@link FormattedLog} * @deprecated use {@link #withZoneId(ZoneId)} */ @Deprecated public static Builder withTimeZone( TimeZone timezone ) { return new Builder().withZoneId( timezone.toZoneId() ); }
/** * Start creating a {@link FormattedLog} without auto flushing. * Use {@link Builder#toOutputStream} to complete. * * @return a builder for a {@link FormattedLog} */ public static Builder withoutAutoFlush() { return new Builder().withoutAutoFlush(); }
/** * Start creating a {@link FormattedLog} with the specified zoneId for datestamps in the log * * @param zoneId to use * @return a builder for a {@link FormattedLog} */ public static Builder withZoneId( ZoneId zoneId ) { return new Builder().withZoneId( zoneId ); }
/** * Start creating a {@link FormattedLog} with UTC timezone for datestamps in the log * * @return a builder for a {@link FormattedLog} */ public static Builder withUTCTimeZone() { return new Builder().withUTCZoneId(); }
/** * Creates a {@link FormattedLog} instance that writes messages to a {@link PrintWriter}. * * @param writer A {@link PrintWriter} to write to * @return A {@link FormattedLog} instance that writes to the specified PrintWriter */ public FormattedLog toPrintWriter( PrintWriter writer ) { return toPrintWriter( Suppliers.singleton( writer ) ); }
/** * Creates a {@link FormattedLog} instance that writes messages to an {@link OutputStream}. * * @param out An {@link OutputStream} to write to * @return A {@link FormattedLog} instance that writes to the specified OutputStream */ public FormattedLog toOutputStream( OutputStream out ) { return toPrintWriter( Suppliers.singleton( OUTPUT_STREAM_CONVERTER.apply( out ) ) ); }
/** * Include the specified category in each output log line * * @param category the category to include ing each output line * @return a builder for a {@link FormattedLog} */ public static Builder withCategory( String category ) { return new Builder().withCategory( category ); }
public SecurityLog( Config config, FileSystemAbstraction fileSystem, Executor executor ) throws IOException { ZoneId logTimeZoneId = config.get( GraphDatabaseSettings.db_timezone ).getZoneId(); File logFile = config.get( SecuritySettings.security_log_filename ); FormattedLog.Builder builder = FormattedLog.withZoneId( logTimeZoneId ); rotatingSupplier = new RotatingFileOutputStreamSupplier( fileSystem, logFile, config.get( SecuritySettings.store_security_log_rotation_threshold ), config.get( SecuritySettings.store_security_log_rotation_delay ).toMillis(), config.get( SecuritySettings.store_security_log_max_archives ), executor ); FormattedLog formattedLog = builder.toOutputStream( rotatingSupplier ); formattedLog.setLevel( config.get( SecuritySettings.security_log_level ) ); this.inner = formattedLog; }
private void buildNonRotatingLog() throws IOException { OutputStream logOutputStream = createOrOpenAsOutputStream( fileSystem, currentQueryLogFile, true ); log = logBuilder.toOutputStream( logOutputStream ); closable = logOutputStream; }
private void buildRotatingLog( long rotationThreshold, int maxArchives ) throws IOException { RotatingFileOutputStreamSupplier rotatingSupplier = new RotatingFileOutputStreamSupplier( fileSystem, currentQueryLogFile, rotationThreshold, 0, maxArchives, scheduler.executor( JobScheduler.Groups.queryLogRotation ) ); log = logBuilder.toOutputStream( rotatingSupplier ); closable = rotatingSupplier; }
@Override public String dumpAll( ) { StringWriter stringWriter = new StringWriter(); ZoneId zoneId = config.get( GraphDatabaseSettings.db_timezone ).getZoneId(); FormattedLog.Builder logBuilder = FormattedLog.withZoneId( zoneId ); diagnostics.dumpAll( logBuilder.toWriter( stringWriter ) ); return stringWriter.toString(); }
/** * Start creating a {@link FormattedLog} with the specified zoneId from timezone for datestamps in the log * * @param timezone to use * @return a builder for a {@link FormattedLog} * @deprecated use {@link #withZoneId(ZoneId)} */ @Deprecated public static Builder withTimeZone( TimeZone timezone ) { return new Builder().withZoneId( timezone.toZoneId() ); }
/** * Creates a {@link FormattedLog} instance that writes messages to a {@link Writer}. * * @param writer A {@link Writer} to write to * @return A {@link FormattedLog} instance that writes to the specified Writer */ public FormattedLog toWriter( Writer writer ) { return toPrintWriter( new PrintWriter( writer ) ); }
/** * Creates a {@link FormattedLog} instance that writes messages to a {@link PrintWriter}. * * @param writer A {@link PrintWriter} to write to * @return A {@link FormattedLog} instance that writes to the specified PrintWriter */ public static FormattedLog toPrintWriter( PrintWriter writer ) { return new Builder().toPrintWriter( writer ); }
/** * Creates a {@link FormattedLog} instance that writes messages to {@link PrintWriter}s obtained from the specified * {@link Supplier}. The PrintWriter is obtained from the Supplier before every log message is written. * * @param writerSupplier A supplier for a {@link PrintWriter} to write to * @return A {@link FormattedLog} instance that writes to the specified PrintWriter */ public static FormattedLog toPrintWriter( Supplier<PrintWriter> writerSupplier ) { return new Builder().toPrintWriter( writerSupplier ); }
/** * Creates a {@link FormattedLog} instance that writes messages to {@link OutputStream}s obtained from the specified * {@link Supplier}. The OutputStream is obtained from the Supplier before every log message is written. * * @param outSupplier A supplier for an output stream to write to * @return A {@link FormattedLog} instance */ public static FormattedLog toOutputStream( Supplier<OutputStream> outSupplier ) { return new Builder().toOutputStream( outSupplier ); }
/** * Start creating a {@link FormattedLog} with the specified log {@link Level} as a default. * Use {@link Builder#toOutputStream} to complete. * * @param level the log level to use as a default * @return a builder for a {@link FormattedLog} */ public static Builder withLogLevel( Level level ) { return new Builder().withLogLevel( level ); }
/** * Start creating a {@link FormattedLog} using the specified object to synchronize on. * Use {@link Builder#toOutputStream} to complete. * * @param lock the object to synchronize on * @return a builder for a {@link FormattedLog} */ public static Builder usingLock( Object lock ) { return new Builder().usingLock( lock ); }