Java Code Examples for java.util.logging.Handler#publish()
The following examples show how to use
java.util.logging.Handler#publish() .
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: LogUtilsTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testLogNoParamsWithThrowable() { Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testLogNoParamsWithThrowable"); Handler handler = EasyMock.createNiceMock(Handler.class); Exception ex = new Exception("x"); LogRecord record = new LogRecord(Level.SEVERE, "subbed in {0} only"); record.setThrown(ex); EasyMock.reportMatcher(new LogRecordMatcher(record)); handler.publish(record); EasyMock.replay(handler); synchronized (log) { log.addHandler(handler); // handler called *after* localization of message LogUtils.log(log, Level.SEVERE, "SUB1_MSG", ex); EasyMock.verify(handler); log.removeHandler(handler); } }
Example 2
Source File: LogUtilsTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testLogParamSubstitutionWithThrowable() throws Exception { Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testLogParamSubstitutionWithThrowable"); Handler handler = EasyMock.createNiceMock(Handler.class); Exception ex = new Exception(); LogRecord record = new LogRecord(Level.SEVERE, "subbed in 1 only"); record.setThrown(ex); EasyMock.reportMatcher(new LogRecordMatcher(record)); handler.publish(record); EasyMock.replay(handler); synchronized (log) { log.addHandler(handler); LogUtils.log(log, Level.SEVERE, "SUB1_MSG", ex, 1); EasyMock.verify(handler); log.removeHandler(handler); } }
Example 3
Source File: LogUtilsTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testLogParamsSubstitutionWithThrowable() throws Exception { Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testLogParamsSubstitutionWithThrowable"); Handler handler = EasyMock.createNiceMock(Handler.class); Exception ex = new Exception(); LogRecord record = new LogRecord(Level.SEVERE, "subbed in 4 & 3"); record.setThrown(ex); EasyMock.reportMatcher(new LogRecordMatcher(record)); handler.publish(record); EasyMock.replay(handler); synchronized (log) { log.addHandler(handler); LogUtils.log(log, Level.SEVERE, "SUB2_MSG", ex, new Object[] {3, 4}); EasyMock.verify(handler); log.removeHandler(handler); } }
Example 4
Source File: AbstractBackend.java From flogger with Apache License 2.0 | 5 votes |
private static void publish(Logger logger, LogRecord record) { // Annoyingly this method appears to copy the array every time it is called, but there's // nothing much we can do about this (and there could be synchronization issues even if we // could access things directly because handlers can be changed at any time). Most of the // time this returns the singleton empty array however, so it's not as bad as all that. for (Handler handler : logger.getHandlers()) { handler.publish(record); } if (logger.getUseParentHandlers()) { logger = logger.getParent(); if (logger != null) { publish(logger, record); } } }
Example 5
Source File: LevelHandler.java From baratine with GNU General Public License v2.0 | 5 votes |
/** * Publishes the record. */ public void publish(LogRecord record) { if (! isLoggable(record)) return; int level = getLevel().intValue(); for (int i = 0; i < _handlers.length; i++) { Handler handler = _handlers[i]; if (level <= handler.getLevel().intValue()) handler.publish(record); } }
Example 6
Source File: LogUtilsTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testHandleL7dMessage() throws Exception { Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testHandleL7dMessage"); Handler handler = EasyMock.createNiceMock(Handler.class); log.addHandler(handler); // handler called *before* localization of message LogRecord record = new LogRecord(Level.WARNING, "FOOBAR_MSG"); record.setResourceBundle(log.getResourceBundle()); EasyMock.reportMatcher(new LogRecordMatcher(record)); handler.publish(record); EasyMock.replay(handler); log.log(Level.WARNING, "FOOBAR_MSG"); EasyMock.verify(handler); log.removeHandler(handler); }
Example 7
Source File: LogUtilsTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testLogNoParamsOrThrowable() { Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testLogNoParamsOrThrowable"); Handler handler = EasyMock.createNiceMock(Handler.class); log.addHandler(handler); // handler called *after* localization of message LogRecord record = new LogRecord(Level.SEVERE, "subbed in {0} only"); EasyMock.reportMatcher(new LogRecordMatcher(record)); handler.publish(record); EasyMock.replay(handler); LogUtils.log(log, Level.SEVERE, "SUB1_MSG"); EasyMock.verify(handler); log.removeHandler(handler); }
Example 8
Source File: TopLogging.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void publish(LogRecord record) { for (Handler h : instances) { h.publish(record); } }
Example 9
Source File: LogsTooEarlyTest.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void publish(LogRecord record) { for (Handler h : Lookup.getDefault().lookupAll(Handler.class)) { h.publish(record); } }
Example 10
Source File: Slf4jLogger.java From cxf with Apache License 2.0 | 4 votes |
@Override protected void internalLogFormatted(String msg, LogRecord record) { Level level = record.getLevel(); Throwable t = record.getThrown(); Handler[] targets = getHandlers(); if (targets != null) { for (Handler h : targets) { h.publish(record); } } if (!getUseParentHandlers()) { return; } /* * As we can not use a "switch ... case" block but only a "if ... else if ..." block, the order of the * comparisons is important. We first try log level FINE then INFO, WARN, FINER, etc */ if (Level.FINE.equals(level)) { if (locationAwareLogger == null) { logger.debug(msg, t); } else { locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t); } } else if (Level.INFO.equals(level)) { if (locationAwareLogger == null) { logger.info(msg, t); } else { locationAwareLogger.log(null, FQCN, LocationAwareLogger.INFO_INT, msg, null, t); } } else if (Level.WARNING.equals(level)) { if (locationAwareLogger == null) { logger.warn(msg, t); } else { locationAwareLogger.log(null, FQCN, LocationAwareLogger.WARN_INT, msg, null, t); } } else if (Level.FINER.equals(level)) { if (locationAwareLogger == null) { logger.trace(msg, t); } else { locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t); } } else if (Level.FINEST.equals(level)) { if (locationAwareLogger == null) { logger.trace(msg, t); } else { locationAwareLogger.log(null, FQCN, LocationAwareLogger.TRACE_INT, msg, null, t); } } else if (Level.ALL.equals(level)) { // should never occur, all is used to configure java.util.logging // but not accessible by the API Logger.xxx() API if (locationAwareLogger == null) { logger.error(msg, t); } else { locationAwareLogger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, t); } } else if (Level.SEVERE.equals(level)) { if (locationAwareLogger == null) { logger.error(msg, t); } else { locationAwareLogger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, t); } } else if (Level.CONFIG.equals(level)) { if (locationAwareLogger == null) { logger.debug(msg, t); } else { locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t); } } else if (Level.OFF.equals(level)) { // don't log } }
Example 11
Source File: Slf4jLogger.java From tomee with Apache License 2.0 | 4 votes |
@Override protected void internalLogFormatted(final String msg, final LogRecord record) { final Level level = record.getLevel(); final Throwable t = record.getThrown(); final Handler[] targets = getHandlers(); if (targets != null) { for (final Handler h : targets) { h.publish(record); } } if (!getUseParentHandlers()) { return; } /* * As we can not use a "switch ... case" block but only a "if ... else if ..." block, the order of the * comparisons is important. We first try log level FINE then INFO, WARN, FINER, etc */ if (Level.FINE.equals(level)) { if (locationAwareLogger == null) { logger.debug(msg, t); } else { locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t); } } else if (Level.INFO.equals(level)) { if (locationAwareLogger == null) { logger.info(msg, t); } else { locationAwareLogger.log(null, FQCN, LocationAwareLogger.INFO_INT, msg, null, t); } } else if (Level.WARNING.equals(level)) { if (locationAwareLogger == null) { logger.warn(msg, t); } else { locationAwareLogger.log(null, FQCN, LocationAwareLogger.WARN_INT, msg, null, t); } } else if (Level.FINER.equals(level)) { if (locationAwareLogger == null) { logger.trace(msg, t); } else { locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t); } } else if (Level.FINEST.equals(level)) { if (locationAwareLogger == null) { logger.trace(msg, t); } else { locationAwareLogger.log(null, FQCN, LocationAwareLogger.TRACE_INT, msg, null, t); } } else if (Level.ALL.equals(level)) { // should never occur, all is used to configure java.util.logging // but not accessible by the API Logger.xxx() API if (locationAwareLogger == null) { logger.error(msg, t); } else { locationAwareLogger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, t); } } else if (Level.SEVERE.equals(level)) { if (locationAwareLogger == null) { logger.error(msg, t); } else { locationAwareLogger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, t); } } else if (Level.CONFIG.equals(level)) { if (locationAwareLogger == null) { logger.debug(msg, t); } else { locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t); } } // don't log if Level.OFF }
Example 12
Source File: ConsoleHandlerTest.java From buck with Apache License 2.0 | 4 votes |
private static void publishAndFlush(Handler handler, LogRecord logRecord) { handler.publish(logRecord); handler.flush(); }