List of usage examples for java.util.logging Level parse
public static synchronized Level parse(String name) throws IllegalArgumentException
From source file:org.jenkinsci.maven.plugins.hpi.RunMojo.java
public void execute() throws MojoExecutionException, MojoFailureException { getProject().setArtifacts(resolveDependencies(dependencyResolution)); File basedir = getProject().getBasedir(); if (webApp == null || webApp.getContextPath() == null) { if (contextPath != null) { getLog().warn(// w ww . ja v a 2s . co m "Please use `webApp/contextPath` configuration parameter in place of the deprecated `contextPath` parameter"); if (webApp == null) { try { webApp = new JettyWebAppContext(); } catch (Exception e) { throw new MojoExecutionException("Failed to initialize webApp configuration", e); } } webApp.setContextPath(contextPath); } } // compute jenkinsHome if (jenkinsHome == null) { if (hudsonHome != null) { getLog().warn( "Please use the `jenkinsHome` configuration parameter in place of the deprecated `hudsonHome` parameter"); jenkinsHome = hudsonHome; } String h = System.getenv("JENKINS_HOME"); if (h == null) { h = System.getenv("HUDSON_HOME"); } if (h != null) jenkinsHome = new File(h); else jenkinsHome = new File(basedir, "work"); } // auto-enable stapler trace, unless otherwise configured already. setSystemPropertyIfEmpty("stapler.trace", "true"); // allow Jetty to accept a bigger form so that it can handle update center JSON post setSystemPropertyIfEmpty("org.eclipse.jetty.Request.maxFormContentSize", "-1"); // general-purpose system property so that we can tell from Jenkins if we are running in the hpi:run mode. setSystemPropertyIfEmpty("hudson.hpi.run", "true"); // this adds 3 secs to the shutdown time. Skip it. setSystemPropertyIfEmpty("hudson.DNSMultiCast.disabled", "true"); // expose the current top-directory of the plugin setSystemPropertyIfEmpty("jenkins.moduleRoot", basedir.getAbsolutePath()); if (systemProperties != null && !systemProperties.isEmpty()) { for (Map.Entry<String, String> entry : systemProperties.entrySet()) { if (entry.getKey() != null && entry.getValue() != null) { System.setProperty(entry.getKey(), entry.getValue()); } } } // look for jenkins.war Artifacts jenkinsArtifacts = Artifacts.of(getProject()) .groupIdIs("org.jenkins-ci.main", "org.jvnet.hudson.main").artifactIdIsNot("remoting"); // remoting moved to its own release cycle webAppFile = getJenkinsWarArtifact().getFile(); // make sure all the relevant Jenkins artifacts have the same version for (Artifact a : jenkinsArtifacts) { Artifact ba = jenkinsArtifacts.get(0); if (!a.getVersion().equals(ba.getVersion())) throw new MojoExecutionException("Version of " + a.getId() + " is inconsistent with " + ba.getId()); } // set JENKINS_HOME setSystemPropertyIfEmpty("JENKINS_HOME", jenkinsHome.getAbsolutePath()); File pluginsDir = new File(jenkinsHome, "plugins"); pluginsDir.mkdirs(); // enable view auto refreshing via stapler setSystemPropertyIfEmpty("stapler.jelly.noCache", "true"); List<Resource> res = getProject().getBuild().getResources(); if (!res.isEmpty()) { // pick up the first one and use it Resource r = res.get(0); setSystemPropertyIfEmpty("stapler.resourcePath", r.getDirectory()); } generateHpl(); // copy other dependency Jenkins plugins try { for (MavenArtifact a : getProjectArtifacts()) { if (!a.isPlugin()) continue; // find corresponding .hpi file Artifact hpi = artifactFactory.createArtifact(a.getGroupId(), a.getArtifactId(), a.getVersion(), null, "hpi"); artifactResolver.resolve(hpi, getProject().getRemoteArtifactRepositories(), localRepository); // check recursive dependency. this is a rare case that happens when we split out some things from the core // into a plugin if (hasSameGavAsProject(hpi)) continue; if (hpi.getFile().isDirectory()) throw new UnsupportedOperationException( hpi.getFile() + " is a directory and not packaged yet. this isn't supported"); File upstreamHpl = pluginWorkspaceMap.read(hpi.getId()); if (upstreamHpl != null) { copyHpl(upstreamHpl, pluginsDir, a.getActualArtifactId()); } else { copyPlugin(hpi.getFile(), pluginsDir, a.getActualArtifactId()); } } } catch (IOException e) { throw new MojoExecutionException("Unable to copy dependency plugin", e); } catch (ArtifactNotFoundException e) { throw new MojoExecutionException("Unable to copy dependency plugin", e); } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Unable to copy dependency plugin", e); } if (loggers != null) { for (Handler h : LogManager.getLogManager().getLogger("").getHandlers()) { if (h instanceof ConsoleHandler) { h.setLevel(Level.ALL); } } loggerReferences = new LinkedList<Logger>(); for (Map.Entry<String, String> logger : loggers.entrySet()) { Logger l = Logger.getLogger(logger.getKey()); loggerReferences.add(l); l.setLevel(Level.parse(logger.getValue())); } } super.execute(); }
From source file:datasphere.catalog.DSCatalog.java
/** * Allows command line arguments to be passed into the framework - any parameters * supplied in this fashion will override any that were previously being held. * @param args The command line arguments supplied on running of the server instance. * @exception DSException Thrown if the supplied port number is illegal or already in use. *//*from w ww. j a va2s .c o m*/ public void setArgs(String[] args) throws DSException { try { //-- create Options object Options options = new Options(); options.addOption("w", "wipe", false, "clears the system databases on startup"); options.addOption("d", "debug", false, "pulls up a debugger window for each XMPP connection"); options.addOption("x", "xmpp", true, "specify the port the xmpp server listens on. default is " + DSChatServer.DEFAULT_SERVER_PORT); options.addOption("t", "http", true, "specify the port the http server listens on. default is " + DSWebServer.DEFAULT_SERVER_PORT); options.addOption("p", "password", true, "specify the admin password for the system"); options.addOption("l", "log-level", true, "specify the log level (0-1000) to display"); options.addOption("c", "create", false, "Automatically generates required system tables"); options.addOption("h", "help", false, "prints this message"); options.addOption("v", "version", false, "returns version information"); options.addOption("b", "verbose", false, "posts all logger information to the console"); options.addOption("bt", "verbose-http", false, "posts all http log information to the console"); options.addOption("bx", "verbose-xmpp", false, "posts all xmpp log information to the console"); options.addOption("vf", "version-full", false, "returns full version, build and authorship information"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); for (String s : cmd.getArgs()) System.out.println("(" + s + ")"); //-- automatically generate the help statement if (cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("DSCatalog.jar", options); xmppStartable = false; httpStartable = false; return; } //-- determine if version information is being asked for if (cmd.hasOption("version") || cmd.hasOption("version-full")) { //-- load config file for the server Properties v = new Properties(); InputStream is = getClass().getClassLoader().getResourceAsStream("version.info"); //-- if it exists extract the properties contained within if (is != null) { try { v.load(is); is.close(); System.out.println("version: datasphere.catalog " + v.getProperty("version")); if (cmd.hasOption("version-full")) { System.out.println("compiler: " + v.getProperty("compiled-by")); System.out.println("built: " + v.getProperty("build-time") + ""); System.out.println("Java: " + v.getProperty("java-version")); } } catch (IOException e) { System.out.println("version: information cannot be loaded"); } } else { System.out.println("version: information cannot be found"); } xmppStartable = false; httpStartable = false; return; } //-- determine if system databases should be cleaned if (cmd.hasOption("wipe")) { systemWipe = true; } //-- determine if user is attempting to create the system database if (cmd.hasOption("create")) { systemCreate = true; } //-- determine if user is attempting to create the system database if (cmd.hasOption("debug")) { this.debug = true; } //-- check the validity of any log-level supplied if (cmd.hasOption("log-level")) { try { setLoggingLevel(Level.parse(cmd.getOptionValue("log-level").toUpperCase())); } catch (IllegalArgumentException e) { throw new ParseException("Logging error: " + e.getMessage()); } } //-- determine if a port number is being specified if (cmd.hasOption("password")) { try { this.password = cmd.getOptionValue("p"); } catch (NumberFormatException e) { throw new ParseException("Invalid password specified"); } } //-- determine if an xmpp port number is being specified if (cmd.hasOption("xmpp")) { try { xmppPort = Integer.parseInt(cmd.getOptionValue("x")); } catch (NumberFormatException e) { throw new ParseException("Invalid XMPP Port Number specified"); } } //-- determine if an xmpp port number is being specified if (cmd.hasOption("http")) { try { httpPort = Integer.parseInt(cmd.getOptionValue("t")); } catch (NumberFormatException e) { throw new ParseException("Invalid HTTP Port Number specified"); } } } catch (ParseException e) { throw new DSException(e.getMessage() + "\n" + "Please try '--help' for more information"); } }
From source file:org.hippoecm.repository.LoggingServlet.java
/** * Set the logger's log level through reflection * @param name String the name of the logger to change * @param level String the new log level *//*from w w w . ja va 2 s .co m*/ private void setLoggerLevel(String name, String level) { if (name == null || name.length() == 0) { log.warn("Invalid empty name. Not settting log level"); return; } if (isJDK14Log) { java.util.logging.LogManager logManager = java.util.logging.LogManager.getLogManager(); java.util.logging.Logger logger = logManager.getLogger(name); if (logger != null) { logger.setLevel(Level.parse(level)); } else { log.warn("Logger not found : " + name); } } else if (isLog4jLog) { try { log.warn("Setting logger " + name + " to level " + level); // basic log4j reflection Class<?> loggerClass = Class.forName("org.apache.log4j.Logger"); Class<?> levelClass = Class.forName("org.apache.log4j.Level"); Class<?> logManagerClass = Class.forName("org.apache.log4j.LogManager"); Method setLevel = loggerClass.getMethod("setLevel", levelClass); // get the logger Object logger = logManagerClass.getMethod("getLogger", String.class).invoke(null, name); // get the static level object field, e.g. Level.INFO Field levelField; levelField = levelClass.getField(level); Object levelObj = levelField.get(null); // set the level setLevel.invoke(logger, levelObj); } catch (NoSuchFieldException e) { log.warn("Unable to find Level." + level + " , not adjusting logger " + name); } catch (Exception e) { log.error("Unable to set logger " + name + " + to level " + level, e); } } else { log.warn("Unable to determine logger"); } }
From source file:fr.ens.biologie.genomique.eoulsan.Main.java
/** * Initialize the application logger.//from w ww .j a v a 2s .com */ private void initApplicationLogger() { // Disable parent Handler getLogger().setUseParentHandlers(false); // Set log level to all before setting the real log level with // BufferedHandler getLogger().setLevel(Level.ALL); // Add Buffered handler as unique Handler getLogger().addHandler(this.handler); // Set the formatter this.handler.setFormatter(Globals.LOG_FORMATTER); // Set the log level if (this.logLevel != null) { try { this.handler.setLevel(Level.parse(this.logLevel.toUpperCase())); } catch (IllegalArgumentException e) { Common.showErrorMessageAndExit("Unknown log level (" + this.logLevel + "). Accepted values are [SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST]."); } } else { this.handler.setLevel(Globals.LOG_LEVEL); } // Set the log file in arguments if (this.logFile != null) { try { this.handler.addHandler(getLogHandler(new File(this.logFile).getAbsoluteFile().toURI())); } catch (IOException e) { Common.errorExit(e, "Error while creating log file: " + e.getMessage()); } } }
From source file:org.jboss.as.logging.LoggingOperationsSubsystemTestCase.java
private void testChangeRootLogLevel(final String loggingProfile) throws Exception { final KernelServices kernelServices = boot(); final String fileHandlerName = "test-file-handler"; // add new file logger so we can track logged messages final File logFile = createLogFile(); addFileHandler(kernelServices, loggingProfile, fileHandlerName, org.jboss.logmanager.Level.TRACE, logFile, true);/* www . j ava2s . c om*/ final Level[] levels = { org.jboss.logmanager.Level.FATAL, org.jboss.logmanager.Level.ERROR, org.jboss.logmanager.Level.WARN, org.jboss.logmanager.Level.INFO, org.jboss.logmanager.Level.DEBUG, org.jboss.logmanager.Level.TRACE }; final Map<Level, Integer> levelOrd = new HashMap<Level, Integer>(); levelOrd.put(org.jboss.logmanager.Level.FATAL, 0); levelOrd.put(org.jboss.logmanager.Level.ERROR, 1); levelOrd.put(org.jboss.logmanager.Level.WARN, 2); levelOrd.put(org.jboss.logmanager.Level.INFO, 3); levelOrd.put(org.jboss.logmanager.Level.DEBUG, 4); levelOrd.put(org.jboss.logmanager.Level.TRACE, 5); // log messages on all levels with different root logger level settings final ModelNode address = createRootLoggerAddress(loggingProfile).toModelNode(); for (Level level : levels) { // change root log level final ModelNode op = SubsystemOperations.createWriteAttributeOperation(address, CommonAttributes.LEVEL, level.getName()); executeOperation(kernelServices, op); doLog(loggingProfile, levels, "RootLoggerTestCaseTST %s", level); } // Remove the handler removeFileHandler(kernelServices, loggingProfile, fileHandlerName, true); // go through logged messages - test that with each root logger level settings // message with equal priority and also messages with all higher // priorities were logged final boolean[][] logFound = new boolean[levelOrd.size()][levelOrd.size()]; final List<String> logLines = FileUtils.readLines(logFile); for (String line : logLines) { if (!line.contains("RootLoggerTestCaseTST")) continue; // not our log final String[] words = line.split("\\s+"); try { final Level lineLogLevel = Level.parse(words[1]); final Level rootLogLevel = Level.parse(words[5]); final int producedLevel = levelOrd.get(lineLogLevel); final int loggedLevel = levelOrd.get(rootLogLevel); assertTrue(String.format("Produced level(%s) greater than logged level (%s)", lineLogLevel, rootLogLevel), producedLevel <= loggedLevel); logFound[producedLevel][loggedLevel] = true; } catch (Exception e) { throw new Exception("Unexpected log:" + line); } } for (Level level : levels) { final int rl = levelOrd.get(level); for (int ll = 0; ll <= rl; ll++) assertTrue(logFound[ll][rl]); } }
From source file:gov.llnl.lc.smt.command.config.SmtConfig.java
/** * Describe the method here/*from w w w. j av a 2 s . c om*/ * * @see describe related java objects * * @param options ***********************************************************/ private boolean configLogging() { boolean status = false; // fix any changes to the logging system if (sConfigMap.containsKey(SmtProperty.SMT_LOG_FILE.getName())) { status = true; // a valid argument String pattern = sConfigMap.get(SmtProperty.SMT_LOG_FILE.getName()); java.util.logging.Handler hpcHandlerF = null; try { // set the file pattern hpcHandlerF = new java.util.logging.FileHandler(pattern, true); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block, probably because path to logging is not set up // a typical error is; // java.io.IOException: Couldn't get lock for %h/.smt/smt-console%u.log e.printStackTrace(); } logger.addHandler(hpcHandlerF); Handler[] lhand = logger.getHandlers(); if (lhand.length > 1) { // changing to a new handler, get rid of the original one lhand[0].close(); logger.removeHandler(lhand[0]); logger.info("Replaced the original log handler"); } // Done, may want to clean up previous log file,if any?? } if (sConfigMap.containsKey(SmtProperty.SMT_LOG_LEVEL.getName())) { status = true; // a valid argument Level level = logger.getLevel(); // just keep the default try { Level l = Level.parse(sConfigMap.get(SmtProperty.SMT_LOG_LEVEL.getName())); level = l; } catch (IllegalArgumentException iae) { } logger.info("Setting the log level to: " + level.toString()); logger.setLevel(level); } return status; }
From source file:com.machinepublishers.jbrowserdriver.JBrowserDriver.java
private static void log(Logger logger, String prefix, String message) { if (logger != null && !filteredLogs.contains(message)) { LogRecord record = null;// ww w . j a va 2s . com if (message.startsWith(">")) { String[] parts = message.substring(1).split("/", 3); record = new LogRecord(Level.parse(parts[0]), new StringBuilder().append(prefix).append(" ").append(parts[2]).toString()); record.setSourceMethodName(parts[1]); record.setSourceClassName(JBrowserDriver.class.getName()); } else { record = new LogRecord(Level.WARNING, new StringBuilder().append(prefix).append(" ").append(message).toString()); record.setSourceMethodName(null); record.setSourceClassName(JBrowserDriver.class.getName()); } logger.log(record); } }
From source file:com.ellychou.todo.rest.service.SpringContextJerseyTest.java
/** * Register {@link Handler log handler} to the list of root loggers. *///ww w . j a v a2 s .c o m private void registerLogHandler() { final String recordLogLevel = getProperty(TestProperties.RECORD_LOG_LEVEL); final int recordLogLevelInt = Integer.valueOf(recordLogLevel); final Level level = Level.parse(recordLogLevel); logLevelMap.clear(); for (final Logger root : getRootLoggers()) { logLevelMap.put(root, root.getLevel()); if (root.getLevel().intValue() > recordLogLevelInt) { root.setLevel(level); } root.addHandler(getLogHandler()); } }
From source file:org.openconcerto.sql.PropsConfiguration.java
/** * For each property starting with {@link #LOG}, set the level of the specified logger to the * property's value. Eg if there's "log.level.=FINE", the root logger will be set to log FINE * messages.// w w w.j ava2 s . co m */ public final void setLoggersLevel() { this.propIterate(new IClosure<String>() { @Override public void executeChecked(final String propName) { final String logName = propName.substring(LOG.length()); LogUtils.getLogger(logName).setLevel(Level.parse(getProperty(propName))); } }, LOG); }
From source file:net.rptools.maptool.launcher.MapToolLauncher.java
private JPanel buildTroubleshootingPanel() { final JPanel p = new JPanel(); p.setLayout(new BorderLayout()); ActionListener levelChange = new ActionListener() { @Override//www.j a va 2s.c o m public void actionPerformed(ActionEvent e) { Level x = Level.parse(e.getActionCommand()); if (Level.OFF.equals(x) || Level.INFO.equals(x) || Level.WARNING.equals(x) || Level.SEVERE.equals(x)) log.setLevel(x); } }; JPanel logPanel = new JPanel(); logPanel.setLayout(new GridLayout(0, 1)); logPanel.setBorder(new TitledBorder(new LineBorder(Color.BLACK), CopiedFromOtherJars.getText("msg.logDetailPanel.border"))); //$NON-NLS-1$ logPanel.setAlignmentX(Component.LEFT_ALIGNMENT); ButtonGroup logGroup = new ButtonGroup(); for (Level type : new Level[] { Level.OFF, Level.INFO, Level.WARNING, Level.SEVERE }) { JRadioButton jrb = new JRadioButton(type.toString()); jrb.setActionCommand(type.toString()); jrb.addActionListener(levelChange); jrb.setBorder( BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red), jrb.getBorder())); logPanel.add(jrb); logGroup.add(jrb); if (type == Level.WARNING) { jrb.setSelected(true); log.setLevel(type); } } jcbEnableAssertions.setAlignmentX(Component.LEFT_ALIGNMENT); jcbEnableAssertions.setText(CopiedFromOtherJars.getText("msg.info.enableAssertions")); //$NON-NLS-1$ jcbEnableAssertions.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.enableAssertions")); //$NON-NLS-1$ jcbEnableAssertions.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { if (!extraArgs.contains(ASSERTIONS_OPTION)) { extraArgs = (ASSERTIONS_OPTION + " " + extraArgs); //$NON-NLS-1$ } } else if (e.getStateChange() == ItemEvent.DESELECTED) { extraArgs = extraArgs.replace(ASSERTIONS_OPTION, ""); //$NON-NLS-1$ } extraArgs = extraArgs.trim(); jtfArgs.setText(extraArgs); updateCommand(); } }); p.add(logPanel, BorderLayout.NORTH); Box other = new Box(BoxLayout.PAGE_AXIS); other.add(jcbEnableAssertions); other.add(Box.createVerticalGlue()); p.add(other, BorderLayout.CENTER); return p; }