java.util.logging.StreamHandler Java Examples

The following examples show how to use java.util.logging.StreamHandler. 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: CommandRunnerTest.java    From copybara with Apache License 2.0 6 votes vote down vote up
private CommandOutputWithStatus runCommand(CommandRunner commandRunner) throws CommandException {
  Logger logger = Logger.getLogger(CommandRunner.class.getName());
  boolean useParentLogger = logger.getUseParentHandlers();
  logger.setUseParentHandlers(false);
  StreamHandler handler = new StreamHandler() {
    @Override
    public synchronized void publish(LogRecord record) {
      logLines.add(record.getMessage());
    }
  };
  logger.addHandler(handler);
  PrintStream outRestore = System.out;
  PrintStream errRestore = System.err;
  System.setOut(new PrintStream(outContent));
  System.setErr(new PrintStream(errContent));
  try {
    return commandRunner.execute();
  } finally {
    System.setOut(outRestore);
    System.setErr(errRestore);
    logger.removeHandler(handler);
    logger.setUseParentHandlers(useParentLogger);
  }
}
 
Example #2
Source File: ProcessScopeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldLogExceptionStacktrace() throws IOException {
  Logger logger = Logger.getLogger(ProcessScope.class.getName());
  try (ByteArrayOutputStream out = new ByteArrayOutputStream();) {
    Handler handler = new StreamHandler(out, new SimpleFormatter());
    logger.addHandler(handler);
    try {
      ProcessScope scope = new ProcessScope();
      Object variable = scope.get("testObject", null);
      assertNull(variable);
    } finally {
      handler.flush();
      handler.close();
      logger.removeHandler(handler);
    }
    // test for logged exception
    String message = new String(out.toByteArray(), StandardCharsets.UTF_8);
    assertTrue(!message.isEmpty());
    assertTrue(message.contains("org.camunda.bpm.engine.spring.components.scope.ProcessScope get"));
    assertTrue(message.contains("couldn't return value from process scope! java.lang.NullPointerException"));
    assertTrue(message.contains("at org.camunda.bpm.engine.spring.components.scope.ProcessScope.getExecutionId(ProcessScope.java:")); 
    assertTrue(message.contains("at org.camunda.bpm.engine.spring.components.scope.ProcessScope.getConversationId(ProcessScope.java:")); 
    assertTrue(message.contains("at org.camunda.bpm.engine.spring.components.scope.ProcessScope.get(ProcessScope.java:")); 
    assertTrue(message.contains("at org.camunda.bpm.engine.spring.test.components.scope.ProcessScopeTest.shouldLogExceptionStacktrace(ProcessScopeTest.java:")); 
  }
}
 
Example #3
Source File: ConsoleShellFactory.java    From Bukkit-SSHD with Apache License 2.0 6 votes vote down vote up
public void start(Environment env) throws IOException {
    try {
        consoleReader = new ConsoleReader(in, new FlushyOutputStream(out), new SshTerminal());
        consoleReader.setExpandEvents(true);
        consoleReader.addCompleter(new ConsoleCommandCompleter());

        StreamHandler streamHandler = new FlushyStreamHandler(out, new ConsoleLogFormatter(), consoleReader);
        streamHandlerAppender = new StreamHandlerAppender(streamHandler);

        ((Logger) LogManager.getRootLogger()).addAppender(streamHandlerAppender);

        environment = env;
        thread = new Thread(this, "SSHD ConsoleShell " + env.getEnv().get(Environment.ENV_USER));
        thread.start();
    } catch (Exception e) {
        throw new IOException("Error starting shell", e);
    }
}
 
Example #4
Source File: Logger.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private static StreamHandler getTracingHandler( )
{
	if ( tracingHandler == null )
	{
		tracingHandler = AccessController.doPrivileged( new PrivilegedAction<StreamHandler>( ) {

			public StreamHandler run( )
			{
				StreamHandler handler = new StreamHandler( System.out,
						new SimpleFormatter( ) );
				try
				{
					tracingHandler.setLevel( Level.ALL );
				}
				catch ( SecurityException e )
				{
					e.printStackTrace( );
				}
				return handler;
			}
		} );
	}
	return tracingHandler;
}
 
Example #5
Source File: ExceptionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Test GlassFishException with message throwing and logging.
 */
@Test
public void testGlassFishExceptionWithMsg() {
    String gfieMsg = "Test 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 {
        throw new GlassFishIdeException(gfieMsg);
    } catch (GlassFishIdeException gfie) {
        handler.flush();
    } finally {
        logger.removeHandler(handler);
        handler.close();
        logger.setLevel(logLevel);
    }
    String logMsg = logOut.toString();
    int contains = logMsg.indexOf(gfieMsg);
    assertTrue(contains > -1);
}
 
Example #6
Source File: ExceptionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Test GlassFishException with no parameters specified throwing
 * and logging.
 */
@Test
public void testGlassFishExceptionWithNothing() {
    // this message must match GlassFishIdeException() constructor
    // log message.
    String gfieMsg = "Caught GlassFishIdeException.";
    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 {
        throw new GlassFishIdeException();
    } catch (GlassFishIdeException gfie) {
        handler.flush();
    } finally {
        logger.removeHandler(handler);
        handler.close();
        logger.setLevel(logLevel);
    }
    String logMsg = logOut.toString();
    int contains = logMsg.indexOf(gfieMsg);
    assertTrue(contains > -1);
}
 
Example #7
Source File: ExceptionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Test PayaraException with message throwing and logging.
 */
@Test
public void testPayaraExceptionWithMsg() {
    String gfieMsg = "Test 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 {
        throw new PayaraIdeException(gfieMsg);
    } catch (PayaraIdeException gfie) {
        handler.flush();
    } finally {
        logger.removeHandler(handler);
        handler.close();
        logger.setLevel(logLevel);
    }
    String logMsg = logOut.toString();
    int contains = logMsg.indexOf(gfieMsg);
    assertTrue(contains > -1);
}
 
Example #8
Source File: ExceptionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Test PayaraException with no parameters specified throwing
 * and logging.
 */
@Test
public void testPayaraExceptionWithNothing() {
    // this message must match PayaraIdeException() constructor
    // log message.
    String gfieMsg = "Caught PayaraIdeException.";
    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 {
        throw new PayaraIdeException();
    } catch (PayaraIdeException gfie) {
        handler.flush();
    } finally {
        logger.removeHandler(handler);
        handler.close();
        logger.setLevel(logLevel);
    }
    String logMsg = logOut.toString();
    int contains = logMsg.indexOf(gfieMsg);
    assertTrue(contains > -1);
}
 
Example #9
Source File: DispatchingHandlerTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testOwnFormatter() throws UnsupportedEncodingException {
    class MyFrmtr extends Formatter {
        private int cnt;
        @Override
        public String format(LogRecord record) {
            cnt++;
            return record.getMessage();
        }
    }
    MyFrmtr my = new MyFrmtr();
    
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    StreamHandler sh = new StreamHandler(os, NbFormatter.FORMATTER);
    DispatchingHandler dh = new DispatchingHandler(sh, 10);
    dh.setFormatter(my);
    dh.publish(new LogRecord(Level.WARNING, "Ahoj"));
    dh.flush();
    String res = new String(os.toByteArray(), "UTF-8");
    assertEquals("Only the message is written", "Ahoj", res);
    assertEquals("Called once", 1, my.cnt);
}
 
Example #10
Source File: ExceptionTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #11
Source File: LoggingSpanExporterTest.java    From opentelemetry-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testFlush() {
  final AtomicBoolean flushed = new AtomicBoolean(false);
  Logger.getLogger(LoggingSpanExporter.class.getName())
      .addHandler(
          new StreamHandler(System.err, new SimpleFormatter()) {
            @Override
            public synchronized void flush() {
              flushed.set(true);
            }
          });
  exporter.flush();
  assertThat(flushed.get()).isTrue();
}
 
Example #12
Source File: SyncMonitorTest.java    From mnIMAPSync with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setUp() {
  outputBuffer = spy(new ByteArrayOutputStream());
  System.setOut(new PrintStream(outputBuffer));
  Logger.getLogger(SyncMonitor.class.getName())
      .addHandler(new StreamHandler(outputBuffer, new Formatter() {
        @Override
        public String format(LogRecord record) {
          return record.getThrown().getMessage();
        }
      }));
}
 
Example #13
Source File: TopLogging.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Logger for test purposes.
 */
static Handler createStreamHandler (PrintStream pw) {
    StreamHandler s = new StreamHandler (
        pw, NbFormatter.FORMATTER
    );
    return NbLogging.createDispatchHandler(s, 50);
}
 
Example #14
Source File: NamedArgumentPlaceholderTest.java    From junit-dataprovider with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void prepareLogCapturing() {
    // Logger matches Logger in ClassUnderTest
    Logger logger = Logger.getLogger(NamedArgumentPlaceholder.class.getName());

    logCapturingStream = new ByteArrayOutputStream();
    Handler[] handlers = logger.getParent().getHandlers();
    customLogHandler = new StreamHandler(logCapturingStream, handlers[0].getFormatter());

    logger.addHandler(customLogHandler);
}
 
Example #15
Source File: TopLogging.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static synchronized Handler streamHandler() {
    if (streamHandler == null) {
        StreamHandler sth = new StreamHandler (OLD_ERR, NbFormatter.FORMATTER);
        sth.setLevel(Level.ALL);
        streamHandler = NbLogging.createDispatchHandler(sth, 500);
    }
    return streamHandler;
}
 
Example #16
Source File: LoggingMediaHttpUploaderProgressListenerTest.java    From hadoop-connectors with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  listener = new LoggingMediaHttpUploaderProgressListener("NAME", 60000L);

  jdkLoggerForConfig.setLevel(Level.FINE);
  logCapturingStream = new ByteArrayOutputStream();
  customLogHandler = new StreamHandler(logCapturingStream, LOG_FORMATTER);
  customLogHandler.setLevel(Level.FINE);
  jdkLoggerForConfig.addHandler(customLogHandler);
}
 
Example #17
Source File: ReportingTest.java    From vertx-unit with Apache License 2.0 5 votes vote down vote up
private String testLog(String name, Runnable runnable) {
  ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  StreamHandler handler = new StreamHandler(buffer, new java.util.logging.SimpleFormatter());
  Logger logger = Logger.getLogger(name);
  logger.addHandler(handler);
  try {
    runnable.run();
    handler.flush();
    return buffer.toString();
  } finally {
    logger.removeHandler(handler);
  }
}
 
Example #18
Source File: GridCommandHandlerClusterByClassTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Test checks that stack trace for unexpected error will be output with or
 * without {@link CommonArgParser#CMD_VERBOSE} flag.
 */
@Test
public void testErrUnexpectedWithWithoutVerbose() {
    injectTestSystemOut();

    Logger log = CommandHandler.initLogger(null);
    log.addHandler(new StreamHandler(System.out, new Formatter() {
        /** {@inheritDoc} */
        @Override public String format(LogRecord record) {
            String msg = record.getMessage();

            if (msg.contains("Cluster state:"))
                throw new Error();

            return msg + "\n";
        }
    }));

    int resCode = EXIT_CODE_UNEXPECTED_ERROR;
    CommandHandler cmd = new CommandHandler(log);

    assertEquals(resCode, execute(cmd, BASELINE.text()));
    assertContains(GridAbstractTest.log, testOut.toString(), ERROR_STACK_TRACE_PREFIX);

    assertEquals(resCode, execute(cmd, BASELINE.text(), CMD_VERBOSE));
    assertContains(GridAbstractTest.log, testOut.toString(), ERROR_STACK_TRACE_PREFIX);
}
 
Example #19
Source File: CommandHandler.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @return StreamHandler with empty formatting
 */
public static StreamHandler setupStreamHandler() {
    return new StreamHandler(System.out, new Formatter() {
        @Override public String format(LogRecord record) {
            return record.getMessage() + "\n";
        }
    });
}
 
Example #20
Source File: GemcachedDevelopmentJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();
  PORT = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
  this.server = new GemFireMemcachedServer(PORT, getProtocol());
  server.start();
  logger.addHandler(new StreamHandler());
  logger.info("SWAP:Running test:"+getName());
  logger.info("SWAP:userdir:"+System.getProperty("user.dir"));
}
 
Example #21
Source File: DomainObjectsAsValuesJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();
  PORT = AvailablePortHelper.getRandomAvailableTCPPort();
  this.server = new GemFireMemcachedServer(PORT);
  server.start();
  logger.addHandler(new StreamHandler());
  logger.info("SWAP:Running test:"+getName());
}
 
Example #22
Source File: LoggerTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Set up logger
 */
@Before
public void before() {
    fLogger = Logger.getAnonymousLogger();
    fLog = new StringOutputStream();
    fStreamHandler = new StreamHandler(fLog, new SimpleFormatter());
    fStreamHandler.setLevel(Level.FINER);
    fLogger.setLevel(Level.ALL);
    fLogger.addHandler(fStreamHandler);
}
 
Example #23
Source File: HandlersConfigTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
OutputStream getOutput(StreamHandler streamHandler) {
    try {
        return (OutputStream) streamHandlerOutput.get(streamHandler);
    } catch (IllegalAccessException e) {
        throw new IllegalAccessError(e.getMessage());
    }
}
 
Example #24
Source File: ExceptionTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Test GlassFishException with message and cause <code>Throwable</code>
 * throwing and logging.
 */
@Test
public void testGlassFishExceptionWithMsgAndCause() {
    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 GlassFishIdeException(gfieMsg, e);
        }
    } catch (GlassFishIdeException 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 #25
Source File: CatalogModelTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testDepResolver() throws URISyntaxException, CatalogModelException, IOException {
    
    Logger logger = Logger.getLogger(CatalogModelTest.class.getName());
    logger.setLevel(Level.ALL);
    StreamHandler sh = new MyHandler(System.out, new SimpleFormatter());
    sh.setLevel(logger.getLevel());
    //logger.addHandler(sh);
    CatalogFileWrapperDOMImpl.TEST_ENVIRONMENT = true;
    File catFile = new File(System.getProperty("java.io.tmpdir")+File.separator+CatalogWriteModel.PUBLIC_CATALOG_FILE_NAME+CatalogWriteModel.CATALOG_FILE_EXTENSION+".girish");
    catFile.delete();
    catFile.createNewFile();
    FileObject catFO = FileUtil.toFileObject(FileUtil.normalizeFile(catFile));
    URL url = getClass().getResource("dummyFile.txt");
    FileObject peerfo = FileUtil.toFileObject(new File(url.toURI()).getAbsoluteFile());
    System.out.println(catFile);
    CatalogWriteModel drz = new MyCatalogWriteModel(catFO);
    //CatalogWriteModel drz = new MyCatalogWriteModel(new File(System.getProperty("java.io.tmpdir")));
    drz.addURI(new URI("dummy/dummy"), peerfo);
    int length = drz.getCatalogEntries().size();
    
    assertEquals(1, length);
    
    //System.out.println("%%%%"+drz.getModelSource(new URI("dummy/dummy")).getFileObject());
    
    //System.out.println("$$$$"+LSResourceResolverFactory.getDefault().resolveResource(null, null, null, "dummy/dummy", url.toURI().toString()).getSystemId());
    
    //assertTrue(LSResourceResolverFactory.getDefault().resolveResource(null, null, null, "dummy/dummy", url.toURI().toString()).getSystemId().endsWith("dummyFile.txt"));
    
    FileObject fob = (FileObject) drz.getModelSource(new URI("dummy/dummy")).getLookup().lookup(FileObject.class);
    
    assertNotNull(fob);
    
    drz.removeURI(new URI("dummy/dummy"));
    
    length = drz.getCatalogEntries().size();
    
    assertEquals(0, length);
}
 
Example #26
Source File: HandlersConfigTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    // MemoryHandler

    check(new MemoryHandler(),
        Level.ALL, null, null, SimpleFormatter.class,
        ConfiguredHandler.class, 1000, Level.SEVERE);

    check(new MemoryHandler(new SpecifiedHandler(), 100, Level.WARNING),
        Level.ALL, null, null, SimpleFormatter.class,
        SpecifiedHandler.class, 100, Level.WARNING);

    // StreamHandler

    check(new StreamHandler(),
        Level.INFO, null, null, SimpleFormatter.class,
        null);

    check(new StreamHandler(System.out, new SpecifiedFormatter()),
        Level.INFO, null, null, SpecifiedFormatter.class,
        System.out);

    // ConsoleHandler

    check(new ConsoleHandler(),
        Level.INFO, null, null, SimpleFormatter.class,
        System.err);

    // SocketHandler (use the ServerSocket's port)

    try {
        check(new SocketHandler("localhost", serverSocket.getLocalPort()),
            Level.ALL, null, null, XMLFormatter.class);
    } catch (IOException e) {
        throw new RuntimeException("Can't connect to localhost:" + serverSocket.getLocalPort(), e);
    }
}
 
Example #27
Source File: HandlersConfigTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    // MemoryHandler

    check(new MemoryHandler(),
        Level.FINE, null, ConfiguredFilter.class, ConfiguredFormatter.class,
        ConfiguredHandler.class, 123, Level.FINE);

    check(new MemoryHandler(new SpecifiedHandler(), 100, Level.WARNING),
        Level.FINE, null, ConfiguredFilter.class, ConfiguredFormatter.class,
        SpecifiedHandler.class, 100, Level.WARNING);

    // StreamHandler

    check(new StreamHandler(),
        Level.FINE, "ASCII", ConfiguredFilter.class, ConfiguredFormatter.class,
        null);

    check(new StreamHandler(System.out, new SpecifiedFormatter()),
        Level.FINE, "ASCII", ConfiguredFilter.class, SpecifiedFormatter.class,
        System.out);

    // ConsoleHandler

    check(new ConsoleHandler(),
        Level.FINE, "ASCII", ConfiguredFilter.class, ConfiguredFormatter.class,
        System.err);

    // SocketHandler (use the ServerSocket's port)

    try {
        check(new SocketHandler("localhost", serverSocket.getLocalPort()),
            Level.FINE, "ASCII", ConfiguredFilter.class, ConfiguredFormatter.class);
    } catch (Exception e) {
        throw new RuntimeException("Can't connect to localhost:" + serverSocket.getLocalPort(), e);
    }
}
 
Example #28
Source File: HandlersConfigTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void check(StreamHandler handler,
           Level expectedLevel,
           String expectedEncoding,
           Class<? extends Filter> expectedFilterType,
           Class<? extends Formatter> expectedFormatterType,
           OutputStream expectedOutputStream) {
    checkEquals(handler, "outputStream", getOutput(handler), expectedOutputStream);
    check(handler, expectedLevel, expectedEncoding, expectedFilterType, expectedFormatterType);
}
 
Example #29
Source File: FixedConsoleHandler.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void close() {
	super.close();

	Method flushAndClose;
	try {
		flushAndClose = StreamHandler.class.getDeclaredMethod("flushAndClose", new Class[0]);
		flushAndClose.setAccessible(true);
		flushAndClose.invoke(this);
	} catch (Exception e) {
		// e.printStackTrace();
	}
}
 
Example #30
Source File: Log.java    From aws-codecommit-trigger-plugin with Apache License 2.0 5 votes vote down vote up
public static Log get(Class clazz, PrintStream out, boolean autoFormat) throws IOException {
    Log log = get(clazz);
    log.autoFormat = autoFormat;

    log.streamHandler = new StreamHandler(out, new SimpleFormatter());
    log.logger.addHandler(log.streamHandler);

    return log;
}