Package java.util.logging

Examples of java.util.logging.StreamHandler


  /*
   * Test setEncoding() methods with unsupported encoding.
   */
  public void testSetEncoding_Unsupported() {
    StreamHandler h = new StreamHandler();
    try {
      h.setEncoding("impossible");
      fail("Should throw UnsupportedEncodingException!");
    } catch (UnsupportedEncodingException e) {
      // expected
    }
    assertNull(h.getEncoding());
  }
View Full Code Here


  /*
   * Test setEncoding() with insufficient privilege.
   */
  public void testSetEncoding_InsufficientPrivilege() throws Exception {
    StreamHandler h = new StreamHandler();
    SecurityManager oldMan = System.getSecurityManager();
    System.setSecurityManager(new MockSecurityManager());
    // set a normal value
    try {
      h.setEncoding("iso-8859-1");
      fail("Should throw SecurityException!");
    } catch (SecurityException e) {
      // expected
    } finally {
      System.setSecurityManager(oldMan);
    }
    assertNull(h.getEncoding());
    System.setSecurityManager(new MockSecurityManager());
    // set an invalid value
    try {

      h.setEncoding("impossible");
      fail("Should throw SecurityException!");
    } catch (SecurityException e) {
      // expected
    } finally {
      System.setSecurityManager(oldMan);
    }
    assertNull(h.getEncoding());
  }
View Full Code Here

  /*
   * Test setEncoding() methods will flush a stream before setting.
   */
  public void testSetEncoding_FlushBeforeSetting() throws Exception {
    ByteArrayOutputStream aos = new ByteArrayOutputStream();
    StreamHandler h = new StreamHandler(aos, new MockFormatter());
    LogRecord r = new LogRecord(Level.INFO, "abcd");
    h.publish(r);
    assertFalse(aos.toString().indexOf("abcd") > 0);
    h.setEncoding("iso-8859-1");
    assertTrue(aos.toString().indexOf("abcd") > 0);
  }
View Full Code Here

   * @param debug whether or not this is in debug mode
   */
  public void debug(boolean debug) {
    this.debug = debug;
    if (debug && debugHandler == null) {
          debugHandler = new StreamHandler(System.out, new SimpleFormatter());
          debugHandler.setLevel(Level.ALL);
    }
  }
View Full Code Here

   *          whether or not this is in debug mode
   */
  public synchronized void debug(boolean debug) {
    this.debug = debug;
    if (debug && debugHandler == null) {
      debugHandler = new StreamHandler(System.out, new SimpleFormatter());
      debugHandler.setLevel(Level.ALL);
    }
  }
View Full Code Here

   *          whether or not this is in debug mode
   */
  public synchronized void debug(boolean debug) {
    this.debug = debug;
    if (debug && debugHandler == null) {
      debugHandler = new StreamHandler(System.out, new SimpleFormatter());
      debugHandler.setLevel(Level.ALL);
    }
  }
View Full Code Here

    Logger.getLogger("").addHandler(fileHandler);

    PrintStream stdout = System.out;
    PrintStream stderr = System.err;

    Handler ConsoleHandle = new StreamHandler(stdout, new ClientLoggerFormatter());
    Logger.getLogger("").addHandler(ConsoleHandle);

    Handler ErrHandle = new StreamHandler(stderr, new ClientLoggerFormatter());
    Logger.getLogger("").addHandler(ErrHandle);

    Logger logger;
    SystemListenerStream los;
View Full Code Here

            // very odd, but lets tell the user and continue
            System.err.println(String.format(
                "Could not create log '%s' due to error '%s'",
                LOG_FILE_PATTERN, ioe.getLocalizedMessage()));
            System.err.println("Will send logs to standard.err instead.");
            handler = new StreamHandler(System.err, new UpgradeFormatter());
        }
        return handler;
    }
View Full Code Here

   *          whether or not this is in debug mode
   */
  public synchronized void debug(boolean debug) {
    this.debug = debug;
    if (debug && debugHandler == null) {
      debugHandler = new StreamHandler(System.out, new SimpleFormatter());
      debugHandler.setLevel(Level.ALL);
    }
  }
View Full Code Here

   *          whether or not this is in debug mode
   */
  public void debug(boolean debug) {
    this.debug = debug;
    if (debug && debugHandler == null) {
      debugHandler = new StreamHandler(System.out, new SimpleFormatter());
      debugHandler.setLevel(Level.ALL);
    }
  }
View Full Code Here

TOP

Related Classes of java.util.logging.StreamHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.