List of usage examples for java.util.logging Level parse
public static synchronized Level parse(String name) throws IllegalArgumentException
From source file:org.apache.aurora.common.net.http.handlers.LogConfig.java
@POST @Produces(MediaType.TEXT_HTML)//from w ww . j a v a2 s.c om public String post(@FormParam("logger") String loggerName, @FormParam("level") String loggerLevel) throws TemplateException { Optional<String> configChange = Optional.empty(); if (loggerName != null && loggerLevel != null) { Logger logger = Logger.getLogger(loggerName); Level newLevel = loggerLevel.equals("INHERIT") ? null : Level.parse(loggerLevel); logger.setLevel(newLevel); if (newLevel != null) { maybeAdjustHandlerLevels(logger, newLevel); } configChange = Optional.of(String.format("%s level changed to %s", loggerName, loggerLevel)); } return displayPage(configChange); }
From source file:com.adr.taskexecutor.ui.TaskExecutorRemote.java
/** Creates new form TaskExecutorRemote */ public TaskExecutorRemote() { initComponents();// w w w . ja v a 2 s . c o m jLoggingLevel.addItem(Level.SEVERE); jLoggingLevel.addItem(Level.WARNING); jLoggingLevel.addItem(Level.INFO); jLoggingLevel.addItem(Level.CONFIG); jLoggingLevel.addItem(Level.FINE); jLoggingLevel.addItem(Level.FINER); jLoggingLevel.addItem(Level.FINEST); jLoggingLevel.addItem(Level.OFF); jLoggingLevel.addItem(Level.ALL); jURL.setText(Configuration.getInstance().getPreference("remote.serverurl", "http://localhost/taskexecutoree/executetask")); jLoggingLevel.setSelectedItem(Level .parse(Configuration.getInstance().getPreference("remote.logginglevel", Level.INFO.toString()))); jTrace.setSelected(Boolean .parseBoolean(Configuration.getInstance().getPreference("remote.trace", Boolean.FALSE.toString()))); jStats.setSelected(Boolean .parseBoolean(Configuration.getInstance().getPreference("remote.stats", Boolean.TRUE.toString()))); }
From source file:io.stallion.services.Log.java
public static void setLogLevelFromSettings() { if (!empty(Context.getSettings().getLogLevel())) { Level level = Level.parse(Context.getSettings().getLogLevel()); handler.setLevel(level);//from www . j a va 2s . com logger.setLevel(level); if (fileHandler != null) { fileHandler.setLevel(level); } } if (!empty(Context.getSettings().getPackageLogLevels())) { LogFilter filter = new LogFilter(logger.getLevel(), Context.getSettings().getPackageLogLevels()); logger.setFilter(filter); } }
From source file:org.apache.jena.atlas.logging.java.ConsoleHandlerStream.java
public ConsoleHandlerStream(OutputStream outputStream) { super(protectStdOutput(outputStream), new TextFormatter()); LogManager manager = LogManager.getLogManager(); ClassLoader classLoader = ClassLoader.getSystemClassLoader(); String cname = getClass().getName(); // -- Level/*from ww w . jav a 2 s . c om*/ Level level = Level.INFO; String pLevel = getProperty(manager, cname, "level"); if (pLevel != null) level = Level.parse(pLevel); setLevel(level); // -- Formatter // The default is TextFormatter above // (we had to pass a Formatter of some kind to super(,)). String pFormatter = getProperty(manager, cname, "formatter"); if (pFormatter != null) { try { Class<?> cls = classLoader.loadClass(pFormatter); setFormatter((Formatter) cls.newInstance()); } catch (Exception ex) { System.err.println("Problems setting the logging formatter"); ex.printStackTrace(System.err); } } // -- Filter String pFilter = getProperty(manager, cname, "filter"); if (pFilter != null) { try { Class<?> cls = classLoader.loadClass(pFilter); setFilter((Filter) cls.newInstance()); } catch (Exception ex) { System.err.println("Problems setting the logging filter"); ex.printStackTrace(System.err); } } // -- Encoding : Default UTF-8 String pEncoding = getProperty(manager, cname, "encoding"); if (pEncoding == null) pEncoding = StandardCharsets.UTF_8.name(); try { setEncoding(pEncoding); } catch (Exception e) { // That should work for UTF-8 as it is a required charset. System.err.print("Failed to set encoding: " + e.getMessage()); } }
From source file:dk.hippogrif.prettyxml.PrettyPrint.java
static String loadConfiguration(String resource) { try {/*from ww w . j a v a2 s .com*/ Properties prop = loadPropertiesResource(resource); // logging String loggingLevel = prop.getProperty("logging.Level"); if (loggingLevel != null) { Level level = Level.parse(loggingLevel); Logger l = Logger.getLogger("dk.hippogrif.prettyxml"); l.setLevel(level); if ("ConsoleHandler".equals(prop.getProperty("logging.Handler"))) { ConsoleHandler h = new ConsoleHandler(); h.setLevel(level); l.addHandler(h); } else if ("FileHandler".equals(prop.getProperty("logging.Handler"))) { FileHandler h = new FileHandler(System.getProperty("user.home") + "/prettyxml.log"); h.setLevel(level); l.addHandler(h); } logger.config("logging.Level=" + loggingLevel); } // version version = prop.getProperty("version", ""); logger.config("version=" + version); // wellknown encodings String s = prop.getProperty("encodings"); if (s == null) { throw new Exception("encodings missing in prettyxml.properties"); } encodings = s.split(";"); // wellknown property settings s = prop.getProperty("settings"); if (s == null) { throw new Exception("settings missing in prettyxml.properties"); } settings = s.split(";"); setting = new HashMap(); for (int i = 0; i < settings.length; i++) { String name = settings[i]; Properties props = loadPropertiesResource(name + ".properties"); checkProperties(props, false); setting.put(name, props); } // wellknown transformations s = prop.getProperty("transformations"); if (s == null) { throw new Exception("transformations missing in prettyxml.properties"); } transformations = s.split(";"); transformation = new HashMap(); for (int i = 0; i < transformations.length; i++) { String name = transformations[i]; transformation.put(name, mkTransformerResource(name + ".xslt")); } } catch (Exception e) { throw new RuntimeException(e); } return version; }
From source file:org.jamwiki.utils.WikiLogger.java
/** * *///from w w w. j a v a 2s . c om private static void initializeLogParams() { FileInputStream stream = null; try { File propertyFile = WikiLogger.loadProperties(); stream = new FileInputStream(propertyFile); Properties properties = new Properties(); properties.load(stream); String pattern = properties.getProperty("org.jamwiki.pattern"); int limit = new Integer(properties.getProperty("org.jamwiki.limit")).intValue(); int count = new Integer(properties.getProperty("org.jamwiki.count")).intValue(); boolean append = Boolean.valueOf(properties.getProperty("org.jamwiki.append")).booleanValue(); String datePattern = properties.getProperty("org.jamwiki.timestamp"); DEFAULT_LOG_LEVEL = Level.parse(properties.getProperty("org.jamwiki.level")); WikiLogger.DEFAULT_LOG_HANDLER = new FileHandler(pattern, limit, count, append); DEFAULT_LOG_HANDLER.setFormatter(new WikiLogFormatter(datePattern)); DEFAULT_LOG_HANDLER.setLevel(DEFAULT_LOG_LEVEL); // test the logger to verify permissions are OK Logger logger = Logger.getLogger(WikiLogger.class.getName()); logger.addHandler(WikiLogger.DEFAULT_LOG_HANDLER); logger.setLevel(DEFAULT_LOG_LEVEL); logger.config("JAMWiki log initialized from " + propertyFile.getPath() + " with pattern " + pattern); } catch (Exception e) { System.out.println("WARNING: Unable to load custom JAMWiki logging configuration, using system default " + e.getMessage()); WikiLogger.DEFAULT_LOG_HANDLER = null; } finally { if (stream != null) { try { stream.close(); } catch (Exception ex) { } } } }
From source file:com.twitter.common.net.http.handlers.LogConfig.java
protected void displayPage(final HttpServletRequest req, HttpServletResponse resp, final boolean posted) throws ServletException, IOException { writeTemplate(resp, new Closure<StringTemplate>() { @Override//from ww w . j a v a 2 s .com public void execute(StringTemplate stringTemplate) { LoggingMXBean logBean = LogManager.getLoggingMXBean(); if (posted) { String loggerName = req.getParameter("logger"); String loggerLevel = req.getParameter("level"); if (loggerName != null && loggerLevel != null) { Logger logger = Logger.getLogger(loggerName); Level newLevel = loggerLevel.equals("INHERIT") ? null : Level.parse(loggerLevel); logger.setLevel(newLevel); if (newLevel != null) { maybeAdjustHandlerLevels(logger, newLevel); } stringTemplate.setAttribute("configChange", String.format("%s level changed to %s", loggerName, loggerLevel)); } } List<LoggerConfig> loggerConfigs = Lists.newArrayList(); for (String logger : Ordering.natural().immutableSortedCopy(logBean.getLoggerNames())) { loggerConfigs.add(new LoggerConfig(logger, logBean.getLoggerLevel(logger))); } stringTemplate.setAttribute("loggers", loggerConfigs); stringTemplate.setAttribute("levels", LOG_LEVELS); } }); }
From source file:edu.usu.sdl.openstorefront.web.action.admin.LoggingAction.java
@HandlesEvent("UpdateLogLevel") public Resolution updateLogLevel() { Logger localLogger = LogManager.getLogManager().getLogger(logger); if (localLogger != null) { if (StringUtils.isNotBlank(level)) { localLogger.setLevel(Level.parse(level)); } else {/*from ww w . jav a 2s . c o m*/ localLogger.setLevel(null); } log.log(Level.INFO, SecurityUtil.adminAuditLogMessage(getContext().getRequest())); } else { throw new OpenStorefrontRuntimeException("Unable to find logger", "Check name"); } return viewLoggers(); }
From source file:tiemens.util.instancer.antlr.InstancerCode.java
public void configureLogging(final String loggingConfigureString) { logger.fine("I see logging of '" + loggingConfigureString + "'"); Level newLevel = null;/*from ww w. ja va 2 s . co m*/ try { newLevel = Level.parse(loggingConfigureString.toUpperCase()); } catch (IllegalArgumentException e) { newLevel = null; } if (newLevel != null) { // If the handler level is too high, you won't see stuff // So, change the handler(s) if needed: updateHandlers(newLevel, logger, loggingConfigureString); logger.setLevel(newLevel); logger.info("Set logging level to " + loggingConfigureString); } else { String msg = "Logging level '" + loggingConfigureString + "' not understood."; System.out.println(msg); logger.severe(msg); } }
From source file:io.trivium.Central.java
/** * parses command line arguments and sets up the server. * * @param args command line arguments// w w w. j a v a 2 s .c o m * @return true, if normal startup can proceed * @throws Exception */ public static boolean setup(String[] args) throws Exception { CommandLineParser parser = new PosixParser(); Options opts = new Options(); opts.addOption("ll", "loglevel", true, "turn logging to one of the following levels: fine,info,warning,severe"); opts.addOption("h", "help", false, "show help"); opts.addOption("?", "help", false, "show help"); opts.addOption("p", "path", true, "base path for the local storage"); opts.addOption("hp", "http", true, "port for the http interface, defaults to port 12345"); opts.addOption("cs", "cleanStore", false, "re-initializes the local store (all information will be lost)"); opts.addOption("cq", "cleanQueue", false, "re-initializes the local ingestion queue"); opts.addOption("t", "test", true, "starts test mode with target scope (default core)"); opts.addOption("c", "compress", true, "enable/disable snappy compression (default=true)"); opts.addOption("b", "build", false, "generate executable shell script"); CommandLine cmd = parser.parse(opts, args); if (cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("trivium", opts); return false; } if (cmd.hasOption("build")) { uuencode(); return false; } if (cmd.hasOption("loglevel")) { String val = cmd.getOptionValue("loglevel"); try { Level l = Level.parse(val.toUpperCase()); Central.setLogLevel(val); } catch (Exception ex) { logger.log(Level.WARNING, "log level was not recognized, falling back to default value"); } } if (cmd.hasOption("compress")) { String val = cmd.getOptionValue("compress"); if (val.equalsIgnoreCase("false")) { Central.setProperty("compression", "false"); } else { Central.setProperty("compression", "true"); } } else { Central.setProperty("compression", "true"); } if (cmd.hasOption("test")) { String target = cmd.getOptionValue("test"); Central.setProperty("test", target); } if (cmd.hasOption("path")) { String val = cmd.getOptionValue("path"); if (val != null && val.length() > 1) { if (!val.endsWith(File.separator)) val += File.separator; Central.setProperty("basePath", val); } else { Central.setProperty("basePath", System.getProperty("user.dir")); } } else { Central.setProperty("basePath", System.getProperty("user.dir")); } if (cmd.hasOption("cleanStore")) { StoreUtils.cleanStore(); } if (cmd.hasOption("cleanQueue")) { StoreUtils.cleanQueue(); } if (cmd.hasOption("http")) { String val = cmd.getOptionValue("http"); if (val != null && val.length() > 1) { try { int port = Integer.parseInt(val); if (port > 0 && port < 65535) Central.setProperty("httpPort", val); else throw new Exception("out of range"); } catch (Exception ex) { Central.setProperty("httpPort", "12345"); } } else { Central.setProperty("httpPort", "12345"); } } else { Central.setProperty("httpPort", "12345"); } Hardware.discover(); return true; }