List of usage examples for java.util.logging Logger setLevel
public void setLevel(Level newLevel) throws SecurityException
From source file:io.trivium.Central.java
public static void setLogLevel(String level) { Logger logger = Logger.getLogger(""); logger.setLevel(Level.parse(level.toUpperCase())); }
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 w w. j a v a2s .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:fr.eurecom.nerd.core.proxy.ExtractivClient.java
private static HttpClient getClient() { if (httpClient == null) { // snuff the getBody() HTTPClient warnings final Logger logger = Logger.getLogger("org.apache.commons.httpclient"); logger.setLevel(Level.SEVERE); httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); }//from w ww . j ava2s.c om return httpClient; }
From source file:jshm.logging.Log.java
public static void configTestLogging() { Handler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(Level.ALL); consoleHandler.setFormatter(new OneLineFormatter()); Logger cur = Logger.getLogger(""); removeHandlers(cur);/*from w w w. ja va 2 s . co m*/ // cur.setLevel(Level.ALL); cur.addHandler(consoleHandler); cur = Logger.getLogger("jshm"); cur.setLevel(Level.ALL); cur = Logger.getLogger("httpclient.wire.header"); cur.setLevel(Level.ALL); // cur = Logger.getLogger("org.hibernate"); // removeHandlers(cur); // // cur.setLevel(Level.INFO); }
From source file:ductive.log.JDKToCommonsHandler.java
public static JDKToCommonsHandler rerouteJDKToCommons(Level level) { Logger root = Logger.getLogger(""); {//from w w w. j a va2s. c o m Handler[] handlers = root.getHandlers(); if (!ArrayUtils.isEmpty(handlers)) for (Handler h : handlers) root.removeHandler(h); } root.addHandler(DEFAULT); root.setLevel(level); return DEFAULT; }
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. j ava2s . c o m 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:de.fosd.jdime.config.JDimeConfig.java
/** * Set the logging level. The levels in descending order are:<br> * * <ul>//ww w .j a v a 2 s .com * <li>ALL</li> * <li>SEVERE (highest value)</li> * <li>WARNING</li> * <li>INFO</li> * <li>CONFIG</li> * <li>FINE</li> * <li>FINER</li> * <li>FINEST (lowest value)</li> * <li>OFF</li> * </ul> * * @param logLevel * one of the valid log levels according to {@link Level#parse(String)} */ public static void setLogLevel(String logLevel) { Level level; try { level = Level.parse(logLevel.toUpperCase()); } catch (IllegalArgumentException e) { LOG.warning( () -> "Invalid log level %s. Must be one of OFF, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST or ALL."); return; } Logger root = Logger.getLogger(Main.class.getPackage().getName()); root.setLevel(level); for (Handler handler : root.getHandlers()) { handler.setLevel(level); } }
From source file:nl.minvenj.pef.stream.LiveCapture.java
/** * Initializes a logger.// w w w . ja va 2s . c o m * * @param logPath The location and name of the log file * @throws SecurityException on opening the log file * @throws IOException on opening the log file */ private static void initLogger(final String logPath) throws SecurityException, IOException, IllegalArgumentException { logFileHandler = new FileHandler(logPath, true); Logger initLogger = Logger.getLogger(""); logFileHandler.setFormatter(new SimpleFormatter()); initLogger.addHandler(logFileHandler); initLogger.setLevel(Level.CONFIG); }
From source file:com.twitter.heron.common.utils.logging.LoggingHelper.java
/** * Init java util logging// w w w. j av a 2s. c om * * @param level the Level of message to log * @param isRedirectStdOutErr whether we redirect std out&err * @param format the format to log */ public static void loggerInit(Level level, boolean isRedirectStdOutErr, String format) throws IOException { // Set the java util logging format setLoggingFormat(format); // Configure the root logger and its handlers so that all the // derived loggers will inherit the properties Logger rootLogger = Logger.getLogger(""); for (Handler handler : rootLogger.getHandlers()) { handler.setLevel(level); } rootLogger.setLevel(level); if (rootLogger.getLevel().intValue() < Level.WARNING.intValue()) { // zookeeper logging scares me. if people want this, we can patch to config-drive this Logger.getLogger("org.apache.zookeeper").setLevel(Level.WARNING); } // setting logging for http client to be error level System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "ERROR"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "ERROR"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "ERROR"); if (isRedirectStdOutErr) { // Remove ConsoleHandler if present, to avoid StackOverflowError. // ConsoleHandler writes to System.err and since we are redirecting // System.err to Logger, it results in an infinite loop. for (Handler handler : rootLogger.getHandlers()) { if (handler instanceof ConsoleHandler) { rootLogger.removeHandler(handler); } } // now rebind stdout/stderr to logger Logger logger; LoggingOutputStream los; logger = Logger.getLogger("stdout"); los = new LoggingOutputStream(logger, StdOutErrLevel.STDOUT); System.setOut(new PrintStream(los, true)); logger = Logger.getLogger("stderr"); los = new LoggingOutputStream(logger, StdOutErrLevel.STDERR); System.setErr(new PrintStream(los, true)); } }
From source file:org.jboss.jdf.stack.test.StacksTest.java
@BeforeClass public static void setupClient() throws MalformedURLException { // suppress shrinkwrap warning messages Logger shrinkwrapLogger = Logger.getLogger("org.jboss.shrinkwrap"); shrinkwrapLogger.setLevel(Level.SEVERE); stacksFile = new File("./stacks.yaml"); URL url = stacksFile.toURI().toURL(); log.info("Testing file: " + url); stacksClient = new StacksClient(); StacksClientConfiguration config = stacksClient.getActualConfiguration(); config.setCacheRefreshPeriodInSeconds(-1); config.setUrl(url);/*from w ww .j a v a 2 s . co m*/ }