List of usage examples for java.util.logging Level parse
public static synchronized Level parse(String name) throws IllegalArgumentException
From source file:com.yahoo.dba.perf.myperf.common.MyPerfContext.java
private void configureLogging() { Logger logger = Logger.getLogger(""); try {//from ww w . j a v a 2 s.c om logger.setLevel(Level.parse(getLogLevel())); } catch (Exception ex) { logger.setLevel(Level.INFO); } try { for (Handler h : logger.getHandlers()) { if (h instanceof java.util.logging.ConsoleHandler) h.setLevel(Level.SEVERE); } String logRoot = System.getProperty("logPath", "."); java.util.logging.FileHandler fileHandler = new java.util.logging.FileHandler( logRoot + File.separatorChar + getLogPath(), this.logFileSize, this.logFileCount); fileHandler.setLevel(logger.getLevel()); fileHandler.setFormatter(new SimpleFormatter()); logger.addHandler(fileHandler); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.cloudbees.jenkins.support.SupportPlugin.java
private static Level getLogLevel() { return Level.parse(System.getProperty(SupportPlugin.class.getName() + ".LogLevel", "INFO")); }
From source file:com.cloudbees.jenkins.support.SupportPlugin.java
public static void setLogLevel(String level) { setLogLevel(Level.parse(StringUtils.defaultIfEmpty(level, "INFO"))); }
From source file:pl.otros.logview.importer.UtilLoggingXmlLogImporter.java
/** * Given a Document, converts the XML into a Vector of LoggingEvents. * * @param document/*from w w w. jav a 2 s . com*/ * XML document * @return Vector of LoggingEvents */ private void decodeEvents(final Document document, LogDataCollector collector, ParsingContext parsingContext) { NodeList eventList = document.getElementsByTagName("record"); for (int eventIndex = 0; eventIndex < eventList.getLength(); eventIndex++) { Node eventNode = eventList.item(eventIndex); Logger logger = null; long timeStamp = 0L; Level level = null; String threadName = null; Object message = null; String className = null; String methodName = null; String exceptionStackTrace = null; // format of date: 2003-05-04T11:04:52 // ignore date or set as a property? using millis in constructor instead NodeList list = eventNode.getChildNodes(); int listLength = list.getLength(); if (listLength == 0) { continue; } for (int y = 0; y < listLength; y++) { Node logEventNode = list.item(y); String tagName = logEventNode.getNodeName(); if (tagName.equalsIgnoreCase("logger")) { logger = Logger.getLogger(getCData(list.item(y))); } else if (tagName.equalsIgnoreCase("millis")) { timeStamp = Long.parseLong(getCData(list.item(y))); } else if (tagName.equalsIgnoreCase("level")) { level = Level.parse(getCData(list.item(y))); } else if (tagName.equalsIgnoreCase("thread")) { threadName = getCData(list.item(y)); } else if (tagName.equalsIgnoreCase("message")) { message = getCData(list.item(y)); } else if (tagName.equalsIgnoreCase("class")) { className = getCData(list.item(y)); } else if (tagName.equalsIgnoreCase("method")) { methodName = getCData(list.item(y)); } else if (tagName.equalsIgnoreCase("exception")) { exceptionStackTrace = getExceptionStackTrace(list.item(y)); } } if (message != null && exceptionStackTrace != null) { message = message + "\n" + exceptionStackTrace; } else if (exceptionStackTrace != null) { message = exceptionStackTrace; } LogData logData = new LogData(); logData.setLevel(level); logData.setClazz(className); logData.setId(parsingContext.getGeneratedIdAndIncrease()); logData.setDate(new Date(timeStamp)); logData.setLoggerName(logger.getName()); logData.setMessage(StringUtils.defaultString(message != null ? message.toString() : "")); logData.setThread(threadName); logData.setMethod(methodName); logData.setLogSource(parsingContext.getLogSource()); collector.add(logData); } }
From source file:org.kalypso.services.observation.server.ObservationServiceDelegate.java
/** * Initialise the Service according to configuration. * * @throws RemoteException/*from www . j av a2s . c o m*/ */ protected final synchronized void init() { // TODO: at the moment, we silently ignore this implementation if no // service location was given: this is necessary, because if // the help system is running (jetty!), this implementation is also available at the // client side... // TODO Solution: remove this server code from the client side... (but in order to do that, we must split-up the // observation service plug-ins) if (m_initialized || m_configurationLocation == null) return; m_initialized = true; clearCache(); final Properties props = new Properties(); try { final URL confLocation = new URL(m_configurationLocation); final URL confUrl = UrlResolverSingleton.resolveUrl(confLocation, "repositories_server.xml"); //$NON-NLS-1$ // this call also closes the stream final RepositoryFactoryConfig[] facConfs = RepositoryConfigUtils.loadConfig(confUrl); // load the service properties final URL urlProps = UrlResolverSingleton.resolveUrl(confLocation, "service.properties"); //$NON-NLS-1$ InputStream ins = null; try { ins = urlProps.openStream(); props.load(ins); ins.close(); } catch (final IOException e) { m_logger.warning("Cannot read properties-file: " + e.getLocalizedMessage()); //$NON-NLS-1$ } finally { IOUtils.closeQuietly(ins); } /* Configure logging according to configuration */ try { final String logLevelString = props.getProperty("LOG_LEVEL", Level.INFO.getName()); //$NON-NLS-1$ final Level logLevel = Level.parse(logLevelString); Logger.getLogger("").setLevel(logLevel); //$NON-NLS-1$ } catch (final Throwable t) { // Catch everything, changing the log level should not prohibit this service to run t.printStackTrace(); } /* Load Repositories */ for (final RepositoryFactoryConfig item : facConfs) { final IRepositoryFactory fact = item.getFactory(); try { final IRepository rep = fact.createRepository(); m_repositories.add(rep); m_mapRepId2Rep.put(rep.getIdentifier(), rep); } catch (final Exception e) { m_logger.warning( "Could not create Repository " + fact.getRepositoryName() + " with configuration " //$NON-NLS-1$//$NON-NLS-2$ + fact.getConfiguration() + ". Reason is:\n" + e.getLocalizedMessage()); //$NON-NLS-1$ e.printStackTrace(); } } // tricky: set the list of repositories to the ZmlFilter so that // it can directly fetch the observations without using the default // URL resolving stuff ZmlFilter.configureFor(m_repositories); } catch (final Exception e) // generic exception caught for simplicity { m_logger.throwing(getClass().getName(), "init", e); //$NON-NLS-1$ /** don't throw exception - in sachsen anhalt it's normal that the wiski repository don't exists on server side */ // throw new RepositoryException( "Exception in KalypsoObservationService.init()", e ); //$NON-NLS-1$ } }
From source file:name.livitski.databag.cli.Launcher.java
public Level getRequestedLogLevel() { if (!hasOption(VERBOSE_OPTION)) return Level.INFO; String arg = optionValue(VERBOSE_OPTION); if (null == arg) return Level.FINE; else if ("v".equals(arg)) return Level.FINER; else/*from w w w . j a va 2 s .c o m*/ try { return Level.parse(arg.toUpperCase()); } catch (IllegalArgumentException e) { Level defl = Level.FINE; log().warning("Invalid argument to verbose: '" + arg + "', using default level " + defl); return defl; } }
From source file:dk.alexandra.fresco.framework.configuration.CmdLineUtil.java
private void validateStandardOptions() throws ParseException { int myId;/*from w w w.ja v a 2 s. com*/ Level logLevel; Object suiteObj = this.cmd.getParsedOptionValue("s"); if (suiteObj == null) { throw new ParseException("Cannot parse '" + this.cmd.getOptionValue("s") + "' as a string"); } final Map<Integer, Party> parties = new HashMap<Integer, Party>(); final String suite = (String) suiteObj; if (!ProtocolSuite.getSupportedProtocolSuites().contains(suite.toLowerCase())) { throw new ParseException("Unknown protocol suite: " + suite); } myId = parseNonzeroInt("i"); if (myId == 0) { throw new ParseException("Player id must be positive, non-zero integer"); } for (String pStr : this.cmd.getOptionValues("p")) { String[] p = pStr.split(":"); if (p.length < 3 || p.length > 4) { throw new ParseException( "Could not parse '" + pStr + "' as [id]:[host]:[port] or [id]:[host]:[port]:[shared key]"); } try { int id = Integer.parseInt(p[0]); InetAddress.getByName(p[1]); // Check that hostname is valid. int port = Integer.parseInt(p[2]); Party party; if (p.length == 3) { party = new Party(id, p[1], port); } else { party = new Party(id, p[1], port, p[3]); } if (parties.containsKey(id)) { throw new ParseException("Party ids must be unique"); } parties.put(id, party); } catch (NumberFormatException | UnknownHostException e) { throw new ParseException("Could not parse '" + pStr + "': " + e.getMessage()); } } if (!parties.containsKey(myId)) { throw new ParseException("This party is given the id " + myId + " but this id is not present in the list of parties " + parties.keySet()); } if (this.cmd.hasOption("l")) { System.out.println(this.cmd.getOptionValue("l")); logLevel = Level.parse(this.cmd.getOptionValue("l")); } else { logLevel = Level.WARNING; } Reporter.init(logLevel); int noOfThreads = this.cmd.hasOption("t") ? parseNonzeroInt("t") : getDefaultNoOfThreads(); if (noOfThreads > Runtime.getRuntime().availableProcessors()) { Reporter.warn("You are using " + noOfThreads + " but system has only " + Runtime.getRuntime().availableProcessors() + " available processors. This is likely to result in less than optimal performance."); } int vmThreads = this.cmd.hasOption("vt") ? parseNonzeroInt("vt") : getDefaultNoOfThreads(); if (vmThreads > Runtime.getRuntime().availableProcessors()) { Reporter.warn("You are using " + vmThreads + " but system has only " + Runtime.getRuntime().availableProcessors() + " available processors. This is likely to result in less than optimal performance."); } final ProtocolEvaluator evaluator; if (this.cmd.hasOption("e")) { try { evaluator = EvaluationStrategy.fromString(this.cmd.getOptionValue("e")); } catch (ConfigurationException e) { throw new ParseException("Invalid evaluation strategy: " + this.cmd.getOptionValue("e")); } } else { evaluator = new SequentialEvaluator(); } final Storage storage; if (this.cmd.hasOption("store")) { try { storage = StorageStrategy.fromString(this.cmd.getOptionValue("store")); } catch (ConfigurationException e) { throw new ParseException("Invalid storage strategy: " + this.cmd.getOptionValue("store")); } } else { storage = new InMemoryStorage(); } final int maxBatchSize; if (this.cmd.hasOption("b")) { try { maxBatchSize = Integer.parseInt(this.cmd.getOptionValue("b")); } catch (Exception e) { throw new ParseException(""); } } else { maxBatchSize = 4096; } // TODO: Rather: Just log sceConf.toString() Reporter.config("Player id : " + myId); Reporter.config("Protocol suite : " + suite); Reporter.config("Players : " + parties); Reporter.config("Log level : " + logLevel); Reporter.config("No of threads : " + noOfThreads); Reporter.config("No of vm threads : " + vmThreads); Reporter.config("Evaluation strategy: " + evaluator); Reporter.config("Storage strategy : " + storage); Reporter.config("Maximum batch size : " + maxBatchSize); this.sceConf = new SCEConfiguration() { @Override public int getMyId() { return myId; } @Override public String getProtocolSuiteName() { return suite; } @Override public Map<Integer, Party> getParties() { return parties; } @Override public Level getLogLevel() { return logLevel; } @Override public int getNoOfThreads() { return noOfThreads; } @Override public int getNoOfVMThreads() { return vmThreads; } @Override public ProtocolEvaluator getEvaluator() { return evaluator; } @Override public Storage getStorage() { return storage; } @Override public int getMaxBatchSize() { return maxBatchSize; } @Override public StreamedStorage getStreamedStorage() { if (storage instanceof StreamedStorage) { return (StreamedStorage) storage; } else { return null; } } }; }
From source file:de.fosd.jdime.config.JDimeConfig.java
/** * Set the logging level. The levels in descending order are:<br> * * <ul>//www . jav a 2 s.co m * <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:org.syncany.cli.CommandLineClient.java
private void initLogLevel(OptionSet options, OptionSpec<Void> optionDebug, OptionSpec<String> optionLogLevel) { Level newLogLevel = null;/*from w w w . j a va 2 s .c o m*/ // --debug if (options.has(optionDebug)) { newLogLevel = Level.ALL; } // --loglevel=<level> else if (options.has(optionLogLevel)) { String newLogLevelStr = options.valueOf(optionLogLevel); try { newLogLevel = Level.parse(newLogLevelStr); } catch (IllegalArgumentException e) { showErrorAndExit("Invalid log level given " + newLogLevelStr + "'"); } } else { newLogLevel = Level.INFO; } // Add handler to existing loggers, and future ones Logging.setGlobalLogLevel(newLogLevel); // Debug output if (options.has(optionDebug)) { out.println("debug"); out.println(String.format("Application version: %s", Client.getApplicationVersionFull())); logger.log(Level.INFO, "Application version: {0}", Client.getApplicationVersionFull()); } }
From source file:edu.usu.sdl.openstorefront.web.rest.service.Application.java
@PUT @RequireAdmin// w w w.j a va 2s .c om @APIDescription("Sets logger level") @Produces({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.WILDCARD }) @DataType(LoggerView.class) @Path("/logger/{loggername}/level") public Response updateApplicationProperty(@PathParam("loggername") @RequiredParam String loggername, String level) { Response response = Response.status(Response.Status.NOT_FOUND).build(); Logger logger = LogManager.getLogManager().getLogger(loggername); if (logger != null) { List<String> levels = loadLevels(); boolean saved = false; if (StringUtils.isBlank(level)) { logger.setLevel(null); saved = true; } else { if (levels.contains(level)) { logger.setLevel(Level.parse(level)); saved = true; } else { RestErrorModel restErrorModel = new RestErrorModel(); restErrorModel.getErrors().put("level", "Log level is not valid. Check level value passed in."); response = Response.ok(restErrorModel).build(); } } if (saved) { LoggerView loggerView = new LoggerView(); loggerView.setName(loggername); loggerView.setLevel(level); for (Handler handlerLocal : logger.getHandlers()) { loggerView.getHandlers() .add(handlerLocal.getClass().getName() + " = " + handlerLocal.getLevel().getName()); } response = Response.ok(loggerView).build(); } } return response; }