List of usage examples for java.util.logging Logger getHandlers
public Handler[] getHandlers()
From source file:org.eclipse.virgo.medic.impl.LogController.java
private void disableJulConsoleHandler() { // remove console handler from root logger Logger rootLogger = getJavaRootLogger(); Handler[] handlers = rootLogger.getHandlers(); for (Handler handler : handlers) { if (handler instanceof ConsoleHandler) { this.javaConsoleHandler = (ConsoleHandler) handler; rootLogger.removeHandler(handler); }/* ww w. ja v a 2 s .co m*/ } }
From source file:com.kyne.webby.rtk.modules.WebbyRTKModule.java
public WebbyRTKModule(final ModuleMetadata moduleMetadata, final ModuleLoader moduleLoader, final ClassLoader classLoader) { super(moduleMetadata, moduleLoader, classLoader, ToolkitEvent.ON_TOOLKIT_START, ToolkitEvent.NULL_EVENT); //Fix formatting on logger (Based on MilkAdmin) final Logger rootlog = Logger.getLogger(""); for (final Handler h : rootlog.getHandlers()) { //remove all handlers h.setFormatter(new WebbyFormatter()); }/* w w w.j a va 2 s .com*/ LogHelper.initLogger("WebbyRTKModule", "Minecraft"); }
From source file:ste.xtest.logging.BugFreeLoggingByteArrayOutputStream.java
@Test public void log_text_within_max_size() throws Exception { Logger log = getLog(); LoggingByteArrayOutputStream o = new LoggingByteArrayOutputStream(log, Level.INFO, 1000); final char[] TEST_CHARS = new char[] { 'a', 'b', 'c' }; for (char c : TEST_CHARS) { o.write(c);//from ww w . ja v a 2s .co m } ListLogHandler h = (ListLogHandler) log.getHandlers()[0]; for (char c : TEST_CHARS) { LogAssertions.then(h.getRecords()).containsINFO("w> " + c); LogAssertions.then(h.getRecords()).containsINFO(String.format("w> %02x", (int) c)); } final byte[] TEST_DATA = "hello world".getBytes(); o.write(TEST_DATA); LogAssertions.then(h.getRecords()).containsINFO("w> hello world"); LogAssertions.then(h.getRecords()).containsINFO("w> 68656c6c6f20776f726c64"); }
From source file:edu.usu.sdl.openstorefront.web.rest.service.Application.java
@GET @RequireAdmin//from w ww . jav a 2 s. c o m @APIDescription("Gets Loggers in the system") @Produces({ MediaType.APPLICATION_JSON }) @DataType(LoggerView.class) @Path("/loggers") public List<LoggerView> getLoggers() { List<LoggerView> loggers = new ArrayList<>(); List<String> allLoggers = LogManager.getLoggingMXBean().getLoggerNames(); Collections.sort(allLoggers); for (String name : allLoggers) { LoggerView loggerView = new LoggerView(); loggerView.setName(name); Level levelLocal = LogManager.getLogManager().getLogger(name).getLevel(); String levelName = ""; if (levelLocal != null) { levelName = levelLocal.getName(); } loggerView.setLevel(levelName); Logger localLogger = LogManager.getLogManager().getLogger(name); for (Handler handlerLocal : localLogger.getHandlers()) { loggerView.getHandlers() .add(handlerLocal.getClass().getName() + " = " + handlerLocal.getLevel().getName()); } loggers.add(loggerView); } return loggers; }
From source file:net.openhft.chronicle.logger.jul.JulTestBase.java
protected void testChronicleConfiguration(String testId, Class<? extends Handler> expectedHandlerType) throws IOException { setupLogManager(testId);// w w w . j a v a 2s . c o m Logger logger = Logger.getLogger(testId); assertEquals(Level.INFO, logger.getLevel()); assertFalse(logger.getUseParentHandlers()); assertNull(logger.getFilter()); assertNotNull(logger.getHandlers()); assertEquals(1, logger.getHandlers().length); assertTrue(logger.getHandlers()[0].getClass() == expectedHandlerType); }
From source file:tiemens.util.instancer.antlr.InstancerCode.java
/** * If loggingConfigureString is NOT UPPER CASE, * Then// ww w . j a v a 2s . c om * If uselogger's handler(s) are examined and changed if they * would not log at 'newLevel' * * @param newLevel the parsed loggingConfigureString * @param uselogger whose handler(s) we change * @param loggingConfigureString original configuration string */ private void updateHandlers(Level newLevel, Logger uselogger, String loggingConfigureString) { List<Handler> handlers = new ArrayList<Handler>(); Logger walk = uselogger; while (walk != null) { for (Handler add : walk.getHandlers()) { handlers.add(add); } walk = walk.getParent(); } for (Handler handler : handlers) { metaLoggerInfo( "Handler level = " + handler.getLevel().intValue() + "newLevel = " + newLevel.intValue()); if (handler.getLevel().intValue() > newLevel.intValue()) { if (!loggingConfigureString.equals(loggingConfigureString.toUpperCase())) { String note = "Note: setting handler level to '" + loggingConfigureString + "'."; String explain = "Use '" + loggingConfigureString.toUpperCase() + "' to prevent this behavior."; String msg = "Instancer: " + note + " " + explain; metaLoggerInfo(msg); logger.info(msg); handler.setLevel(newLevel); } } } }
From source file:de.crowdcode.kissmda.maven.plugin.KissMdaMojo.java
private void setLoggingLevel() { Logger log = LogManager.getLogManager().getLogger(""); if (loggingLevel == null || loggingLevel.equals("")) { log.setLevel(Level.INFO); } else {//from w w w . j a va 2 s. c o m log.setLevel(loggingLevelMapper.getLevel(loggingLevel)); } for (Handler handler : log.getHandlers()) { if (loggingLevel == null || loggingLevel.equals("")) { handler.setLevel(Level.INFO); } else { handler.setLevel(loggingLevelMapper.getLevel(loggingLevel)); } } }
From source file:org.ScripterRon.JavaBitcoin.RpcHandler.java
/** * Process 'getlog' request//from ww w .j av a 2 s. com * * @return Response as a JSONArray */ private JSONArray getLog() { log.debug("Processing 'getlog'"); JSONArray result = new JSONArray(); Logger logger = Logger.getLogger(""); Handler[] handlers = logger.getHandlers(); for (Handler handler : handlers) { if (handler instanceof MemoryLogHandler) { result.addAll(((MemoryLogHandler) handler).getMessages()); break; } } return result; }
From source file:org.apache.directory.studio.connection.core.io.jndi.LdifSearchLogger.java
/** * Creates a new instance of LdifSearchLogger. *///from ww w .j a v a2 s . co m public LdifSearchLogger() { ConnectionCorePlugin.getDefault().getPluginPreferences() .addPropertyChangeListener(new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (ConnectionCoreConstants.PREFERENCE_SEARCHLOGS_FILE_COUNT.equals(event.getProperty()) || ConnectionCoreConstants.PREFERENCE_SEARCHLOGS_FILE_SIZE .equals(event.getProperty())) { // dispose all loggers/handlers for (Logger logger : loggers.values()) { for (Handler handler : logger.getHandlers()) { handler.close(); } } // delete files with index greater than new file count for (FileHandler fh : fileHandlers.values()) { try { File[] logFiles = getLogFiles(fh); for (int i = getFileCount(); i < logFiles.length; i++) { if (logFiles[i] != null && logFiles[i].exists()) { logFiles[i].delete(); } } } catch (Exception e) { } } loggers.clear(); } } }); }
From source file:org.springframework.shell.core.JLineShell.java
private void removeHandlers(final Logger l) { Handler[] handlers = l.getHandlers(); if (handlers != null && handlers.length > 0) { for (Handler h : handlers) { l.removeHandler(h);//www .j av a 2 s. co m } } }