List of usage examples for java.util.logging LogManager getLogManager
public static LogManager getLogManager()
From source file:org.apache.jul.JulLogFactory.java
public JulLogFactory() { final InputStream is = getClass().getClassLoader().getResourceAsStream("logging.properties"); try {// w ww. j a v a2s.c om if (is != null) { LogManager.getLogManager().readConfiguration(is); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.codice.git.ConfigureLogging.java
public ConfigureLogging() { // Configure the java logging InputStream is = null;/*from w w w .j a va 2 s . co m*/ try { is = ConfigureLogging.class.getResourceAsStream("/logging.properties"); if (is != null) { LogManager.getLogManager().readConfiguration(is); } } catch (IOException e) { System.err.println("Unable to configure java logger."); } finally { IOUtils.closeQuietly(is); } }
From source file:org.stanwood.nwn2.gui.logging.JavaLoggingToCommonLoggingRedirector.java
/** * Deactivates this feature./*from w w w . j a v a2 s . c o m*/ */ public static void deactivate() { Logger rootLogger = LogManager.getLogManager().getLogger(""); rootLogger.removeHandler(activeHandler); Logger.getLogger(JavaLoggingToCommonLoggingRedirector.class.getName()).info("dactivated"); }
From source file:org.nuxeo.common.logging.JavaUtilLoggingHelper.java
/** * Redirects {@code java.util.logging} to Apache Commons Logging do not log * below the threshold level./* w w w . j ava 2 s. co m*/ * * @since 5.4.2 */ public static synchronized void redirectToApacheCommons(Level threshold) { if (activeHandler != null) { return; } try { Logger rootLogger = LogManager.getLogManager().getLogger(""); for (Handler handler : rootLogger.getHandlers()) { rootLogger.removeHandler(handler); } activeHandler = new LogHandler(); activeHandler.setLevel(threshold); rootLogger.addHandler(activeHandler); rootLogger.setLevel(threshold); log.info("Redirecting java.util.logging to Apache Commons Logging, threshold is " + threshold.toString()); } catch (SecurityException e) { log.error("Handler setup failed", e); } }
From source file:de.otto.mongodb.profiler.web.util.LogManagerLifecycle.java
public void configure() throws IOException { final LogManager logManager = LogManager.getLogManager(); logManager.readConfiguration(defaultConfig.getInputStream()); logger.info("Logging has been configured."); }
From source file:org.jbpm.internal.log.Jdk14LogFactory.java
/** configures JDK 1.4 logging from the resource file <code>logging.properties</code> */ public static synchronized void initializeJdk14Logging() { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream inputStream = classLoader.getResourceAsStream("logging.properties"); try {//from w w w . j a v a 2 s .c om if (inputStream != null) { LogManager.getLogManager().readConfiguration(inputStream); String redirectCommons = LogManager.getLogManager().getProperty("redirect.commons.logging"); if ((redirectCommons != null) && (!redirectCommons.equalsIgnoreCase("disabled")) && (!redirectCommons.equalsIgnoreCase("off")) && (!redirectCommons.equalsIgnoreCase("false"))) { redirectCommonsToJdk14(); } } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("couldn't initialize logging properly", e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:org.yamj.api.trakttv.TestLogger.java
public static boolean configure(String level) { StringBuilder config = new StringBuilder("handlers = java.util.logging.ConsoleHandler\n"); config.append(".level = ").append(level).append(CRLF); config.append("java.util.logging.ConsoleHandler.level = ").append(level).append(CRLF); // Only works with Java 7 or later config.append("java.util.logging.SimpleFormatter.format = [%1$tH:%1$tM:%1$tS %4$6s] %2$s - %5$s %6$s%n") .append(CRLF);/*from ww w. j a va 2s . c om*/ // Exclude http logging config.append("sun.net.www.protocol.http.HttpURLConnection.level = OFF").append(CRLF); config.append("org.apache.http.level = SEVERE").append(CRLF); try (InputStream ins = new ByteArrayInputStream(config.toString().getBytes())) { LogManager.getLogManager().readConfiguration(ins); } catch (IOException e) { LOG.warn("Failed to configure log manager due to an IO problem", e); return Boolean.FALSE; } LOG.debug("Logger initialized to '{}' level", level); return Boolean.TRUE; }
From source file:com.omertron.omdbapi.TestLogger.java
/** * configure the logger with a simple in-memory file for the required log level * * @param level The logging level required * @return True if successful/*from ww w. j a va2 s .c o m*/ */ public static boolean configure(String level) { StringBuilder config = new StringBuilder("handlers = java.util.logging.ConsoleHandler\n"); config.append(".level = ").append(level).append(CRLF); config.append("java.util.logging.ConsoleHandler.level = ").append(level).append(CRLF); // Only works with Java 7 or later config.append("java.util.logging.SimpleFormatter.format = [%1$tH:%1$tM:%1$tS %4$6s] %2$s - %5$s %6$s%n") .append(CRLF); // Exclude logging messages config.append("org.apache.http.level = SEVERE").append(CRLF); InputStream ins = new ByteArrayInputStream(config.toString().getBytes()); try { LogManager.getLogManager().readConfiguration(ins); // Exclude http logging System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "warn"); } catch (IOException ex) { LOG.warn("Failed to configure log manager due to an IO problem", ex); return Boolean.FALSE; } finally { try { ins.close(); } catch (IOException ex) { LOG.info("Failed to close input stream", ex); } } LOG.debug("Logger initialized to '{}' level", level); return Boolean.TRUE; }
From source file:com.ning.jetty.core.listeners.SetupJULBridge.java
@Override public void contextInitialized(final ServletContextEvent event) { // We first remove the default handler(s) final Logger rootLogger = LogManager.getLogManager().getLogger(""); final Handler[] handlers = rootLogger.getHandlers(); if (!ArrayUtils.isEmpty(handlers)) { for (final Handler handler : handlers) { rootLogger.removeHandler(handler); }/*from w ww. jav a 2 s . com*/ } // And then we let jul-to-sfl4j do its magic so that jersey messages go to sfl4j SLF4JBridgeHandler.install(); }
From source file:com.archivas.logging.FileHandler.java
private static boolean getAppend() { LogManager manager = LogManager.getLogManager(); String cname = FileHandler.class.getName(); String appendStr = manager.getProperty(cname + ".append"); boolean append = true; if (appendStr != null) { append = Boolean.valueOf(appendStr); }//from w ww . j a v a 2 s .co m return append; }