@Test public void test25PercentSamplingThroughIsLoggable() { Logger mockLogger = EasyMock.createMock(Logger.class); reset(mockLogger); expect(mockLogger.getName()).andReturn("loggerName").anyTimes(); expect(mockLogger.isLoggable(anyObject())).andReturn(true).anyTimes(); replay(mockLogger); SamplingLogger testLog1 = new SamplingLogger(ReportableEntityType.POINT, mockLogger, 0.25, false, null); int count = 0; for (int i = 0; i < 1000; i++) { if (testLog1.isLoggable(Level.FINEST)) count++; } assertTrue(count < 300); assertTrue(count > 200); count = 0; for (int i = 0; i < 1000; i++) { if (testLog1.isLoggable(Level.FINER)) count++; } assertEquals(1000, count); }
@Override public boolean isLoggable(Level level) { if (level == Level.FINEST) { return (alwaysActive || loggingActive.get()) && (samplingRate >= 1.0d || (samplingRate > 0.0d && RANDOM.nextDouble() < samplingRate)); } else { return delegate.isLoggable(level); } }
SamplingLogger extends DelegatingLogger { @Override public boolean isLoggable(Level level) { if (level == Level.FINEST) { return (alwaysActive || loggingActive.get()) && (samplingRate >= 1.0d || (samplingRate > 0.0d && RANDOM.nextDouble() < samplingRate)); } else { return delegate.isLoggable(level); } } }
SamplingLogger extends DelegatingLogger { @Override public boolean isLoggable(Level level) { if (level == Level.FINEST) { return (alwaysActive || loggingActive.get()) && (samplingRate >= 1.0d || (samplingRate > 0.0d && RANDOM.nextDouble() < samplingRate)); } else { return delegate.isLoggable(level); } } SamplingLogger(ReportableEntityType entityType,
                        Logger delegate,
                        double samplingRate,
                        boolean alwaysActive,
                        @Nullable Consumer<String> statusChangeConsumer); }
SamplingLogger extends DelegatingLogger { @Override public boolean isLoggable(Level level) { if (level == Level.FINEST) { return (alwaysActive || loggingActive.get()) && (samplingRate >= 1.0d || (samplingRate > 0.0d && RANDOM.nextDouble() < samplingRate)); } else { return delegate.isLoggable(level); } } SamplingLogger(ReportableEntityType entityType,
                        Logger delegate,
                        double samplingRate,
                        boolean alwaysActive,
                        @Nullable Consumer<String> statusChangeConsumer); @Override boolean isLoggable(Level level); @Override void log(Level level, String message); }
SamplingLogger extends DelegatingLogger { @Override public boolean isLoggable(Level level) { if (level == Level.FINEST) { return (alwaysActive || loggingActive.get()) && (samplingRate >= 1.0d || (samplingRate > 0.0d && RANDOM.nextDouble() < samplingRate)); } else { return delegate.isLoggable(level); } } SamplingLogger(ReportableEntityType entityType,
                        Logger delegate,
                        double samplingRate,
                        boolean alwaysActive,
                        @Nullable Consumer<String> statusChangeConsumer); @Override boolean isLoggable(Level level); @Override void log(Level level, String message);  }