Java Code Examples for java.util.logging.Handler#getFormatter()
The following examples show how to use
java.util.logging.Handler#getFormatter() .
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: JsonFormatterDefaultConfigTest.java From quarkus with Apache License 2.0 | 6 votes |
public static JsonFormatter getJsonFormatter() { LogManager logManager = LogManager.getLogManager(); assertThat(logManager).isInstanceOf(org.jboss.logmanager.LogManager.class); DelayedHandler delayedHandler = InitialConfigurator.DELAYED_HANDLER; assertThat(Logger.getLogger("").getHandlers()).contains(delayedHandler); assertThat(delayedHandler.getLevel()).isEqualTo(Level.ALL); Handler handler = Arrays.stream(delayedHandler.getHandlers()) .filter(h -> (h instanceof ConsoleHandler)) .findFirst().orElse(null); assertThat(handler).isNotNull(); assertThat(handler.getLevel()).isEqualTo(Level.WARNING); Formatter formatter = handler.getFormatter(); assertThat(formatter).isInstanceOf(JsonFormatter.class); return (JsonFormatter) formatter; }
Example 2
Source File: SyslogHandlerTest.java From quarkus with Apache License 2.0 | 6 votes |
@Test public void syslogOutputTest() { Handler handler = getHandler(SyslogHandler.class); assertThat(handler.getLevel()).isEqualTo(Level.WARNING); Formatter formatter = handler.getFormatter(); assertThat(formatter).isInstanceOf(PatternFormatter.class); PatternFormatter patternFormatter = (PatternFormatter) formatter; assertThat(patternFormatter.getPattern()).isEqualTo("%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n"); SyslogHandler syslogHandler = (SyslogHandler) handler; assertThat(syslogHandler.getPort()).isEqualTo(5140); assertThat(syslogHandler.getAppName()).isEqualTo(getProcessName()); assertThat(syslogHandler.getHostname()).isEqualTo(getQualifiedHostName()); assertThat(syslogHandler.getFacility()).isEqualTo(SyslogHandler.Facility.USER_LEVEL); assertThat(syslogHandler.getSyslogType()).isEqualTo(SyslogHandler.SyslogType.RFC5424); assertThat(syslogHandler.getProtocol()).isEqualTo(SyslogHandler.Protocol.TCP); assertThat(syslogHandler.isUseCountingFraming()).isEqualTo(false); assertThat(syslogHandler.isTruncate()).isEqualTo(true); assertThat(syslogHandler.isBlockOnReconnect()).isEqualTo(false); }
Example 3
Source File: PeriodicRotatingLoggingTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test public void periodicRotatingConfigurationTest() { Handler handler = getHandler(PeriodicRotatingFileHandler.class); assertThat(handler.getLevel()).isEqualTo(Level.INFO); Formatter formatter = handler.getFormatter(); assertThat(formatter).isInstanceOf(PatternFormatter.class); PatternFormatter patternFormatter = (PatternFormatter) formatter; assertThat(patternFormatter.getPattern()).isEqualTo("%d{HH:mm:ss} %-5p [%c{2.}]] (%t) %s%e%n"); }
Example 4
Source File: PeriodicSizeRotatingLoggingTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test public void periodicSizeRotatingConfigurationTest() { Handler handler = getHandler(PeriodicSizeRotatingFileHandler.class); assertThat(handler.getLevel()).isEqualTo(Level.INFO); Formatter formatter = handler.getFormatter(); assertThat(formatter).isInstanceOf(PatternFormatter.class); PatternFormatter patternFormatter = (PatternFormatter) formatter; assertThat(patternFormatter.getPattern()).isEqualTo("%d{HH:mm:ss} %-5p [%c{2.}]] (%t) %s%e%n"); PeriodicSizeRotatingFileHandler periodicSizeRotatingFileHandler = (PeriodicSizeRotatingFileHandler) handler; assertThat(periodicSizeRotatingFileHandler.isRotateOnBoot()).isFalse(); }
Example 5
Source File: SizeRotatingLoggingTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test public void sizeRotatingConfigurationTest() { Handler handler = getHandler(SizeRotatingFileHandler.class); assertThat(handler.getLevel()).isEqualTo(Level.INFO); Formatter formatter = handler.getFormatter(); assertThat(formatter).isInstanceOf(PatternFormatter.class); PatternFormatter patternFormatter = (PatternFormatter) formatter; assertThat(patternFormatter.getPattern()).isEqualTo("%d{HH:mm:ss} %-5p [%c{2.}]] (%t) %s%e%n"); SizeRotatingFileHandler sizeRotatingFileHandler = (SizeRotatingFileHandler) handler; assertThat(sizeRotatingFileHandler.isRotateOnBoot()).isTrue(); }
Example 6
Source File: PeriodicSizeRotatingLoggingRotateOnBootTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test public void periodicSizeRotatingConfigurationTest() { Handler handler = getHandler(PeriodicSizeRotatingFileHandler.class); assertThat(handler.getLevel()).isEqualTo(Level.INFO); Formatter formatter = handler.getFormatter(); assertThat(formatter).isInstanceOf(PatternFormatter.class); PatternFormatter patternFormatter = (PatternFormatter) formatter; assertThat(patternFormatter.getPattern()).isEqualTo("%d{HH:mm:ss} %-5p [%c{2.}]] (%t) %s%e%n"); PeriodicSizeRotatingFileHandler periodicSizeRotatingFileHandler = (PeriodicSizeRotatingFileHandler) handler; assertThat(periodicSizeRotatingFileHandler.isRotateOnBoot()).isTrue(); }
Example 7
Source File: ConsoleHandlerTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test public void consoleOutputTest() { Handler handler = getHandler(ConsoleHandler.class); assertThat(handler).isNotNull(); assertThat(handler.getLevel()).isEqualTo(Level.WARNING); Formatter formatter = handler.getFormatter(); assertThat(formatter).isInstanceOf(PatternFormatter.class); PatternFormatter patternFormatter = (PatternFormatter) formatter; assertThat(patternFormatter.getPattern()).isEqualTo("%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n"); }
Example 8
Source File: FileHandlerTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test public void fileOutputTest() { Handler handler = getHandler(FileHandler.class); assertThat(handler.getLevel()).isEqualTo(Level.INFO); Formatter formatter = handler.getFormatter(); assertThat(formatter).isInstanceOf(PatternFormatter.class); PatternFormatter patternFormatter = (PatternFormatter) formatter; assertThat(patternFormatter.getPattern()).isEqualTo("%d{HH:mm:ss} %-5p [%c{2.}]] (%t) %s%e%n"); }
Example 9
Source File: LoggingHelper.java From twister2 with Apache License 2.0 | 5 votes |
private static void updateComponentId(String component) { Logger rootLogger = Logger.getLogger(""); for (Handler handler : rootLogger.getHandlers()) { Formatter formatter = handler.getFormatter(); if (formatter instanceof Twister2LogFormatter) { ((Twister2LogFormatter) formatter).setComponentName(component); } } }
Example 10
Source File: LoggingManager.java From selenium with Apache License 2.0 | 5 votes |
public static void overrideSimpleFormatterWithTerseOneForConsoleHandler( Logger logger, boolean debugMode) { for (Handler handler : logger.getHandlers()) { if (handler instanceof ConsoleHandler) { final Formatter formatter; formatter = handler.getFormatter(); if (formatter instanceof SimpleFormatter) { final StdOutHandler stdOutHandler; final Level originalLevel; /* * DGF - Nobody likes the SimpleFormatter; surely they wanted our terse formatter instead. */ originalLevel = handler.getLevel(); handler.setFormatter(new TerseFormatter()); handler.setLevel(Level.WARNING); /* * Furthermore, we all want DEBUG/INFO on stdout and WARN/ERROR on stderr */ stdOutHandler = new StdOutHandler(); stdOutHandler.setFormatter(new TerseFormatter()); stdOutHandler.setFilter(new MaxLevelFilter(Level.INFO)); stdOutHandler.setLevel(originalLevel); logger.addHandler(stdOutHandler); if (debugMode) { if (originalLevel.intValue() > Level.FINE.intValue()) { stdOutHandler.setLevel(Level.FINE); } } } } } }