hudson.util.RingBufferLogHandler Java Examples

The following examples show how to use hudson.util.RingBufferLogHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoggerRule.java    From jenkins-test-harness with MIT License 6 votes vote down vote up
/**
 * Initializes log record capture, in addition to merely printing it.
 * This allows you to call {@link #getRecords} and/or {@link #getMessages} later.
 * @param maximum the maximum number of records to keep (any further will be discarded)
 * @return this rule, for convenience
 */
public LoggerRule capture(int maximum) {
    messages = new ArrayList<>();
    ringHandler = new RingBufferLogHandler(maximum) {
        final Formatter f = new SimpleFormatter(); // placeholder instance for what should have been a static method perhaps
        @Override
        public synchronized void publish(LogRecord record) {
            super.publish(record);
            String message = f.formatMessage(record);
            Throwable x = record.getThrown();
            synchronized (messages) {
                messages.add(message == null && x != null ? x.toString() : message);
            }
        }
    };
    ringHandler.setLevel(Level.ALL);
    for (Logger logger : loggers.keySet()) {
        logger.addHandler(ringHandler);
    }
    return this;
}
 
Example #2
Source File: ApiRateLimitCheckerTest.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    github = Connector.connect("http://localhost:" + githubApi.port(), null);

    resetAllScenarios();

    handler = new RingBufferLogHandler(1000);
    final Logger logger = Logger.getLogger(getClass().getName());
    logger.addHandler(handler);
    listener = new LogTaskListener(logger, Level.INFO);

    // Set the random to a known state for testing
    ApiRateLimitChecker.setEntropy(entropy);

    // Default the expiration window to a small but measurable time for testing
    ApiRateLimitChecker.setExpirationWaitMillis(20);

    // Default the notification interval to a small but measurable time for testing
    ApiRateLimitChecker. setNotificationWaitMillis(60);
}