List of usage examples for java.util.logging Handler setLevel
public synchronized void setLevel(Level newLevel) throws SecurityException
From source file:brut.apktool.Main.java
private static void setupLogging(Verbosity verbosity) { Logger logger = Logger.getLogger(""); for (Handler handler : logger.getHandlers()) { logger.removeHandler(handler);/* w w w. j a v a 2s. c om*/ } LogManager.getLogManager().reset(); if (verbosity == Verbosity.QUIET) { return; } Handler handler = new Handler() { @Override public void publish(LogRecord record) { if (getFormatter() == null) { setFormatter(new SimpleFormatter()); } try { String message = getFormatter().format(record); if (record.getLevel().intValue() >= Level.WARNING.intValue()) { System.err.write(message.getBytes()); } else { System.out.write(message.getBytes()); } } catch (Exception exception) { reportError(null, exception, ErrorManager.FORMAT_FAILURE); } } @Override public void close() throws SecurityException { } @Override public void flush() { } }; logger.addHandler(handler); if (verbosity == Verbosity.VERBOSE) { handler.setLevel(Level.ALL); logger.setLevel(Level.ALL); } else { handler.setFormatter(new Formatter() { @Override public String format(LogRecord record) { return record.getLevel().toString().charAt(0) + ": " + record.getMessage() + System.getProperty("line.separator"); } }); } }
From source file:org.jenkinsci.plugins.workflow.WorkflowTest.java
@RandomlyFails("never printed 'finished waiting'") @Test/*from w w w.j a va 2 s . com*/ public void buildShellScriptAcrossDisconnect() throws Exception { story.addStep(new Statement() { @SuppressWarnings("SleepWhileInLoop") @Override public void evaluate() throws Throwable { Logger LOGGER = Logger.getLogger(DurableTaskStep.class.getName()); LOGGER.setLevel(Level.FINE); Handler handler = new ConsoleHandler(); handler.setLevel(Level.ALL); LOGGER.addHandler(handler); DumbSlave s = new DumbSlave("dumbo", "dummy", tmp.getRoot().getAbsolutePath(), "1", Node.Mode.NORMAL, "", new JNLPLauncher(), RetentionStrategy.NOOP, Collections.<NodeProperty<?>>emptyList()); story.j.jenkins.addNode(s); startJnlpProc(); p = story.j.jenkins.createProject(WorkflowJob.class, "demo"); File f1 = new File(story.j.jenkins.getRootDir(), "f1"); File f2 = new File(story.j.jenkins.getRootDir(), "f2"); new FileOutputStream(f1).close(); p.setDefinition(new CpsFlowDefinition("node('dumbo') {\n" + " sh 'touch \"" + f2 + "\"; while [ -f \"" + f1 + "\" ]; do sleep 1; done; echo finished waiting; rm \"" + f2 + "\"'\n" + " echo 'OK, done'\n" + "}")); startBuilding(); while (!f2.isFile()) { Thread.sleep(100); } assertTrue(b.isBuilding()); Computer c = s.toComputer(); assertNotNull(c); killJnlpProc(); while (c.isOnline()) { Thread.sleep(100); } startJnlpProc(); while (c.isOffline()) { Thread.sleep(100); } assertTrue(f2.isFile()); assertTrue(f1.delete()); while (f2.isFile()) { Thread.sleep(100); } story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b)); story.j.assertLogContains("finished waiting", b); story.j.assertLogContains("OK, done", b); killJnlpProc(); } }); }
From source file:org.jenkinsci.plugins.workflow.WorkflowTest.java
@RandomlyFails("TODO isBuilding assertion after restart occasionally fails; log ends with: Running: Allocate node : Body : Start (no shell step in sight)") @Test/* w w w.j av a 2 s . c o m*/ public void buildShellScriptAcrossRestart() throws Exception { story.addStep(new Statement() { @SuppressWarnings("SleepWhileInLoop") @Override public void evaluate() throws Throwable { Logger LOGGER = Logger.getLogger(DurableTaskStep.class.getName()); LOGGER.setLevel(Level.FINE); Handler handler = new ConsoleHandler(); handler.setLevel(Level.ALL); LOGGER.addHandler(handler); // Cannot use regular JenkinsRule.createSlave due to JENKINS-26398. // Nor can we can use JenkinsRule.createComputerLauncher, since spawned commands are killed by CommandLauncher somehow (it is not clear how; apparently before its onClosed kills them off). DumbSlave s = new DumbSlave("dumbo", "dummy", tmp.getRoot().getAbsolutePath(), "1", Node.Mode.NORMAL, "", new JNLPLauncher(), RetentionStrategy.NOOP, Collections.<NodeProperty<?>>emptyList()); story.j.jenkins.addNode(s); startJnlpProc(); p = story.j.jenkins.createProject(WorkflowJob.class, "demo"); File f1 = new File(story.j.jenkins.getRootDir(), "f1"); File f2 = new File(story.j.jenkins.getRootDir(), "f2"); new FileOutputStream(f1).close(); p.setDefinition(new CpsFlowDefinition("node('dumbo') {\n" + " sh 'touch \"" + f2 + "\"; while [ -f \"" + f1 + "\" ]; do sleep 1; done; echo finished waiting; rm \"" + f2 + "\"'\n" + " echo 'OK, done'\n" + "}")); startBuilding(); while (!f2.isFile()) { Thread.sleep(100); } assertTrue(b.isBuilding()); killJnlpProc(); } }); story.addStep(new Statement() { @Override public void evaluate() throws Throwable { rebuildContext(story.j); assertTrue(b.isBuilding()); startJnlpProc(); // Have to relaunch JNLP agent, since the Jenkins port has changed, and we cannot force JenkinsRule to reuse the same port as before. File f1 = new File(story.j.jenkins.getRootDir(), "f1"); File f2 = new File(story.j.jenkins.getRootDir(), "f2"); assertTrue(f2.isFile()); assertTrue(f1.delete()); while (f2.isFile()) { Thread.sleep(100); } story.j.assertBuildStatusSuccess(JenkinsRuleExt.waitForCompletion(b)); story.j.assertLogContains("finished waiting", b); story.j.assertLogContains("OK, done", b); killJnlpProc(); } }); }
From source file:org.apache.qpid.amqp_1_0.client.Util.java
protected Util(String[] args) { CommandLineParser cmdLineParse = new PosixParser(); Options options = new Options(); options.addOption("h", "help", false, "show this help message and exit"); options.addOption(OptionBuilder.withLongOpt("host").withDescription("host to connect to (default 0.0.0.0)") .hasArg(true).withArgName("HOST").create('H')); options.addOption(//from www.ja v a 2 s . co m OptionBuilder.withLongOpt("username").withDescription("username to use for authentication") .hasArg(true).withArgName("USERNAME").create('u')); options.addOption( OptionBuilder.withLongOpt("password").withDescription("password to use for authentication") .hasArg(true).withArgName("PASSWORD").create('w')); options.addOption(OptionBuilder.withLongOpt("port").withDescription("port to connect to (default 5672)") .hasArg(true).withArgName("PORT").create('p')); options.addOption(OptionBuilder.withLongOpt("frame-size").withDescription("specify the maximum frame size") .hasArg(true).withArgName("FRAME_SIZE").create('f')); options.addOption(OptionBuilder.withLongOpt("container-name").withDescription("Container name").hasArg(true) .withArgName("CONTAINER_NAME").create('C')); options.addOption(OptionBuilder.withLongOpt("ssl").withDescription("Use SSL").create('S')); options.addOption( OptionBuilder.withLongOpt("remote-hostname").withDescription("hostname to supply in the open frame") .hasArg(true).withArgName("HOST").create('O')); if (hasBlockOption()) options.addOption( OptionBuilder.withLongOpt("block").withDescription("block until messages arrive").create('b')); if (hasCountOption()) options.addOption( OptionBuilder.withLongOpt("count").withDescription("number of messages to send (default 1)") .hasArg(true).withArgName("COUNT").create('c')); if (hasModeOption()) options.addOption(OptionBuilder.withLongOpt("acknowledge-mode") .withDescription("acknowledgement mode: AMO|ALO|EO (At Least Once, At Most Once, Exactly Once") .hasArg(true).withArgName("MODE").create('k')); if (hasSubjectOption()) options.addOption(OptionBuilder.withLongOpt("subject").withDescription("subject message property") .hasArg(true).withArgName("SUBJECT").create('s')); if (hasSingleLinkPerConnectionMode()) options.addOption(OptionBuilder.withLongOpt("single-link-per-connection") .withDescription("acknowledgement mode: AMO|ALO|EO (At Least Once, At Most Once, Exactly Once") .hasArg(false).create('Z')); if (hasFilterOption()) options.addOption(OptionBuilder.withLongOpt("filter") .withDescription("filter, e.g. exact-subject=hello; matching-subject=%.a.#").hasArg(true) .withArgName("<TYPE>=<VALUE>").create('F')); if (hasTxnOption()) { options.addOption("x", "txn", false, "use transactions"); options.addOption( OptionBuilder.withLongOpt("batch-size").withDescription("transaction batch size (default: 1)") .hasArg(true).withArgName("BATCH-SIZE").create('B')); options.addOption(OptionBuilder.withLongOpt("rollback-ratio") .withDescription("rollback ratio - must be between 0 and 1 (default: 0)").hasArg(true) .withArgName("RATIO").create('R')); } if (hasLinkDurableOption()) { options.addOption("d", "durable-link", false, "use a durable link"); } if (hasStdInOption()) options.addOption("i", "stdin", false, "read messages from stdin (one message per line)"); options.addOption( OptionBuilder.withLongOpt("trace").withDescription("trace logging specified categories: RAW, FRM") .hasArg(true).withArgName("TRACE").create('t')); if (hasSizeOption()) options.addOption( OptionBuilder.withLongOpt("message-size").withDescription("size to pad outgoing messages to") .hasArg(true).withArgName("SIZE").create('z')); if (hasResponseQueueOption()) options.addOption( OptionBuilder.withLongOpt("response-queue").withDescription("response queue to reply to") .hasArg(true).withArgName("RESPONSE_QUEUE").create('r')); if (hasLinkNameOption()) { options.addOption(OptionBuilder.withLongOpt("link").withDescription("link name").hasArg(true) .withArgName("LINK").create('l')); } if (hasWindowSizeOption()) { options.addOption(OptionBuilder.withLongOpt("window-size").withDescription("credit window size") .hasArg(true).withArgName("WINDOW-SIZE").create('W')); } CommandLine cmdLine = null; try { cmdLine = cmdLineParse.parse(options, args); } catch (ParseException e) { printUsage(options); System.exit(-1); } if (cmdLine.hasOption('h') || cmdLine.getArgList().isEmpty()) { printUsage(options); System.exit(0); } _host = cmdLine.getOptionValue('H', "0.0.0.0"); _remoteHost = cmdLine.getOptionValue('O', null); String portStr = cmdLine.getOptionValue('p', "5672"); String countStr = cmdLine.getOptionValue('c', "1"); _useSSL = cmdLine.hasOption('S'); if (hasWindowSizeOption()) { String windowSizeStr = cmdLine.getOptionValue('W', "100"); _windowSize = Integer.parseInt(windowSizeStr); } if (hasSubjectOption()) { _subject = cmdLine.getOptionValue('s'); } if (cmdLine.hasOption('u')) { _username = cmdLine.getOptionValue('u'); } if (cmdLine.hasOption('w')) { _password = cmdLine.getOptionValue('w'); } if (cmdLine.hasOption('F')) { _filter = cmdLine.getOptionValue('F'); } _port = Integer.parseInt(portStr); _containerName = cmdLine.getOptionValue('C'); if (hasBlockOption()) _block = cmdLine.hasOption('b'); if (hasLinkNameOption()) _linkName = cmdLine.getOptionValue('l'); if (hasLinkDurableOption()) _durableLink = cmdLine.hasOption('d'); if (hasCountOption()) _count = Integer.parseInt(countStr); if (hasStdInOption()) _useStdIn = cmdLine.hasOption('i'); if (hasSingleLinkPerConnectionMode()) _useMultipleConnections = cmdLine.hasOption('Z'); if (hasTxnOption()) { _useTran = cmdLine.hasOption('x'); _batchSize = Integer.parseInt(cmdLine.getOptionValue('B', "1")); _rollbackRatio = Double.parseDouble(cmdLine.getOptionValue('R', "0")); } if (hasModeOption()) { _mode = AcknowledgeMode.ALO; if (cmdLine.hasOption('k')) { _mode = AcknowledgeMode.valueOf(cmdLine.getOptionValue('k')); } } if (hasResponseQueueOption()) { _responseQueue = cmdLine.getOptionValue('r'); } _frameSize = Integer.parseInt(cmdLine.getOptionValue('f', "65536")); if (hasSizeOption()) { _messageSize = Integer.parseInt(cmdLine.getOptionValue('z', "-1")); } String categoriesList = cmdLine.getOptionValue('t'); String[] categories = categoriesList == null ? new String[0] : categoriesList.split("[, ]"); for (String cat : categories) { if (cat.equalsIgnoreCase("FRM")) { FRAME_LOGGER.setLevel(Level.FINE); Formatter formatter = new Formatter() { @Override public String format(final LogRecord record) { return "[" + record.getMillis() + " FRM]\t" + record.getMessage() + "\n"; } }; for (Handler handler : FRAME_LOGGER.getHandlers()) { FRAME_LOGGER.removeHandler(handler); } Handler handler = new ConsoleHandler(); handler.setLevel(Level.FINE); handler.setFormatter(formatter); FRAME_LOGGER.addHandler(handler); } else if (cat.equalsIgnoreCase("RAW")) { RAW_LOGGER.setLevel(Level.FINE); Formatter formatter = new Formatter() { @Override public String format(final LogRecord record) { return "[" + record.getMillis() + " RAW]\t" + record.getMessage() + "\n"; } }; for (Handler handler : RAW_LOGGER.getHandlers()) { RAW_LOGGER.removeHandler(handler); } Handler handler = new ConsoleHandler(); handler.setLevel(Level.FINE); handler.setFormatter(formatter); RAW_LOGGER.addHandler(handler); } } _args = cmdLine.getArgs(); }
From source file:es.upm.dit.gsi.sim.twitter.TwitterSimulation.java
/** * Constructor//from w ww . j av a2s. com * * @param seed */ public TwitterSimulation(long seed, List<String> topics) { super(seed); Logger globalLogger = logger.getParent(); globalLogger.setLevel(level); for (Handler handler : globalLogger.getHandlers()) { handler.setLevel(level); } this.topicManager = new TopicManager(); this.topicManager.setTopics(topics); }
From source file:es.upm.dit.gsi.sim.twitter.TwitterSimulation.java
/** * @param seed/*from w ww.ja v a 2s .c o m*/ * @param network */ public TwitterSimulation(long seed, Network network, List<String> topics) { super(seed); Logger globalLogger = logger.getParent(); globalLogger.setLevel(level); for (Handler handler : globalLogger.getHandlers()) { handler.setLevel(level); } this.topicManager = new TopicManager(); this.topicManager.setTopics(topics); this.initialNetwork = network; this.loadInitialNetwork = true; }
From source file:tiemens.util.instancer.antlr.InstancerCode.java
/** * If loggingConfigureString is NOT UPPER CASE, * Then/*from w ww .ja v a 2 s . c o m*/ * If uselogger's handler(s) are examined and changed if they * would not log at 'newLevel' * * @param newLevel the parsed loggingConfigureString * @param uselogger whose handler(s) we change * @param loggingConfigureString original configuration string */ private void updateHandlers(Level newLevel, Logger uselogger, String loggingConfigureString) { List<Handler> handlers = new ArrayList<Handler>(); Logger walk = uselogger; while (walk != null) { for (Handler add : walk.getHandlers()) { handlers.add(add); } walk = walk.getParent(); } for (Handler handler : handlers) { metaLoggerInfo( "Handler level = " + handler.getLevel().intValue() + "newLevel = " + newLevel.intValue()); if (handler.getLevel().intValue() > newLevel.intValue()) { if (!loggingConfigureString.equals(loggingConfigureString.toUpperCase())) { String note = "Note: setting handler level to '" + loggingConfigureString + "'."; String explain = "Use '" + loggingConfigureString.toUpperCase() + "' to prevent this behavior."; String msg = "Instancer: " + note + " " + explain; metaLoggerInfo(msg); logger.info(msg); handler.setLevel(newLevel); } } } }
From source file:processing.app.Base.java
static public void initLogger() { Handler consoleHandler = new ConsoleLogger(); consoleHandler.setLevel(Level.ALL); consoleHandler.setFormatter(new LogFormatter("%1$tl:%1$tM:%1$tS [%4$7s] %2$s: %5$s%n")); Logger globalLogger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); globalLogger.setLevel(consoleHandler.getLevel()); // Remove default Handler[] handlers = globalLogger.getHandlers(); for (Handler handler : handlers) { globalLogger.removeHandler(handler); }/*from www. j av a 2 s . c o m*/ Logger root = Logger.getLogger(""); handlers = root.getHandlers(); for (Handler handler : handlers) { root.removeHandler(handler); } globalLogger.addHandler(consoleHandler); Logger.getLogger("cc.arduino.packages.autocomplete").setParent(globalLogger); Logger.getLogger("br.com.criativasoft.cpluslibparser").setParent(globalLogger); Logger.getLogger(Base.class.getPackage().getName()).setParent(globalLogger); }
From source file:org.tigase.messenger.phone.pro.service.XMPPService.java
public XMPPService() { Logger logger = Logger.getLogger("tigase.jaxmpp"); Handler handler = new AndroidLoggingHandler(); handler.setLevel(Level.ALL); logger.addHandler(handler);/*from ww w . j av a 2 s .c o m*/ logger.setLevel(Level.ALL); }