Java Code Examples for java.util.logging.ConsoleHandler#setLevel()

The following examples show how to use java.util.logging.ConsoleHandler#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: RemoteWriteTest.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Main entry point for the OpenOffice.org Remote Write Test.
 *
 * @param args arguments of the test
 *
 * @author Andreas Bröker
 * @date 17.08.2006
 */
public static void main(String[] args) {
  if(args.length < 2) {
    System.out.println("NOA Remote Write Test");
    System.out.println("-------------------");
    System.out.println("Usage:");
    System.out.println("RemoteWriteTest <host> <port>");
  }
  else { 
    LogManager.getLogManager().reset();
    ConsoleHandler consoleHandler = new ConsoleHandler();
    consoleHandler.setLevel(Level.FINEST);
    LOGGER.addHandler(consoleHandler);
    LOGGER.setLevel(Level.FINEST);
    
    try {
      FileHandler fileHandler = new FileHandler("log.xml");
      fileHandler.setLevel(Level.FINEST);
      LOGGER.addHandler(fileHandler);
    }
    catch (Throwable throwable) {
    }
    RemoteWriteTest remoteWriteTest = new RemoteWriteTest();
    remoteWriteTest.test(args[0], args[1]);
  }
}
 
Example 2
Source File: IteratorTest.java    From blazingcache with Apache License 2.0 6 votes vote down vote up
@Before
public void setupLogger() throws Exception {
    Level level = Level.SEVERE;
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
            e.printStackTrace();
        }
    });
    java.util.logging.LogManager.getLogManager().reset();
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(level);
    SimpleFormatter f = new SimpleFormatter();
    ch.setFormatter(f);
    java.util.logging.Logger.getLogger("").setLevel(level);
    java.util.logging.Logger.getLogger("").addHandler(ch);
}
 
Example 3
Source File: Cloudsync.java    From cloudsync with GNU General Public License v2.0 6 votes vote down vote up
public Cloudsync(final String[] args)
{
	this.options = new CmdOptions(args);

	final Logger logger = Logger.getLogger("cloudsync");
	logger.setLevel(Level.ALL);

	java.util.logging.Handler[] handlers = logger.getHandlers();
	for(java.util.logging.Handler h : handlers) {
		h.close();
		logger.removeHandler(h);
	}
	final ConsoleHandler handler = new LogconsoleHandler();
	handler.setLevel(Level.ALL);
	logger.addHandler(handler);
	logger.setUseParentHandlers(false);
}
 
Example 4
Source File: Main.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
public static void initLogging(boolean debug) {
    try {
        Logger logger = Logger.getLogger("");
        logger.setLevel(Configuration.logLevel);

        Handler[] handlers = logger.getHandlers();
        for (int i = handlers.length - 1; i >= 0; i--) {
            logger.removeHandler(handlers[i]);
        }

        ConsoleHandler conHan = new ConsoleHandler();
        conHan.setLevel(debug ? Level.CONFIG : Level.WARNING);
        SimpleFormatter formatterTxt = new SimpleFormatter();
        conHan.setFormatter(formatterTxt);
        logger.addHandler(conHan);
        clearLogFile();

    } catch (Exception ex) {
        throw new RuntimeException("Problems with creating the log files");
    }
}
 
Example 5
Source File: JSRExamplesTest.java    From blazingcache with Apache License 2.0 6 votes vote down vote up
@Before
public void setupLogger() throws Exception {
    Level level = Level.SEVERE;
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            System.err.println("uncaughtException from thread " + t.getName() + ": " + e);
            e.printStackTrace();
        }
    });
    java.util.logging.LogManager.getLogManager().reset();
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(level);
    SimpleFormatter f = new SimpleFormatter();
    ch.setFormatter(f);
    java.util.logging.Logger.getLogger("").setLevel(level);
    java.util.logging.Logger.getLogger("").addHandler(ch);
}
 
Example 6
Source File: OgarServer.java    From Ogar2-Server with GNU General Public License v3.0 5 votes vote down vote up
private void setupLogging() {
    log.setUseParentHandlers(false);

    LogFormatter formatter = new LogFormatter();

    ConsoleHandler ch = new ConsoleHandler();
    ch.setFormatter(formatter);
    if (isDebugging()) {
        log.setLevel(Level.FINEST);
        ch.setLevel(Level.FINEST);
    } else {
        log.setLevel(Level.INFO);
        ch.setLevel(Level.INFO);
    }
    log.addHandler(ch);

    try {
        FileHandler fh = new FileHandler("server.log");
        fh.setFormatter(formatter);
        if (isDebugging()) {
            fh.setLevel(Level.FINEST);
        } else {
            ch.setLevel(Level.INFO);
        }
        log.addHandler(fh);
    } catch (IOException ex) {
        log.log(Level.SEVERE, "Error while adding FileHandler to logger. Logs will not be output to a file.", ex);
    }

}
 
Example 7
Source File: AnonymousOdsFileWriterTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Before
public final void setUp() {
    this.logger = PowerMock.createNiceMock(Logger.class);
    final ConsoleHandler handler = new ConsoleHandler();
    handler.setLevel(Level.FINEST);
    this.logger.addHandler(handler);
    this.os = new ByteArrayOutputStream();
    this.xmlUtil = XMLUtil.create();
    this.odsElements = PowerMock.createMock(OdsElements.class);
    this.builder = PowerMock.createMock(ZipUTF8WriterBuilderImpl.class);
    this.odsFactory = OdsFactory.create(this.logger, Locale.US);
}
 
Example 8
Source File: EchoServer.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private void enableDebugLogs()
{
    Logger l = Logger.getLogger("org.glassfish.grizzly.http.server.HttpHandler");
    l.setLevel(Level.FINE);
    l.setUseParentHandlers(false);
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(Level.ALL);
    l.addHandler(ch);
}
 
Example 9
Source File: RoundRobinConnectionStrategyTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
private static void set(final Logger logger, final Level level) {
    final ConsoleHandler consoleHandler = new ConsoleHandler();
    consoleHandler.setLevel(level);
    logger.addHandler(consoleHandler);
    logger.setLevel(level);
    logger.setUseParentHandlers(false);
}
 
Example 10
Source File: OfficeBeanTest.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Main entry point for the OpenOffice.org Bean Test.
 *
 * @param args arguments of the test
 *
 * @author Andreas Bröker
 * @date 21.05.2006
 */
public static void main(String[] args) throws OfficeApplicationException {

   LogManager.getLogManager().reset();
   ConsoleHandler consoleHandler = new ConsoleHandler();
   consoleHandler.setLevel(Level.FINEST);
   LOGGER.addHandler(consoleHandler);
   LOGGER.setLevel(Level.FINEST);

   try {
      FileHandler fileHandler = new FileHandler("log.xml");
      fileHandler.setLevel(Level.FINEST);
      LOGGER.addHandler(fileHandler);
   } catch (Throwable throwable) {
   }
   OfficeBeanTest testOfficeBean = new OfficeBeanTest();

   if (args.length == 0) {
      testOfficeBean.test(null);
   }else if (args.length == 1) {
      testOfficeBean.test(args[0]);
   }else if(args.length==4){
      testOfficeBean.remoteTestPDF(new File(args[2]), new File(args[3]), args[0], Integer.valueOf(args[1]));
   }else{
      System.out.println("usage:\nOfficeBeanTest host port source-odt target-pdf\nOfficeBeanTest officeHome");
   }
}
 
Example 11
Source File: PropertyTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
private void enableLogging(Class clazz) {
	Logger logger = Logger.getLogger(clazz.getName());
	ConsoleHandler handler = new ConsoleHandler();
	logger.addHandler(handler);
	handler.setLevel(Level.FINEST);
	logger.setLevel(Level.FINEST);
}
 
Example 12
Source File: ManagedSEDeployableContainer.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
private void configureLogging(ManagedSEContainerConfiguration configuration) {
    ConsoleHandler consoleHandler = new ConsoleHandler();
    consoleHandler.setLevel(configuration.getLogLevel());
    LOGGER.setUseParentHandlers(false);
    LOGGER.addHandler(consoleHandler);
    LOGGER.setLevel(configuration.getLogLevel());
}
 
Example 13
Source File: ExternalChangesTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@RandomlyFails
public void testLogExtCmdChanges () throws Exception {
    waitForInitialScan();
    FileChangeAdapter fca = new FileChangeAdapter();
    workdirFO.addRecursiveListener(fca);
    final File toAdd = new File(modifiedFile.getParentFile(), "toAdd");
    File toDelete = new File(modifiedFile.getParentFile(), "toDelete");
    toDelete.createNewFile();
    FileUtil.refreshFor(repositoryLocation);
    Thread.sleep(11000); // some time for initial scans to finish and event logger to settle down
    File gitFolder = new File(repositoryLocation, ".git");
    final File lockFile = new File(gitFolder, "index.lock");
    
    Logger.getLogger(FilesystemInterceptor.class.getName()).setLevel(Level.ALL);
    ConsoleHandler ch = new ConsoleHandler();
    ch.setLevel(Level.ALL);
    Logger.getLogger(FilesystemInterceptor.class.getName()).addHandler(ch);
    
    assertTrue(lockFile.createNewFile());
    FileUtil.refreshFor(repositoryLocation);
    pause();
    Thread.sleep(1100);
    assertTrue(lockFile.delete());
    FileUtil.refreshFor(repositoryLocation);
    Thread.sleep(1100);
    
    Logger GESTURES_LOG = Logger.getLogger("org.netbeans.ui.vcs");
    ExternalCommandUsageHandler h = new ExternalCommandUsageHandler();
    GESTURES_LOG.addHandler(h);
    assertTrue(lockFile.createNewFile());
    FileUtil.refreshFor(repositoryLocation);
    // modification
    write(modifiedFile, "testExternalCommandLoggedChanges");
    // delete
    toDelete.delete();
    // create
    toAdd.createNewFile();
    FileUtil.refreshFor(repositoryLocation);
    pause();
    Thread.sleep(1100);
    assertTrue(lockFile.delete());
    FileUtil.refreshFor(repositoryLocation);
    
    h.waitForEvent();
    assertNotNull(h.event);
    assertEquals(1, h.numberOfEvents);
    assertTrue(h.event.time > 0);
    assertEquals("GIT", h.event.vcs);
    assertEquals("UNKNOWN", h.event.command);
    assertTrue(h.event.external);
    assertEquals(Long.valueOf(3), h.event.modifications);
    GESTURES_LOG.removeHandler(h);
    workdirFO.removeRecursiveListener(fca);
    Logger.getLogger(FilesystemInterceptor.class.getName()).removeHandler(ch);
}
 
Example 14
Source File: JdpTestUtil.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
static void enableConsoleLogging(Logger log, Level level) throws SecurityException {
    ConsoleHandler handler = new ConsoleHandler();
    handler.setLevel(level);
    log.addHandler(handler);
    log.setLevel(level);
}
 
Example 15
Source File: JdpTestUtil.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
static void enableConsoleLogging(Logger log, Level level) throws SecurityException {
    ConsoleHandler handler = new ConsoleHandler();
    handler.setLevel(level);
    log.addHandler(handler);
    log.setLevel(level);
}
 
Example 16
Source File: SmokeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
static void initServer() throws Exception {

        Logger logger = Logger.getLogger("com.sun.net.httpserver");
        ConsoleHandler ch = new ConsoleHandler();
        logger.setLevel(Level.SEVERE);
        ch.setLevel(Level.SEVERE);
        logger.addHandler(ch);

        String root = System.getProperty ("test.src")+ "/docs";
        InetSocketAddress addr = new InetSocketAddress (0);
        s1 = HttpServer.create (addr, 0);
        if (s1 instanceof HttpsServer) {
            throw new RuntimeException ("should not be httpsserver");
        }
        s2 = HttpsServer.create (addr, 0);
        HttpHandler h = new FileServerHandler(root);

        HttpContext c1 = s1.createContext("/files", h);
        HttpContext c2 = s2.createContext("/files", h);
        HttpContext c3 = s1.createContext("/echo", new EchoHandler());
        redirectHandler = new RedirectHandler("/redirect");
        redirectHandlerSecure = new RedirectHandler("/redirect");
        HttpContext c4 = s1.createContext("/redirect", redirectHandler);
        HttpContext c41 = s2.createContext("/redirect", redirectHandlerSecure);
        HttpContext c5 = s2.createContext("/echo", new EchoHandler());
        HttpContext c6 = s1.createContext("/keepalive", new KeepAliveHandler());
        redirectErrorHandler = new RedirectErrorHandler("/redirecterror");
        redirectErrorHandlerSecure = new RedirectErrorHandler("/redirecterror");
        HttpContext c7 = s1.createContext("/redirecterror", redirectErrorHandler);
        HttpContext c71 = s2.createContext("/redirecterror", redirectErrorHandlerSecure);
        delayHandler = new DelayHandler();
        HttpContext c8 = s1.createContext("/delay", delayHandler);
        HttpContext c81 = s2.createContext("/delay", delayHandler);

        executor = Executors.newCachedThreadPool();
        s1.setExecutor(executor);
        s2.setExecutor(executor);
        ctx = new SimpleSSLContext().get();
        sslparams = ctx.getSupportedSSLParameters();
        s2.setHttpsConfigurator(new Configurator(ctx));
        s1.start();
        s2.start();

        port = s1.getAddress().getPort();
        System.out.println("HTTP server port = " + port);
        httpsport = s2.getAddress().getPort();
        System.out.println("HTTPS server port = " + httpsport);
        httproot = "http://127.0.0.1:" + port + "/";
        httpsroot = "https://127.0.0.1:" + httpsport + "/";

        proxy = new ProxyServer(0, false);
        proxyPort = proxy.getPort();
        System.out.println("Proxy port = " + proxyPort);
    }
 
Example 17
Source File: JavaLogger.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Configures handlers when needed.
 *
 * @param initImpl Optional log implementation.
 */
private void configure(@Nullable Logger initImpl) {
    if (initImpl != null)
        impl = initImpl;

    if (inited)
        return;

    synchronized (mux) {
        if (inited)
            return;

        if (isConfigured()) {
            boolean consoleHndFound = findHandler(impl, ConsoleHandler.class) != null;

            // User configured console appender, thus log is not quiet.
            quiet0 = !consoleHndFound;
            inited = true;
            cfg = System.getProperty("java.util.logging.config.file");

            return;
        }

        defaultConfiguration();

        boolean quiet = Boolean.valueOf(System.getProperty(IGNITE_QUIET, "true"));
        boolean useConsoleAppender = Boolean.valueOf(System.getProperty(IGNITE_CONSOLE_APPENDER, "true"));

        if (useConsoleAppender) {
            ConsoleHandler consoleHnd = findHandler(impl, ConsoleHandler.class);

            if (consoleHnd != null)
                consoleHnd.setLevel(quiet ? SEVERE : INFO);
            else
                System.err.println("Console logging handler is not configured.");
        }
        else {
            Handler[] handlers = Logger.getLogger("").getHandlers();

            if (!F.isEmpty(handlers)) {
                for (Handler h : handlers) {
                    if (h instanceof ConsoleHandler)
                        impl.removeHandler(h);
                }
            }
        }

        quiet0 = quiet;
        inited = true;
    }
}
 
Example 18
Source File: JdpTestUtil.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
static void enableConsoleLogging(Logger log, Level level) throws SecurityException {
    ConsoleHandler handler = new ConsoleHandler();
    handler.setLevel(level);
    log.addHandler(handler);
    log.setLevel(level);
}
 
Example 19
Source File: LoggingExample.java    From ExpectIt with Apache License 2.0 4 votes vote down vote up
static void disableLogging(ConsoleHandler handler) {
    final Logger logger = Logger.getLogger("net.sf.expectit");
    handler.setLevel(Level.INFO);
    logger.setLevel(Level.INFO);
}
 
Example 20
Source File: OLcServerShutdown.java    From Open-Lowcode with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @param port
 */
public OLcServerShutdown(int port) {
	Logger mainlogger = Logger.getLogger("");
	try {
		for (int i = 0; i < mainlogger.getHandlers().length; i++) {
			mainlogger.removeHandler(mainlogger.getHandlers()[i]);
		}
		ConsoleHandler consolehandler = new ConsoleHandler();
		consolehandler.setFormatter(new ConsoleFormatter());
		consolehandler.setLevel(Level.FINER);
		mainlogger.addHandler(consolehandler);
		File file = new File("./log/");
		System.err.println("log folder = " + file.getAbsolutePath());
		FileHandler logfilehandler = new FileHandler("./log/OpenLowcodeClient%g.log", 10000000, 1000, true);
		logfilehandler.setLevel(Level.FINEST);
		logfilehandler.setFormatter(new FileFormatter(true));
		mainlogger.addHandler(logfilehandler);
		mainlogger.setUseParentHandlers(false);
		// ------------------------------------------------------------------------------
		logger.severe("Connection to Open-Lowcode Server on localhost port " + port + " to send shutdown message");
		Socket clientsocket = new Socket("localhost", port);
		MessageSimpleReader reader = new MessageSimpleReader(
				new BufferedReader(new InputStreamReader(clientsocket.getInputStream()), 9090));
		MessageBufferedWriter writer = new MessageBufferedWriter(
				new BufferedWriter(new OutputStreamWriter(clientsocket.getOutputStream())), false);
		@SuppressWarnings("unused")
		AESCommunicator aescommunicator = AESCommunicator.performServerHandshake(reader, writer);
		writer.startNewMessage();
		writer.startStructure("SHUTDOWN");
		writer.endStructure("SHUTDOWN");
		writer.endMessage();
		writer.flushMessage();
		logger.severe("Succesfully sent shutdown message to server on port " + port);
		reader.returnNextMessageStart();
		reader.returnNextStartStructure("SHUTDOWNOK");
		reader.returnNextEndStructure("SHUTDOWNOK");
		reader.returnNextEndMessage();

		logger.severe(
				"Got last message from server before shutdown, all connections are stopped. Server will stop in less than 50ms");
		reader.close();
		writer.close();
		clientsocket.close();
	} catch (Exception e) {
		logger.severe("could not execute correctly shutdown script: " + e.getMessage());
		for (int i = 0; i < e.getStackTrace().length; i++) {
			logger.severe(e.getStackTrace()[i].toString());
		}
	}
}