Search in sources :

Example 76 with LogRecord

use of java.util.logging.LogRecord in project buck by facebook.

the class JavaUtilsLoggingBuildListener method ruleFinished.

@Subscribe
public void ruleFinished(BuildRuleEvent.Finished finished) {
    LogRecord record = new LogRecord(LEVEL, finished.toLogMessage());
    record.setMillis(finished.getTimestamp());
    LOG.log(record);
}
Also used : LogRecord(java.util.logging.LogRecord) Subscribe(com.google.common.eventbus.Subscribe)

Example 77 with LogRecord

use of java.util.logging.LogRecord in project buck by facebook.

the class JavaUtilsLoggingBuildListener method ruleSuspended.

@Subscribe
public void ruleSuspended(BuildRuleEvent.Suspended suspended) {
    LogRecord record = new LogRecord(LEVEL, suspended.toString());
    record.setMillis(suspended.getTimestamp());
    LOG.log(record);
}
Also used : LogRecord(java.util.logging.LogRecord) Subscribe(com.google.common.eventbus.Subscribe)

Example 78 with LogRecord

use of java.util.logging.LogRecord in project buck by facebook.

the class MemoryHandler method publish.

@Override
public void publish(LogRecord record) {
    if (!isLoggable(record)) {
        return;
    }
    List<LogRecord> recordsToLog = null;
    synchronized (buffer) {
        int ix = (start + count) % buffer.length;
        buffer[ix] = record;
        if (count < buffer.length) {
            count++;
        } else {
            start++;
            start %= buffer.length;
        }
        if (record.getLevel().intValue() >= pushLevel.intValue()) {
            recordsToLog = new ArrayList<>();
            while (count > 0) {
                LogRecord oldRecord = buffer[start];
                recordsToLog.add(oldRecord);
                buffer[start] = null;
                start++;
                start %= buffer.length;
                count--;
            }
        }
    }
}
Also used : LogRecord(java.util.logging.LogRecord)

Example 79 with LogRecord

use of java.util.logging.LogRecord in project hudson-2.x by hudson.

the class LogRecorderManager method doRss.

/**
     * Renders the given log recorders as RSS.
     */
/*package*/
static void doRss(StaplerRequest req, StaplerResponse rsp, String recorderName, List<LogRecord> logs) throws IOException, ServletException {
    // filter log records based on the log level
    String level = req.getParameter("level");
    if (level != null) {
        Level threshold = Level.parse(level);
        List<LogRecord> filtered = new ArrayList<LogRecord>();
        for (LogRecord r : logs) {
            if (r.getLevel().intValue() >= threshold.intValue())
                filtered.add(r);
        }
        logs = filtered;
    }
    RSS.forwardToRss("Hudson " + recorderName + " log", "", logs, new FeedAdapter<LogRecord>() {

        public String getEntryTitle(LogRecord entry) {
            return entry.getMessage();
        }

        public String getEntryUrl(LogRecord entry) {
            // TODO: one URL for one log entry?
            return "log";
        }

        public String getEntryID(LogRecord entry) {
            return String.valueOf(entry.getSequenceNumber());
        }

        public String getEntryDescription(LogRecord entry) {
            return Functions.printLogRecord(entry);
        }

        public Calendar getEntryTimestamp(LogRecord entry) {
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTimeInMillis(entry.getMillis());
            return cal;
        }

        public String getEntryAuthor(LogRecord entry) {
            return Mailer.descriptor().getAdminAddress();
        }
    }, req, rsp);
}
Also used : LogRecord(java.util.logging.LogRecord) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar) Level(java.util.logging.Level)

Example 80 with LogRecord

use of java.util.logging.LogRecord in project jersey by jersey.

the class ExtendedExceptionMapperTest method test.

@Test
public void test() {
    // Format of first param: [exception thrown]-[exception mappers which will return true in isMappable]
    _test("A-A", "A");
    _test("A-AB", "A");
    _test("A-ABC", "A");
    _test("A-ABCD", "A");
    _test("A-ABCDE", "A");
    _test("A-ABCDEX", "A");
    _test("A-C", null);
    _test("A-D", null);
    _test("A-E", null);
    _test("A-D", null);
    _test("A-BCDEX", null);
    _test("A-00000", null);
    _test("A-X", null);
    _test("B-A", "A");
    _test("B-B", "B");
    _test("B-AB", "B");
    _test("B-ABC", "B");
    _test("B-ABCD", "B");
    _test("B-ABCDE", "B");
    _test("B-ABCDEX", "B");
    _test("B-C", null);
    _test("B-D", null);
    _test("B-E", null);
    _test("B-CDEX", null);
    _test("B-X", null);
    _test("B-000", null);
    // C is not an ExtendedExceptionMapper but just ExceptionMapper (always mappable)
    _test("C-C", "C");
    _test("C-A", "C");
    _test("C-AB", "C");
    _test("C-ABC", "C");
    _test("C-AEX", "C");
    _test("C-00000", "C");
    _test("C-ABCDEX", "C");
    _test("C-E", "C");
    _test("C-DE", "C");
    _test("C-D", "C");
    _test("C-X", "C");
    _test("D-000", "C");
    _test("D-A", "C");
    _test("D-B", "C");
    _test("D-C", "C");
    _test("D-D", "D");
    _test("D-E", "C");
    _test("D-ABC", "C");
    _test("D-ABCEX", "C");
    _test("D-ABCDEX", "D");
    _test("D-DE", "D");
    _test("D-ABEX", "C");
    _test("D-AEX", "C");
    _test("D-X", "C");
    _test("E-A", "C");
    _test("E-B", "C");
    _test("E-C", "C");
    _test("E-D", "D");
    _test("E-E", "E");
    _test("E-ABC", "C");
    _test("E-ABCD", "D");
    _test("E-ABCDE", "E");
    _test("E-ABCDEX", "E");
    _test("E-DE", "E");
    _test("E-X", "C");
    _test("E-000000", "C");
    _test("X-A", null);
    _test("X-ABCDE", null);
    _test("X-ABCDEX", "X");
    _test("X-X", "X");
    // Check logs. (??)
    for (final LogRecord logRecord : getLoggedRecords()) {
        for (final String message : new String[] { LocalizationMessages.ERROR_EXCEPTION_MAPPING_ORIGINAL_EXCEPTION(), LocalizationMessages.ERROR_EXCEPTION_MAPPING_THROWN_TO_CONTAINER() }) {
            if (logRecord.getMessage().contains(message) && logRecord.getLevel().intValue() > Level.FINE.intValue()) {
                fail("Log message should be logged at lower (FINE) level: " + message);
            }
        }
    }
}
Also used : LogRecord(java.util.logging.LogRecord) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Aggregations

LogRecord (java.util.logging.LogRecord)370 Logger (java.util.logging.Logger)62 Test (org.junit.Test)61 Handler (java.util.logging.Handler)24 File (java.io.File)21 IOException (java.io.IOException)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)16 Level (java.util.logging.Level)16 StreamHandler (java.util.logging.StreamHandler)14 ConsoleHandler (java.util.logging.ConsoleHandler)13 ArrayList (java.util.ArrayList)12 Properties (java.util.Properties)11 Config (com.sun.enterprise.config.serverbeans.Config)10 Formatter (java.util.logging.Formatter)10 SimpleFormatter (java.util.logging.SimpleFormatter)10 LogRecordCollectingLogger (alma.acs.testsupport.LogRecordCollectingLogger)9 BlockingQueueHandler (fish.payara.nucleus.notification.BlockingQueueHandler)9 ActionReport (org.glassfish.api.ActionReport)9 HashMap (java.util.HashMap)7 Subscribe (com.google.common.eventbus.Subscribe)6