@Test void shouldAllowLevelToBeChanged() { // Given StringWriter writer = new StringWriter(); FormattedLog log = newFormattedLog( writer, Level.INFO); // When log.info( "No, it's when there's nothing wrong with you, but you hurt anyway. You get it?" ); log.setLevel( Level.WARN ); log.info( "I know now why you cry. But it's something I can never do." ); log.setLevel( Level.DEBUG ); log.info( "There's 215 bones in the human body. That's one." ); // Then assertThat( writer.toString(), equalTo( format( "%s%n%s%n", "1984-10-26 04:23:24.343+0000 INFO [test] No, it's when there's nothing wrong with you, but " + "you hurt anyway. You get it?", "1984-10-26 04:23:24.343+0000 INFO [test] There's 215 bones in the human body. That's one." ) ) ); }
@Nonnull @Override public Logger debugLogger() { return isDebugEnabled() ? this.debugLogger : NullLogger.getInstance(); }
private FormattedLog buildLog( String context, Level level ) { return new FormattedLog( writerSupplier, zoneId, this, renderContext ? context : null, level, autoFlush ); }
@Override public void outputFileCreated( OutputStream newStream ) { FormattedLogProvider logProvider = internalLogBuilder.toOutputStream( newStream ); logProvider.getLog( StoreLogService.class ).info( "Opened new internal log file" ); rotationListener.accept( logProvider ); }
@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(); }
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 shouldNeverStepMoreThanDistanceOne( SpaceFillingCurve curve, int level, int badnessThresholdPercentage ) { int badCount = 0; long[] previous = null; for ( long derivedValue = 0; derivedValue < curve.getValueWidth(); derivedValue++ ) { long[] point = curve.normalizedCoordinateFor( derivedValue, level ); if ( previous != null ) { double distance = 0; for ( int i = 0; i < point.length; i++ ) { distance += Math.pow( point[i] - previous[i], 2 ); } distance = Math.sqrt( distance ); if ( distance > 1.0 ) { badCount++; } } previous = point; } int badness = (int) (100 * badCount / (curve.getValueWidth() - 1)); assertThat( "Bad distance percentage should never be greater than " + badnessThresholdPercentage + "%", badness, lessThanOrEqualTo( badnessThresholdPercentage ) ); logger.debug( String.format( "Bad distance count for level: %d (%d/%d = %d%%)", level, badCount, curve.getValueWidth() - 1, badness ) ); }
private ConsistencySummaryStatistics check( DirectStoreAccess stores ) throws ConsistencyCheckIncompleteException { Config config = config(); FullCheck checker = new FullCheck( config, ProgressMonitorFactory.NONE, fixture.getAccessStatistics(), defaultConsistencyCheckThreadsNumber() ); return checker.execute( stores, FormattedLog.toOutputStream( System.out ), ( report, method, message ) -> { Set<String> types = allReports.get( report ); assert types != null; types.remove( method ); } ); }
@Nonnull @Override public Logger infoLogger() { return isInfoEnabled() ? this.infoLogger : NullLogger.getInstance(); }
@Nonnull @Override public Logger errorLogger() { return isErrorEnabled() ? this.errorLogger : NullLogger.getInstance(); }
@Override public void rotationCompleted( OutputStream newStream ) { FormattedLogProvider logProvider = internalLogBuilder.toOutputStream( newStream ); logProvider.getLog( StoreLogService.class ).info( "Rotated internal log file" ); }
@Override public String extract( String providerId ) { StringWriter stringWriter = new StringWriter(); ZoneId zoneId = config.get( GraphDatabaseSettings.db_timezone ).getZoneId(); FormattedLog.Builder logBuilder = FormattedLog.withZoneId( zoneId ); diagnostics.extract( providerId, logBuilder.toWriter( stringWriter ) ); return stringWriter.toString(); } }
/** * This test can be uses to reproduce a bug with a single search envelope, if {@link #shouldHaveReasonableCoveredArea()} * fails an assertion. It should be disabled by default. */ @Disabled public void debugSingle() { final int xmin = -100; final int xmax = 100; final int ymin = -100; final int ymax = 100; final int level = 1; final double xStart = -0x1.9p6; final double xEnd = -0x1.8ffffd60e94eep6; final double yStart = 0x1.8ff5c28f5c28ep6; final double yEnd = 0x1.8ffffffffffffp6; Envelope envelope = new Envelope( xmin, xmax, ymin, ymax ); HilbertSpaceFillingCurve2D curve = new HilbertSpaceFillingCurve2D( envelope, level ); Envelope searchEnvelope = new Envelope( xStart, xEnd, yStart, yEnd ); HistogramMonitor monitor = new HistogramMonitor( curve.getMaxLevel() ); List<SpaceFillingCurve.LongRange> ranges = curve.getTilesIntersectingEnvelope( searchEnvelope, new StandardConfiguration(), monitor ); logger.debug( String.format( "Results for level %d, with x=[%f,%f] y=[%f,%f]\n", level, xStart, xEnd, yStart, yEnd ) ); logger.debug( String.format( "Search size vs covered size: %d vs %d\n", monitor.getSearchArea(), monitor.getCoveredArea() ) ); logger.debug( "Ranges: " + ranges.size() ); int[] counts = monitor.getCounts(); for ( int i = 0; i <= curve.getMaxLevel(); i++ ) { logger.debug( "\t" + i + "\t" + counts[i] ); } }
private ConsistencySummaryStatistics check( DirectStoreAccess stores ) throws ConsistencyCheckIncompleteException { Config config = config( taskExecutionOrder ); FullCheck checker = new FullCheck( config, ProgressMonitorFactory.NONE ); return checker.execute( stores, FormattedLog.toOutputStream( out ) ); }
@Nonnull @Override public Logger infoLogger() { return isInfoEnabled() ? this.infoLogger : NullLogger.getInstance(); }
@Nonnull @Override public Logger errorLogger() { return isErrorEnabled() ? this.errorLogger : NullLogger.getInstance(); }
@Override public void rotationError( Exception e, OutputStream outStream ) { FormattedLogProvider logProvider = internalLogBuilder.toOutputStream( outStream ); logProvider.getLog( StoreLogService.class ).info( "Rotation of internal log file failed:", e ); } } );
@Override public synchronized void init() { // This set of settings are currently not dynamic: currentLogTimeZone = config.get( GraphDatabaseSettings.db_timezone ).getZoneId(); logBuilder = FormattedLog.withZoneId( currentLogTimeZone ); currentQueryLogFile = config.get( GraphDatabaseSettings.log_queries_filename ); updateSettings(); registerDynamicSettingUpdater( GraphDatabaseSettings.log_queries ); registerDynamicSettingUpdater( GraphDatabaseSettings.log_queries_threshold ); registerDynamicSettingUpdater( GraphDatabaseSettings.log_queries_rotation_threshold ); registerDynamicSettingUpdater( GraphDatabaseSettings.log_queries_max_archives ); }
@Test void shouldSetLevelForLogWithMatchingContext() { // Given StringWriter writer = new StringWriter(); FormattedLogProvider logProvider = newFormattedLogProvider( writer, "java.io.StringWriter", Level.DEBUG ); // When FormattedLog stringWriterLog = logProvider.getLog( StringWriter.class ); FormattedLog otherClassLog = logProvider.getLog( PrintWriter.class ); FormattedLog matchingNamedLog = logProvider.getLog( "java.io.StringWriter" ); FormattedLog nonMatchingNamedLog = logProvider.getLog( "java.io.Foo" ); // Then assertThat( stringWriterLog.isDebugEnabled(), is( true ) ); assertThat( otherClassLog.isDebugEnabled(), is( false ) ); assertThat( matchingNamedLog.isDebugEnabled(), is( true ) ); assertThat( nonMatchingNamedLog.isDebugEnabled(), is( false ) ); }
@Test void shouldGet2DHilbertSearchTilesForCenterRangeAndTraverseToBottom() { TraverseToBottomConfiguration configuration = new TraverseToBottomConfiguration(); Envelope envelope = new Envelope( -8, 8, -8, 8 ); for ( int level = 2; level <= 11; level++ ) // 12 takes 6s, 13 takes 25s, 14 takes 100s, 15 takes over 400s { HilbertSpaceFillingCurve2D curve = new HilbertSpaceFillingCurve2D( envelope, level ); double fullTile = curve.getTileWidth( 0, level ); double halfTile = fullTile / 2.0; Envelope centerWithoutOuterRing = new Envelope( envelope.getMin( 0 ) + fullTile + halfTile, envelope.getMax( 0 ) - fullTile - halfTile, envelope.getMin( 1 ) + fullTile + halfTile, envelope.getMax( 1 ) - fullTile - halfTile ); long start = System.currentTimeMillis(); List<SpaceFillingCurve.LongRange> result = curve.getTilesIntersectingEnvelope( centerWithoutOuterRing, configuration, null ); logger.debug( "Hilbert query at level " + level + " took " + (System.currentTimeMillis() - start) + "ms to produce " + result.size() + " tiles" ); assertTiles( result, tilesNotTouchingOuterRing( curve ).toArray( new SpaceFillingCurve.LongRange[0] ) ); } }