Java Code Examples for java.util.logging.Handler#setLevel()
The following examples show how to use
java.util.logging.Handler#setLevel() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShellBase.java From kalang with MIT License | 6 votes |
private void setLogLevel(Level logLevel) { Logger rootLogger = LogManager.getLogManager().getLogger(""); int oldLevel = rootLogger.getLevel().intValue(); int newLevel = logLevel.intValue(); rootLogger.setLevel(logLevel); for (Handler h : rootLogger.getHandlers()) { h.setFilter(record -> { int lv = record.getLevel().intValue(); if (lv > oldLevel) { return true; } String ln = record.getLoggerName(); return ln != null && ln.startsWith("kalang.compiler") && lv > newLevel; }); h.setLevel(logLevel); } }
Example 2
Source File: Logger.java From restcommander with Apache License 2.0 | 6 votes |
/** * Force logger to a new level. * @param level TRACE,DEBUG,INFO,WARN,ERROR,FATAL */ public static void setUp(String level) { if (forceJuli || log4j == null) { Logger.juli.setLevel(toJuliLevel(level)); } else { Logger.log4j.setLevel(org.apache.log4j.Level.toLevel(level)); if (redirectJuli) { java.util.logging.Logger rootLogger = java.util.logging.Logger.getLogger(""); for (Handler handler : rootLogger.getHandlers()) { rootLogger.removeHandler(handler); } Handler activeHandler = new JuliToLog4jHandler(); java.util.logging.Level juliLevel = toJuliLevel(level); activeHandler.setLevel(juliLevel); rootLogger.addHandler(activeHandler); rootLogger.setLevel(juliLevel); } } }
Example 3
Source File: JenkinsRule.java From jenkins-test-harness with MIT License | 6 votes |
@Override public Void call() throws RuntimeException { Handler handler = new Handler() { final Formatter formatter = new DeltaSupportLogFormatter(); @Override public void publish(LogRecord record) { if (isLoggable(record)) { stderr.getLogger().print(formatter.format(record).replaceAll("(?m)^([ 0-9.]*)", "$1[" + name + "] ")); stderr.getLogger().flush(); } } @Override public void flush() {} @Override public void close() throws SecurityException {} }; handler.setLevel(Level.ALL); loggers.entrySet().forEach(e -> { Logger logger = Logger.getLogger(e.getKey()); logger.setLevel(e.getValue()); logger.addHandler(handler); loggerReferences.add(logger); }); DeltaSupportLogFormatter.start = start; // match clock time on master stderr.getLogger().println("Set up log dumper on " + name + ": " + loggers); stderr.getLogger().flush(); return null; }
Example 4
Source File: ExceptionTest.java From netbeans with Apache License 2.0 | 5 votes |
/** * Test PayaraException with message and cause <code>Throwable</code> * throwing and logging. */ @Test public void testPayaraExceptionWithMsgAndCause() { String gfieMsg = "Test exception"; String causeMsg = "Cause exception"; java.util.logging.Logger logger = Logger.getLogger(); Level logLevel = logger.getLevel(); OutputStream logOut = new ByteArrayOutputStream(256); Handler handler = new StreamHandler(logOut, new SimpleFormatter()); handler.setLevel(Level.WARNING); logger.addHandler(handler); logger.setLevel(Level.WARNING); try { try { throw new Exception(causeMsg); } catch (Exception e) { throw new PayaraIdeException(gfieMsg, e); } } catch (PayaraIdeException gfie) { handler.flush(); } finally { logger.removeHandler(handler); handler.close(); logger.setLevel(logLevel); } String logMsg = logOut.toString(); int containsGfieMsg = logMsg.indexOf(gfieMsg); int containsCauseMsg = logMsg.indexOf(causeMsg); assertTrue(containsGfieMsg > -1 && containsCauseMsg > -1); }
Example 5
Source File: ArrayMonitorDemo.java From phoebus with Eclipse Public License 1.0 | 5 votes |
public static void main(String[] args) throws Exception { // Configure logging LogManager.getLogManager().readConfiguration(PVASettings.class.getResourceAsStream("/pva_logging.properties")); final Logger root = Logger.getLogger(""); // Profiler shows blocking in ConsoleHandler, // so reduce log messages to only warnings for performance tests root.setLevel(Level.WARNING); for (Handler handler : root.getHandlers()) handler.setLevel(root.getLevel()); // Start PVA servers ForkJoinPool.commonPool().submit(() -> serve("demo1", TimeUnit.MILLISECONDS, 10)); ForkJoinPool.commonPool().submit(() -> serve("demo2", TimeUnit.MILLISECONDS, 10)); ForkJoinPool.commonPool().submit(() -> serve("demo3", TimeUnit.MILLISECONDS, 10)); // PVA Client final PVAClient pva = new PVAClient(); final PVAChannel ch1 = pva.getChannel("demo1"); final PVAChannel ch2 = pva.getChannel("demo2"); final PVAChannel ch3 = pva.getChannel("demo3"); CompletableFuture.allOf(ch1.connect(), ch2.connect(), ch3.connect()).get(); final MonitorListener listener = (ch, changes, overruns, data) -> { // System.out.println(ch.getName() + " = " + data.get("value") + " " + overruns); PVADoubleArray array = data.get("value"); System.out.println(ch.getName() + " = " + array.get().length + " " + overruns); }; ch1.subscribe("", listener ); ch2.subscribe("", listener); ch3.subscribe("", listener); synchronized (ArrayMonitorDemo.class) { ArrayMonitorDemo.class.wait(); } }
Example 6
Source File: PythonProject.java From AndroidRobot with Apache License 2.0 | 5 votes |
private static final void replaceAllLogFormatters(Formatter form, Level level) /* */ { /* 179 */ LogManager mgr = LogManager.getLogManager(); /* 180 */ Enumeration loggerNames = mgr.getLoggerNames(); /* 181 */ while (loggerNames.hasMoreElements()) { /* 182 */ String loggerName = (String)loggerNames.nextElement(); /* 183 */ Logger logger = mgr.getLogger(loggerName); /* 184 */ for (Handler handler : logger.getHandlers()) { /* 185 */ handler.setFormatter(form); /* 186 */ handler.setLevel(level); /* */ } /* */ } /* */ }
Example 7
Source File: Logger.java From scelight with Apache License 2.0 | 5 votes |
/** * Sets the specified {@link LogLevel}. * * @param logLevel log level to be set */ public synchronized void setLogLevel( final LogLevel logLevel ) { this.logLevel = logLevel; logger.setLevel( logLevel.level ); for ( final Handler h : logger.getHandlers() ) h.setLevel( logLevel.level ); }
Example 8
Source File: TestHelper.java From phoebus with Eclipse Public License 1.0 | 5 votes |
public static void setup() { // Logging final Level level = Level.FINE; Logger logger = Logger.getLogger(""); logger.setLevel(level); for (Handler handler : logger.getHandlers()) handler.setLevel(level); }
Example 9
Source File: Logging.java From incubator-heron with Apache License 2.0 | 5 votes |
public static void configure(boolean verbose) { LoggingHelper.setLoggingFormat(DEFAULT_FORMAT); final Level level = verbose ? Level.ALL : Level.INFO; // configure the root heron logger and it's handlers Logger logger = Logger.getLogger(""); for (Handler handler : logger.getHandlers()) { handler.setLevel(level); } logger.setLevel(level); }
Example 10
Source File: AlipayLogger.java From alipay-sdk with Apache License 2.0 | 5 votes |
/** * 开启DEBUG级别日志(仅针对JDK14LOGGER,LOG4J请自行修改配置文件) * * @param isEnabled */ public static void setJDKDebugEnabled(Boolean isEnabled) { //如果使用JDK14LOGGER,将业务日志级别设为DEBUG(FINE) if (blog instanceof Jdk14Logger) { Jdk14Logger logger = (Jdk14Logger) blog; if (isEnabled) { logger.getLogger().setLevel(Level.FINE); Handler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(Level.FINE); logger.getLogger().addHandler(consoleHandler); } else { logger.getLogger().setLevel(Level.INFO); } } }
Example 11
Source File: Firewall.java From DeviceConnect-Android with MIT License | 5 votes |
/** * 接続元のIP制限リストを指定してファイアウォールを生成する. * * @param ipList IPのホワイトリスト。 */ public Firewall(final List<String> ipList) { mIPWhiteList = ipList; if (BuildConfig.DEBUG) { Handler handler = new AndroidHandler(TAG); handler.setFormatter(new SimpleFormatter()); handler.setLevel(Level.ALL); mLogger.addHandler(handler); mLogger.setLevel(Level.WARNING); } }
Example 12
Source File: ConnectDemo.java From phoebus with Eclipse Public License 1.0 | 5 votes |
public static void main(String[] args) throws Exception { // Configure logging LogManager.getLogManager().readConfiguration(PVASettings.class.getResourceAsStream("/pva_logging.properties")); final Logger root = Logger.getLogger(""); root.setLevel(Level.CONFIG); for (Handler handler : root.getHandlers()) handler.setLevel(root.getLevel()); // Start PVA server ForkJoinPool.commonPool().submit(() -> serve("demo1", TimeUnit.SECONDS, 1)); // PVA Client final PVAClient pva = new PVAClient(); while (true) { System.err.println("\nCREATE CHANNEL ----------------------------"); final PVAChannel ch = pva.getChannel("demo1"); ch.connect().get(); System.err.println("READ --------------------------------------"); final PVAStructure data = ch.read("").get(); System.err.println(ch.getName() + " = " + data.get("value")); System.err.println("CLOSE -------------------------------------\n"); ch.close(); // TimeUnit.SECONDS.sleep(1); } }
Example 13
Source File: TestInferCaller.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { TestInferCaller test = new TestInferCaller(); Logger root = Logger.getLogger(""); for (Handler h : root.getHandlers()) { h.setLevel(Level.OFF); } root.addHandler(new TestHandler()); for (Logger logger : Arrays.asList(root, Logger.getGlobal(), Logger.getAnonymousLogger(), Logger.getLogger("foo.bar"))) { System.out.println("Testing with: " + loggerName(logger) + " " + logger.getClass()); test.test(logger); } }
Example 14
Source File: JavaCompiler.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
public static void enableLogging() { Logger logger = Logger.getLogger(com.sun.tools.javac.Main.class.getPackage().getName()); logger.setLevel(Level.ALL); for (Handler h : logger.getParent().getHandlers()) { h.setLevel(Level.ALL); } }
Example 15
Source File: DConnectServerNanoHttpd.java From DeviceConnect-Android with MIT License | 5 votes |
/** * 設定値を元にサーバーを構築します. * * SSL設定がONの場合は、SSLServerSocketFactoryを指定する必要があります. * * @param config サーバー設定。 * @param context コンテキストオブジェクト。 * @param socketFactory SSLサーバーソケットファクトリー * @throws IllegalArgumentException SSL設定がONのときに socketFactory に<coce>null</coce>を指定した場合 */ public DConnectServerNanoHttpd(final DConnectServerConfig config, final Context context, final SSLServerSocketFactory socketFactory) { super(config); if (context == null) { throw new IllegalArgumentException("context must not be null."); } mContext = context; if (config.isSsl() && socketFactory == null) { throw new IllegalArgumentException("keyStoreManager must not be null if SSL is enabled."); } mServerSocketFactory = socketFactory; mAccessLogProvider = new AccessLogProvider(context); if (BuildConfig.DEBUG) { Handler handler = new AndroidHandler(TAG); handler.setFormatter(new SimpleFormatter()); handler.setLevel(Level.ALL); mLogger.addHandler(handler); mLogger.setLevel(Level.WARNING); mLogger.setUseParentHandlers(false); } else { mLogger.setLevel(Level.OFF); } }
Example 16
Source File: MonitorDemo.java From phoebus with Eclipse Public License 1.0 | 5 votes |
public static void main(String[] args) throws Exception { // Configure logging LogManager.getLogManager().readConfiguration(PVASettings.class.getResourceAsStream("/pva_logging.properties")); final Logger root = Logger.getLogger(""); // Profiler shows blocking in ConsoleHandler, // so reduce log messages to only warnings for performance tests root.setLevel(Level.WARNING); for (Handler handler : root.getHandlers()) handler.setLevel(root.getLevel()); // Start PVA servers ForkJoinPool.commonPool().submit(() -> ConnectDemo.serve("demo1", TimeUnit.MILLISECONDS, 10)); ForkJoinPool.commonPool().submit(() -> ConnectDemo.serve("demo2", TimeUnit.MILLISECONDS, 10)); ForkJoinPool.commonPool().submit(() -> ConnectDemo.serve("demo3", TimeUnit.MILLISECONDS, 10)); // PVA Client final PVAClient pva = new PVAClient(); final PVAChannel ch1 = pva.getChannel("demo1"); final PVAChannel ch2 = pva.getChannel("demo2"); final PVAChannel ch3 = pva.getChannel("demo3"); CompletableFuture.allOf(ch1.connect(), ch2.connect(), ch3.connect()).get(); final MonitorListener listener = (ch, changes, overruns, data) -> { System.out.println(ch.getName() + " = " + data.get("value") + " " + overruns); }; ch1.subscribe("", listener ); ch2.subscribe("", listener); ch3.subscribe("", listener); synchronized (MonitorDemo.class) { MonitorDemo.class.wait(); } }
Example 17
Source File: Log.java From pitest with Apache License 2.0 | 4 votes |
private static void setLevel(final Level level) { LOGGER.setLevel(level); for (final Handler each : LOGGER.getHandlers()) { each.setLevel(level); } }
Example 18
Source File: SheepCounterExample.java From java-monitoring-client-library with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { if (args.length < 1) { System.err.println("Missing required project argument"); System.err.printf( "Usage: java %s gcp-project-id [verbose]\n", SheepCounterExample.class.getName()); return; } String project = args[0]; // Turn up the logging verbosity if (args.length > 1) { Logger log = LogManager.getLogManager().getLogger(""); log.setLevel(Level.ALL); for (Handler h : log.getHandlers()) { h.setLevel(Level.ALL); } } // Create a sample resource. In this case, a GCE Instance. // See https://cloud.google.com/monitoring/api/resources for a list of resource types. MonitoredResource monitoredResource = new MonitoredResource() .setType("gce_instance") .setLabels( ImmutableMap.of( "instance_id", "test-instance", "zone", "us-central1-f")); // Set up the Metrics infrastructure. MetricWriter stackdriverWriter = new StackdriverWriter( createAuthorizedMonitoringClient(), project, monitoredResource, STACKDRIVER_MAX_QPS, STACKDRIVER_MAX_POINTS_PER_REQUEST); final MetricReporter reporter = new MetricReporter( stackdriverWriter, METRICS_REPORTING_INTERVAL, Executors.defaultThreadFactory()); reporter.startAsync().awaitRunning(); // Set up a handler to stop sleeping on SIGINT. Runtime.getRuntime() .addShutdownHook( new Thread( () -> { reporter.stopAsync().awaitTerminated(); // Allow the LogManager to cleanup the loggers. DelayedShutdownLogManager.resetFinally(); })); System.err.println("Send SIGINT (Ctrl+C) to stop sleeping."); while (true) { // Count some Googley sheep. int colorIndex = new Random().nextInt(SHEEP_COLORS.size()); int speciesIndex = new Random().nextInt(SHEEP_SPECIES.size()); sheepCounter.incrementBy(1, SHEEP_COLORS.get(colorIndex), SHEEP_SPECIES.get(speciesIndex)); sheepFluffiness.record( new Random().nextDouble() * 200, SHEEP_COLORS.get(colorIndex), SHEEP_SPECIES.get(speciesIndex)); isSleeping.set(true); logger.info("zzz..."); Thread.sleep(5000); } }
Example 19
Source File: SaslGSS.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { String name = "host." + OneKDC.REALM.toLowerCase(Locale.US); new OneKDC(null).writeJAASConf(); System.setProperty("javax.security.auth.useSubjectCredsOnly", "false"); // Client in JGSS so that it can control wrap privacy mode GSSManager m = GSSManager.getInstance(); GSSContext sc = m.createContext( m.createName(OneKDC.SERVER, GSSUtil.NT_GSS_KRB5_PRINCIPAL), GSSUtil.GSS_KRB5_MECH_OID, null, GSSContext.DEFAULT_LIFETIME); sc.requestMutualAuth(false); // Server in SASL final HashMap props = new HashMap(); props.put(Sasl.QOP, "auth-conf"); SaslServer ss = Sasl.createSaslServer("GSSAPI", "server", name, props, new CallbackHandler() { public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback cb : callbacks) { if (cb instanceof RealmCallback) { ((RealmCallback) cb).setText(OneKDC.REALM); } else if (cb instanceof AuthorizeCallback) { ((AuthorizeCallback) cb).setAuthorized(true); } } } }); ByteArrayOutputStream bout = new ByteArrayOutputStream(); PrintStream oldErr = System.err; System.setErr(new PrintStream(bout)); Logger.getLogger("javax.security.sasl").setLevel(Level.ALL); Handler h = new ConsoleHandler(); h.setLevel(Level.ALL); Logger.getLogger("javax.security.sasl").addHandler(h); byte[] token = new byte[0]; try { // Handshake token = sc.initSecContext(token, 0, token.length); token = ss.evaluateResponse(token); token = sc.unwrap(token, 0, token.length, new MessageProp(0, false)); token[0] = (byte)(((token[0] & 4) != 0) ? 4 : 2); token = sc.wrap(token, 0, token.length, new MessageProp(0, false)); ss.evaluateResponse(token); } finally { System.setErr(oldErr); } // Talk // 1. Client sends a auth-int message byte[] hello = "hello".getBytes(); MessageProp qop = new MessageProp(0, false); token = sc.wrap(hello, 0, hello.length, qop); // 2. Server accepts it anyway ss.unwrap(token, 0, token.length); // 3. Server sends a message token = ss.wrap(hello, 0, hello.length); // 4. Client accepts, should be auth-conf sc.unwrap(token, 0, token.length, qop); if (!qop.getPrivacy()) { throw new Exception(); } for (String s: bout.toString().split("\\n")) { if (s.contains("KRB5SRV04") && s.contains("NULL")) { return; } } System.out.println("======================="); System.out.println(bout.toString()); System.out.println("======================="); throw new Exception("Haven't seen KRB5SRV04 with NULL"); }
Example 20
Source File: LoopDemo.java From phoebus with Eclipse Public License 1.0 | 4 votes |
public static void main(String[] args) throws Exception { // Configure logging LogManager.getLogManager().readConfiguration(PVASettings.class.getResourceAsStream("/pva_logging.properties")); final Logger root = Logger.getLogger(""); // Profiler shows blocking in ConsoleHandler, // so reduce log messages to only warnings for performance tests root.setLevel(Level.WARNING); for (Handler handler : root.getHandlers()) handler.setLevel(root.getLevel()); // Start PVA server final PVAServer server = new PVAServer(); final PVATimeStamp time = new PVATimeStamp(); final PVADouble value = new PVADouble("value", 3.13); final PVAStructure data = new PVAStructure("demo", "demo_t", value, time); final ServerPV pv = server.createPV("demo", data); final Semaphore gotit = new Semaphore(0); ForkJoinPool.commonPool().submit(() -> { while (true) { // When monitor received a value... gotit.acquire(); value.set(value.get() + 1); time.set(Instant.now()); pv.update(data); } }); // PVA Client final PVAClient pva = new PVAClient(); final PVAChannel ch1 = pva.getChannel("demo"); ch1.connect().get(); final AtomicInteger updates = new AtomicInteger(); final MonitorListener listener = (ch, changes, overruns, received) -> { updates.incrementAndGet(); // System.out.println(ch.getName() + " = " + received.get("value") + " " + overruns); gotit.release(); }; ch1.subscribe("", listener ); while (true) { TimeUnit.SECONDS.sleep(1); System.out.println(updates.getAndSet(0) + " loops per second"); } }