List of usage examples for java.lang System setErr
public static void setErr(PrintStream err)
From source file:mockit.integration.logging.LoggingIntegrationsTest.java
@BeforeClass public static void redirectSystemOut() { originalErr = System.err;/*from w ww . j ava2 s . c o m*/ OutputStream testOutput = new OutputStream() { @Override public void write(int b) { fail("Logger wrote output message!"); } }; System.setErr(new PrintStream(testOutput)); }
From source file:com.clustercontrol.util.StdOutErrLog.java
/** * ?log4j??<br/>/*from w w w . j a v a 2 s .c o m*/ */ public static void initialize() { System.setOut(new PrintStream(new LoggerStream(log))); System.setErr(new PrintStream(new LoggerStream(log))); }
From source file:mockit.integration.logging.LoggingIntegrationsTest.java
@AfterClass public static void restoreSystemErr() { System.setErr(originalErr); }
From source file:org.marketcetera.util.ws.wrappers.RemoteProxyExceptionTest.java
private static String getStackTraceNoArg(RemoteProxyException ex) { PrintStream stdErrSave = System.err; CloseableRegistry r = new CloseableRegistry(); ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); try {/*w w w.ja v a2 s .com*/ r.register(byteArray); PrintStream stdErr = new PrintStream(byteArray); r.register(stdErr); System.setErr(stdErr); ex.printStackTrace(); } finally { System.setErr(stdErrSave); r.close(); } return new String(byteArray.toByteArray()); }
From source file:Main.java
public Main() { setSize(300, 300);/*from w w w.ja v a2 s . c o m*/ add("Center", new JScrollPane(aTextArea)); setVisible(true); System.setOut(aPrintStream); // catches System.out messages System.setErr(aPrintStream); // catches error messages }
From source file:fi.jumi.core.stdout.SystemOutErrTest.java
@After public void restoreStdoutStderr() { System.setOut(originalStdout); System.setErr(originalStderr); }
From source file:StdErrOutWindows.java
public StdErrOutWindows() { JScrollPane pain = new JScrollPane(outArea); JFrame outFrame = new JFrame("out"); outFrame.getContentPane().add(pain); outFrame.setVisible(true);/*from www . j a va 2 s . c o m*/ pain = new JScrollPane(errArea); JFrame errFrame = new JFrame("err"); errFrame.getContentPane().add(pain); errFrame.setLocation(errFrame.getLocation().x + 20, errFrame.getLocation().y + 20); errFrame.setVisible(true); System.setOut(new PrintStream(new JTextAreaOutputStream(outArea))); System.setErr(new PrintStream(new JTextAreaOutputStream(errArea))); }
From source file:edu.stanford.muse.email.VerifyEmailSetup.java
public static Pair<Boolean, String> run() { PrintStream savedOut = System.out; InputStream savedIn = System.in; try {//from w ww. j a v a2 s .co m // Get a Properties object Properties props = System.getProperties(); // Get a Session object Session session = Session.getInstance(props, null); session.setDebug(true); String filename = System.getProperty("java.io.tmpdir") + File.separatorChar + "verifyEmailSetup"; PrintStream ps = new PrintStream(new FileOutputStream(filename)); System.setOut(ps); System.setErr(ps); // Get a Store object Store store = null; store = session.getStore("imaps"); store.connect("imap.gmail.com", 993, "checkmuse", ""); // not the real password. unfortunately, the checkmuse a/c will get blocked by google. // Folder folder = store.getFolder("[Gmail]/Sent Mail"); // int totalMessages = folder.getMessageCount(); // System.err.println (totalMessages + " messages!"); ps.close(); String contents = Util.getFileContents(filename); System.out.println(contents); return new Pair<Boolean, String>(Boolean.TRUE, contents); } catch (AuthenticationFailedException e) { /* its ok if auth failed. we only want to check if IMAPS network route is blocked. when network is blocked, we'll get something like javax.mail.MessagingException: No route to host; nested exception is: java.net.NoRouteToHostException: No route to host ... */ log.info("Verification succeeded: " + Util.stackTrace(e)); return new Pair<Boolean, String>(Boolean.TRUE, ""); } catch (Exception e) { log.warn("Verification failed: " + Util.stackTrace(e)); return new Pair<Boolean, String>(Boolean.FALSE, e.toString()); // stack track reveals too much about our code... Util.stackTrace(e)); } finally { System.setOut(savedOut); System.setIn(savedIn); } }
From source file:com.iciql.test.IciqlSuite.java
/** * Main entry point for the test suite. Executing this method will run the * test suite on all registered databases. * /*from w w w .ja v a2 s .co m*/ * @param args * @throws Exception */ public static void main(String... args) throws Exception { Params params = new Params(); JCommander jc = new JCommander(params); try { jc.parse(args); } catch (ParameterException t) { usage(jc, t); } // Replace System.out with a file if (!StringUtils.isNullOrEmpty(params.dbPerformanceFile)) { out = new PrintStream(params.dbPerformanceFile); System.setErr(out); } deleteRecursively(new File("testdbs")); // Start the HSQL and H2 servers in-process org.hsqldb.Server hsql = startHSQL(); org.h2.tools.Server h2 = startH2(); // Statement logging final FileWriter statementWriter; if (StringUtils.isNullOrEmpty(params.sqlStatementsFile)) { statementWriter = null; } else { statementWriter = new FileWriter(params.sqlStatementsFile); } IciqlListener statementListener = new IciqlListener() { @Override public void logIciql(StatementType type, String statement) { if (statementWriter == null) { return; } try { statementWriter.append(statement); statementWriter.append('\n'); } catch (IOException e) { e.printStackTrace(); } } }; IciqlLogger.registerListener(statementListener); SuiteClasses suiteClasses = IciqlSuite.class.getAnnotation(SuiteClasses.class); long quickestDatabase = Long.MAX_VALUE; String dividerMajor = buildDivider('*', 79); String dividerMinor = buildDivider('-', 79); // Header out.println(dividerMajor); out.println(MessageFormat.format("{0} {1} ({2}) testing {3} database configurations", Constants.NAME, Constants.VERSION, Constants.VERSION_DATE, TEST_DBS.length)); out.println(dividerMajor); out.println(); showProperty("java.vendor"); showProperty("java.runtime.version"); showProperty("java.vm.name"); showProperty("os.name"); showProperty("os.version"); showProperty("os.arch"); showProperty("available processors", "" + Runtime.getRuntime().availableProcessors()); showProperty("available memory", MessageFormat.format("{0,number,0.0} GB", ((double) Runtime.getRuntime().maxMemory()) / (1024 * 1024))); out.println(); // Test a database long lastCount = 0; for (TestDb testDb : TEST_DBS) { out.println(dividerMinor); out.println("Testing " + testDb.describeDatabase()); out.println(" " + testDb.url); out.println(dividerMinor); // inject a database section delimiter in the statement log if (statementWriter != null) { statementWriter.append("\n\n"); statementWriter.append("# ").append(dividerMinor).append('\n'); statementWriter.append("# ").append("Testing " + testDb.describeDatabase()).append('\n'); statementWriter.append("# ").append(dividerMinor).append('\n'); statementWriter.append("\n\n"); } if (testDb.getVersion().equals("OFFLINE")) { // Database not available out.println("Skipping. Could not find " + testDb.url); out.println(); } else { // Setup system properties System.setProperty("iciql.url", testDb.url); System.setProperty("iciql.user", testDb.username); System.setProperty("iciql.password", testDb.password); // Test database Result result = JUnitCore.runClasses(suiteClasses.value()); // Report results testDb.runtime = result.getRunTime(); if (testDb.runtime < quickestDatabase) { quickestDatabase = testDb.runtime; } testDb.statements = IciqlLogger.getTotalCount() - lastCount; // reset total count for next database lastCount = IciqlLogger.getTotalCount(); out.println(MessageFormat.format( "{0} tests ({1} failures, {2} ignores) {3} statements in {4,number,0.000} secs", result.getRunCount(), result.getFailureCount(), result.getIgnoreCount(), testDb.statements, result.getRunTime() / 1000f)); if (result.getFailureCount() == 0) { out.println(); out.println(" 100% successful test suite run."); out.println(); } else { for (Failure failure : result.getFailures()) { out.println(MessageFormat.format("\n + {0}\n {1}", failure.getTestHeader(), failure.getMessage())); } out.println(); } } } // Display runtime results sorted by performance leader out.println(); out.println(dividerMajor); out.println(MessageFormat.format("{0} {1} ({2}) test suite performance results", Constants.NAME, Constants.VERSION, Constants.VERSION_DATE)); out.println(dividerMajor); List<TestDb> dbs = Arrays.asList(TEST_DBS); Collections.sort(dbs); out.println(MessageFormat.format("{0} {1} {2} {3} {4}", StringUtils.pad("Name", 11, " ", true), StringUtils.pad("Type", 5, " ", true), StringUtils.pad("Version", 23, " ", true), StringUtils.pad("Stats/Sec", 10, " ", true), "Runtime")); out.println(dividerMinor); for (TestDb testDb : dbs) { DecimalFormat df = new DecimalFormat("0.0"); out.println(MessageFormat.format("{0} {1} {2} {3} {4} {5}s ({6,number,0.0}x)", StringUtils.pad(testDb.name, 11, " ", true), testDb.isEmbedded ? "E" : "T", testDb.isMemory ? "M" : "F", StringUtils.pad(testDb.getVersion(), 21, " ", true), StringUtils.pad("" + testDb.getStatementRate(), 10, " ", false), StringUtils.pad(df.format(testDb.getRuntime()), 8, " ", false), ((double) testDb.runtime) / quickestDatabase)); } out.println(dividerMinor); out.println(" E = embedded connection"); out.println(" T = tcp/ip connection"); out.println(" M = memory database"); out.println(" F = file/persistent database"); // cleanup for (PoolableConnectionFactory factory : connectionFactories.values()) { factory.getPool().close(); } IciqlLogger.unregisterListener(statementListener); out.close(); System.setErr(ERR); if (statementWriter != null) { statementWriter.close(); } hsql.stop(); h2.stop(); System.exit(0); }
From source file:com.mbrlabs.mundus.editor.utils.Log.java
public static void init() { System.setErr(new ErrorStreamInterceptor(System.err)); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override/*from w w w . j a va 2 s . c om*/ public void uncaughtException(Thread thread, Throwable throwable) { Log.exception(TAG, throwable); Log.fatal(TAG, "Uncaught exception occurred, error report will be saved"); logFileWriter.flush(); } }); prepareLogFile(); }