List of usage examples for java.util.logging Logger setUseParentHandlers
public void setUseParentHandlers(boolean useParentHandlers)
From source file:mop.MemoryLogger.java
/** * A simple file logger which outputs only the message. * * @param fileName/* ww w. j a v a 2s.com*/ * 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.googlecode.jgenhtml.JGenHtmlUtils.java
public static void setLogFormatter(final Logger logger) { logger.setUseParentHandlers(false); JGenHtmlLogFormatter formatter = new JGenHtmlLogFormatter(); ConsoleHandler handler = new ConsoleHandler(); handler.setFormatter(formatter);/*from w ww.j a v a2 s. c o m*/ logger.addHandler(handler); }
From source file:org.openstreetmap.josm.data.cache.JCSCacheManager.java
@SuppressWarnings("resource") private static void initialize() throws IOException { File cacheDir = new File(Main.pref.getCacheDirectory(), "jcs"); if (!cacheDir.exists() && !cacheDir.mkdirs()) throw new IOException("Cannot access cache directory"); File cacheDirLockPath = new File(cacheDir, ".lock"); if (!cacheDirLockPath.exists() && !cacheDirLockPath.createNewFile()) { LOG.log(Level.WARNING, "Cannot create cache dir lock file"); }// w w w. ja v a 2 s . c om cacheDirLock = new FileOutputStream(cacheDirLockPath).getChannel().tryLock(); if (cacheDirLock == null) LOG.log(Level.WARNING, "Cannot lock cache directory. Will not use disk cache"); // raising logging level gives ~500x performance gain // http://westsworld.dk/blog/2008/01/jcs-and-performance/ final Logger jcsLog = Logger.getLogger("org.apache.commons.jcs"); jcsLog.setLevel(Level.INFO); jcsLog.setUseParentHandlers(false); // we need a separate handler from Main's, as we downgrade LEVEL.INFO to DEBUG level Arrays.stream(jcsLog.getHandlers()).forEach(jcsLog::removeHandler); jcsLog.addHandler(new Handler() { final SimpleFormatter formatter = new SimpleFormatter(); @Override public void publish(LogRecord record) { String msg = formatter.formatMessage(record); if (record.getLevel().intValue() >= Level.SEVERE.intValue()) { Logging.error(msg); } else if (record.getLevel().intValue() >= Level.WARNING.intValue()) { Logging.warn(msg); // downgrade INFO level to debug, as JCS is too verbose at INFO level } else if (record.getLevel().intValue() >= Level.INFO.intValue()) { Logging.debug(msg); } else { Logging.trace(msg); } } @Override public void flush() { // nothing to be done on flush } @Override public void close() { // nothing to be done on close } }); // this could be moved to external file Properties props = new Properties(); // these are default common to all cache regions // use of auxiliary cache and sizing of the caches is done with giving proper geCache(...) params // CHECKSTYLE.OFF: SingleSpaceSeparator props.setProperty("jcs.default.cacheattributes", CompositeCacheAttributes.class.getCanonicalName()); props.setProperty("jcs.default.cacheattributes.MaxObjects", DEFAULT_MAX_OBJECTS_IN_MEMORY.get().toString()); props.setProperty("jcs.default.cacheattributes.UseMemoryShrinker", "true"); props.setProperty("jcs.default.cacheattributes.DiskUsagePatternName", "UPDATE"); // store elements on disk on put props.setProperty("jcs.default.elementattributes", CacheEntryAttributes.class.getCanonicalName()); props.setProperty("jcs.default.elementattributes.IsEternal", "false"); props.setProperty("jcs.default.elementattributes.MaxLife", Long.toString(maxObjectTTL)); props.setProperty("jcs.default.elementattributes.IdleTime", Long.toString(maxObjectTTL)); props.setProperty("jcs.default.elementattributes.IsSpool", "true"); // CHECKSTYLE.ON: SingleSpaceSeparator CompositeCacheManager cm = CompositeCacheManager.getUnconfiguredInstance(); cm.configure(props); cacheManager = cm; }
From source file:org.freaknet.gtrends.client.GoogleTrendsClientFactory.java
private static void setLogLevel(CmdLineParser cmdLine) throws SecurityException, IllegalArgumentException { final Level level; if (cmdLine.getLogLevel() != null) { level = Level.parse(cmdLine.getLogLevel()); } else {// w ww.j a va 2s .c o m level = Level.parse(DEFAULT_LOGGING_LEVEL); } Logger log = LogManager.getLogManager().getLogger(""); for (Handler h : log.getHandlers()) { log.removeHandler(h); } Handler handler = new ConsoleHandler(); handler.setFormatter(new LogFormatter()); handler.setLevel(level); log.setUseParentHandlers(false); Logger defaultLog = Logger.getLogger(GoogleConfigurator.getLoggerPrefix()); defaultLog.addHandler(handler); defaultLog.setLevel(level); defaultLog.setFilter(new Filter() { @Override public boolean isLoggable(LogRecord record) { if (record.getSourceClassName().startsWith(GoogleConfigurator.getLoggerPrefix())) { return (record.getLevel().intValue() >= level.intValue()); } return false; } }); }
From source file:com.bluexml.side.integration.standalone.GenerateModelHelper.java
/** * Init {@link Logger}s associated to package * com.bluexml.side.Integration.standAlone * //from w w w. j av a 2s . co 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:com.basp.trabajo_al_minuto.model.business.BusinessUtils.java
public static void writeLog(String file, List<LogRecord> records) throws BusinessException { try {// ww w . j ava 2 s . 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); } }
From source file:org.spoutcraft.launcher.entrypoint.SpoutcraftLauncher.java
protected static Logger setupLogger() { final Logger logger = Utils.getLogger(); File logDirectory = new File(Utils.getLauncherDirectory(), "logs"); if (!logDirectory.exists()) { logDirectory.mkdir();//w w w . ja v a 2 s. co m } File logs = new File(logDirectory, "techniclauncher_%D.log"); RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath()); fileHandler.setFormatter(new TechnicLogFormatter()); for (Handler h : logger.getHandlers()) { logger.removeHandler(h); } logger.addHandler(fileHandler); SpoutcraftLauncher.handler = fileHandler; if (params != null && !params.isDebugMode()) { logger.setUseParentHandlers(false); System.setOut(new PrintStream(new LoggerOutputStream(console, Level.INFO, logger), true)); System.setErr(new PrintStream(new LoggerOutputStream(console, Level.SEVERE, logger), true)); } Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { logger.log(Level.SEVERE, "Unhandled Exception in " + t, e); if (errorDialog == null) { LauncherFrame frame = null; try { frame = Launcher.getFrame(); } catch (Exception ex) { //This can happen if we have a very early crash- before Launcher initializes } errorDialog = new ErrorDialog(frame, e); errorDialog.setVisible(true); } } }); return logger; }
From source file:net.technicpack.launcher.LauncherMain.java
private static void setupLogging(LauncherDirectories directories, ResourceLoader resources) { System.out.println("Setting up logging"); final Logger logger = Utils.getLogger(); File logDirectory = new File(directories.getLauncherDirectory(), "logs"); if (!logDirectory.exists()) { logDirectory.mkdir();//from w w w .j a v a 2s. c om } File logs = new File(logDirectory, "techniclauncher_%D.log"); RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath()); fileHandler.setFormatter(new BuildLogFormatter(resources.getLauncherBuild())); for (Handler h : logger.getHandlers()) { logger.removeHandler(h); } logger.addHandler(fileHandler); logger.setUseParentHandlers(false); LauncherMain.consoleFrame = new ConsoleFrame(2500, resources.getImage("icon.png")); Console console = new Console(LauncherMain.consoleFrame, resources.getLauncherBuild()); logger.addHandler(new ConsoleHandler(console)); System.setOut(new PrintStream(new LoggerOutputStream(console, Level.INFO, logger), true)); System.setErr(new PrintStream(new LoggerOutputStream(console, Level.SEVERE, logger), true)); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { e.printStackTrace(); logger.log(Level.SEVERE, "Unhandled Exception in " + t, e); // if (errorDialog == null) { // LauncherFrame frame = null; // // try { // frame = Launcher.getFrame(); // } catch (Exception ex) { // //This can happen if we have a very early crash- before Launcher initializes // } // // errorDialog = new ErrorDialog(frame, e); // errorDialog.setVisible(true); // } } }); }
From source file:org.spoutcraft.launcher.Main.java
private static void setupLogger() { Logger logger = Logger.getLogger("launcher"); File logDirectory = new File(Utils.getWorkingDirectory(), "logs"); if (!logDirectory.exists()) { logDirectory.mkdir();/*from w w w . j a v a 2 s . co m*/ } File logs = new File(logDirectory, "spoutcraft_%D.log"); RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath()); fileHandler.setFormatter(new DateOutputFormatter(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"))); for (Handler h : logger.getHandlers()) { logger.removeHandler(h); } logger.addHandler(fileHandler); Main.handler = fileHandler; logger.setUseParentHandlers(false); System.setOut(new PrintStream(new LoggerOutputStream(Level.INFO, logger), true)); System.setErr(new PrintStream(new LoggerOutputStream(Level.SEVERE, logger), true)); Main.logger = logger; }
From source file:de.ailis.jasdoc.Main.java
/** * Initializes logging./*from ww w.ja v a 2 s .c o m*/ */ private void initLogging() { final Logger logger = Logger.getLogger("de.ailis.jasdoc"); logger.setUseParentHandlers(false); final Handler handler = new LogHandler(); handler.setFilter(null); handler.setFormatter(new LogFormatter(this.debug)); if (this.debug) handler.setLevel(Level.ALL); else if (this.quiet) handler.setLevel(Level.WARNING); else handler.setLevel(Level.INFO); logger.setFilter(null); logger.addHandler(handler); Logger.getLogger("").setLevel(handler.getLevel()); }