List of usage examples for java.util.logging Logger addHandler
public void addHandler(Handler handler) throws SecurityException
From source file:org.openqa.selenium.server.log.LoggingManager.java
private static void addInMemoryLogger(Logger logger, RemoteControlConfiguration configuration) { shortTermMemoryHandler = new ShortTermMemoryHandler(configuration.shortTermMemoryLoggerCapacity(), Level.INFO, new TerseFormatter(true)); logger.addHandler(shortTermMemoryHandler); }
From source file:geva.Main.Run.java
protected static void initJavaLogging(java.util.logging.Level level) { // All of the library code uses the commons logging library for output. // If you want to change the log formats or do anything fancy it's strongly // recommended that you switch to the much more capable log4j library as // described at http://commons.apache.org/logging/guide.html // As a default we'll make the JDK logging behave like System.out.println // so we dont introduce another dependency. java.util.logging.SimpleFormatter fmt = new java.util.logging.SimpleFormatter() { @Override//from w ww .j a v a 2 s . c o m public synchronized String format(LogRecord record) { return record.getMessage() + "\n"; } }; java.util.logging.Handler handler = new java.util.logging.StreamHandler(System.out, fmt); java.util.logging.Logger rootLogger = java.util.logging.Logger.getLogger(""); for (java.util.logging.Handler h : rootLogger.getHandlers()) { rootLogger.removeHandler(h); } rootLogger.addHandler(handler); rootLogger.setLevel(level); }
From source file:org.eclipse.ecr.common.logging.JavaUtilLoggingHelper.java
/** * Redirects {@code java.util.logging} to Apache Commons Logging do not log * below the threshold level./*w w w .jav a2s. c o 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 (Exception e) { log.error("Handler setup failed", e); } }
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.//from ww w . j a va 2s . c o 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:org.stanwood.nwn2.gui.logging.JavaLoggingToCommonLoggingRedirector.java
/** * Activates this feature.// ww w. j ava 2 s . c o m */ public static void activate() { try { Logger rootLogger = LogManager.getLogManager().getLogger(""); // remove old handlers for (Handler handler : rootLogger.getHandlers()) { rootLogger.removeHandler(handler); } // add our own activeHandler = new JDKLogHandler(); activeHandler.setLevel(Level.ALL); rootLogger.addHandler(activeHandler); rootLogger.setLevel(Level.ALL); } catch (Exception exc) { LogFactory.getLog(JavaLoggingToCommonLoggingRedirector.class).error("activation failed", exc); } }
From source file:ffx.Main.java
/** * Replace the default console handler with our custom FFX handler. *///from w w w . j ava2s. c om private static void startLogging() { // Remove all log handlers from the default logger. try { Logger defaultLogger = LogManager.getLogManager().getLogger(""); Handler defaultHandlers[] = defaultLogger.getHandlers(); for (Handler h : defaultHandlers) { defaultLogger.removeHandler(h); } } catch (Exception e) { System.err.println(e.toString()); } // Retrieve the log level from the ffx.log system property. String logLevel = System.getProperty("ffx.log", "info"); Level tempLevel; try { tempLevel = Level.parse(logLevel.toUpperCase()); } catch (Exception e) { tempLevel = Level.INFO; } level = tempLevel; logHandler = new LogHandler(); logHandler.setLevel(level); Logger ffxLogger = Logger.getLogger("ffx"); ffxLogger.addHandler(logHandler); ffxLogger.setLevel(level); }
From source file:prm4j.indexing.monitor.ParametricMonitorLogger.java
/** * A simple file logger which outputs only the message. * //from w ww .j a v a 2 s.com * @param fileName * path to the output file * @return the logger */ private static Logger getFileLogger(String fileName) { // make sure parent directories exist new File(fileName).getParentFile().mkdirs(); final Logger logger = Logger.getLogger(fileName); try { logger.setUseParentHandlers(false); Handler handler = new FileHandler(fileName, true); handler.setFormatter(new Formatter() { @Override public String format(LogRecord record) { return record.getMessage() + "\n"; } }); logger.addHandler(handler); } catch (Exception e) { throw new RuntimeException(e); } return logger; }
From source file:com.bluexml.side.integration.standalone.GenerateModelHelper.java
/** * Init {@link Logger}s associated to package * com.bluexml.side.Integration.standAlone * // w ww . ja v a 2 s .c o m * @param baseLevel * the level above which logs will be displayed on the console * @return the base {@link Logger} managing the package */ public static Logger initLogger(Level baseLevel) { if (baseLevel == null) { baseLevel = Level.INFO; } if (baseLogger == null) { Logger logger = Logger.getLogger("com.bluexml.side"); // $NON-NLS-1$ ConsoleHandler handler = new ConsoleHandler(); handler.setFormatter(new ConsoleSimpleFormatter()); logger.setUseParentHandlers(false); logger.addHandler(handler); baseLogger = logger; consoleHandler = handler; } baseLogger.setLevel(baseLevel); consoleHandler.setLevel(baseLevel); return baseLogger; }
From source file:mop.MemoryLogger.java
/** * A simple file logger which outputs only the message. * * @param fileName/*from w w w. j av a2s . c o m*/ * path to the output file * @return the logger */ private static Logger getFileLogger(String fileName) { final Logger logger = Logger.getLogger(fileName); try { logger.setUseParentHandlers(false); Handler handler = new FileHandler(fileName, true); handler.setFormatter(new Formatter() { @Override public String format(LogRecord record) { return record.getMessage() + "\n"; } }); logger.addHandler(handler); } catch (Exception e) { throw new RuntimeException(e); } return logger; }
From source file:com.basp.trabajo_al_minuto.model.business.BusinessUtils.java
public static void writeLog(String file, List<LogRecord> records) throws BusinessException { try {/*from ww w .ja v a 2s . co m*/ Logger logger = Logger.getAnonymousLogger(); SimpleFormatter formatter = new SimpleFormatter(); FileHandler fh = new FileHandler(file, Boolean.TRUE); fh.setFormatter(formatter); logger.addHandler(fh); logger.setUseParentHandlers(false); records.stream().forEach((logRecord) -> { logger.log(logRecord); }); } catch (IOException | SecurityException ex) { Logger.getLogger(BusinessUtils.class.getName()).log(Level.SEVERE, "BusinessUtils.writeLog Exception", ex); throw new BusinessException(ex); } }