List of usage examples for java.lang System setErr
public static void setErr(PrintStream err)
From source file:org.wso2.andes.test.utils.QpidBrokerTestCase.java
public void runBare() throws Throwable { _testName = getClass().getSimpleName() + "." + getName(); String qname = getClass().getName() + "." + getName(); // Initialize this for each test run _env = new HashMap<String, String>(); PrintStream oldOut = System.out; PrintStream oldErr = System.err; PrintStream out = null;// w ww .j a va 2 s. co m PrintStream err = null; boolean redirected = _output != null && _output.length() > 0; if (redirected) { _outputFile = new File(String.format("%s/TEST-%s.out", _output, qname)); out = new PrintStream(_outputFile); err = new PrintStream(String.format("%s/TEST-%s.err", _output, qname)); System.setOut(out); System.setErr(err); if (_interleaveBrokerLog) { _brokerOutputStream = out; } else { _brokerOutputStream = new PrintStream(new FileOutputStream(String .format("%s/TEST-%s.broker.out", _output, qname)), true); } } _logger.info("========== start " + _testName + " =========="); try { super.runBare(); } catch (Exception e) { _logger.error("exception", e); throw e; } finally { try { stopBroker(); } catch (Exception e) { _logger.error("exception stopping broker", e); } if(_brokerCleanBetweenTests) { try { cleanBroker(); } catch (Exception e) { _logger.error("exception cleaning up broker", e); } } _logger.info("========== stop " + _testName + " =========="); if (redirected) { System.setErr(oldErr); System.setOut(oldOut); err.close(); out.close(); if (!_interleaveBrokerLog) { _brokerOutputStream.close(); } } } }
From source file:org.apache.maven.cli.NoSyspropChangingMavenCli.java
private void logging(CliRequest cliRequest) { cliRequest.debug = cliRequest.commandLine.hasOption(CLIManager.DEBUG); cliRequest.quiet = !cliRequest.debug && cliRequest.commandLine.hasOption(CLIManager.QUIET); cliRequest.showErrors = cliRequest.debug || cliRequest.commandLine.hasOption(CLIManager.ERRORS); if (cliRequest.debug) { cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_DEBUG); } else if (cliRequest.quiet) { // TODO: we need to do some more work here. Some plugins use sys out or log errors at info level. // Ideally, we could use Warn across the board cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_ERROR); // TODO:Additionally, we can't change the mojo level because the component key includes the version and // it isn't known ahead of time. This seems worth changing. } else {//from www . j a va2s . com cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_INFO); } if (cliRequest.commandLine.hasOption(CLIManager.LOG_FILE)) { File logFile = new File(cliRequest.commandLine.getOptionValue(CLIManager.LOG_FILE)); logFile = resolveFile(logFile, cliRequest.workingDirectory); try { cliRequest.fileStream = new PrintStream(logFile); System.setOut(cliRequest.fileStream); System.setErr(cliRequest.fileStream); } catch (FileNotFoundException e) { System.err.println(e); } } }
From source file:se.nawroth.asciidoc.browser.AsciidocBrowserApplication.java
public AsciidocBrowserApplication(final String[] args) { super("Asciidoc Browser"); setIconImage(Icons.APPLICATION.image()); setSize(1200, 1024);// w ww . j a v a 2 s . c o m addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { actionExit(); } }); JPanel buttonPanel = new JPanel(); backButton = new JButton(""); backButton.setIcon(Icons.BACK.icon()); backButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { actionBack(); } }); buttonPanel.setLayout(new MigLayout("", "[1px][][][][]", "[1px]")); JButton btnOptionsbutton = new JButton(""); btnOptionsbutton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { settingsDialog.setVisible(true); } }); btnOptionsbutton.setIcon(Icons.OPTIONS.icon()); buttonPanel.add(btnOptionsbutton, "flowx,cell 0 0"); backButton.setEnabled(false); buttonPanel.add(backButton, "cell 0 0,grow"); forwardButton = new JButton(""); forwardButton.setIcon(Icons.FORWARD.icon()); forwardButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { actionForward(); } }); forwardButton.setEnabled(false); buttonPanel.add(forwardButton, "cell 0 0,grow"); getContentPane().setLayout(new MigLayout("", "[793.00px,grow]", "[44px][930px]")); getContentPane().add(buttonPanel, "cell 0 0,growx,aligny top"); locationTextField = new JTextField(65); locationTextField.setText(""); locationTextField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(final KeyEvent e) { int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_TAB) { actionGo(); refreshDocumentTree(); } } }); locationTextField.setTransferHandler( new TextFieldTransferHandler(locationTextField.getTransferHandler(), new Runnable() { @Override public void run() { locationTextField.setText(""); } }, new Runnable() { @Override public void run() { actionGo(); refreshDocumentTree(); } })); homebutton = new JButton(""); homebutton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { locationTextField.setText(Settings.getHome()); actionGo(); refreshDocumentTree(); } }); refreshButton = new JButton(""); refreshButton.setToolTipText("Refresh"); refreshButton.setEnabled(false); refreshButton.setIcon(Icons.REFRESH.icon()); refreshButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { actionGo(); refreshPreview(); } }); buttonPanel.add(refreshButton, "cell 1 0"); homebutton.setIcon(Icons.HOME.icon()); buttonPanel.add(homebutton, "cell 2 0"); buttonPanel.add(locationTextField, "cell 3 0,grow"); treeSourceSplitPane = new JSplitPane(); treeSourceSplitPane.setResizeWeight(0.3); getContentPane().add(treeSourceSplitPane, "cell 0 1,grow"); treeScrollPane = new JScrollPane(); treeScrollPane.setMinimumSize(new Dimension(200, 200)); treeSourceSplitPane.setLeftComponent(treeScrollPane); documentTree = new DocumentTree(documentModel); documentTree.setCellRenderer(new TooltipsTreeCellRenderer()); ToolTipManager.sharedInstance().registerComponent(documentTree); ToolTipManager.sharedInstance().setInitialDelay(INITIAL_TOOLTIP_DELAY); ToolTipManager.sharedInstance().setReshowDelay(0); documentTree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(final TreeSelectionEvent tse) { TreePath newLeadSelectionPath = tse.getNewLeadSelectionPath(); if (newLeadSelectionPath != null && !newLeadSelectionPath.equals(currentSelectionPath)) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) newLeadSelectionPath .getLastPathComponent(); FileWrapper file = (FileWrapper) node.getUserObject(); showFile(file, true); refreshPreview(); } } }); treeScrollPane.setViewportView(documentTree); sourceEditorPane = new JEditorPane(); sourceEditorPane.setContentType("text/html"); sourceEditorPane.setEditable(false); sourceEditorPane.addHyperlinkListener(new HandleHyperlinkUpdate()); JScrollPane fileScrollPane = new JScrollPane(sourceEditorPane); fileScrollPane.setMinimumSize(new Dimension(600, 600)); documentTabbedPane = new JTabbedPane(SwingConstants.BOTTOM); documentTabbedPane.addChangeListener(new ChangeListener() { @Override public void stateChanged(final ChangeEvent ce) { refreshPreview(); } }); sourceLogSplitPane = new JSplitPane(); sourceLogSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); treeSourceSplitPane.setRightComponent(sourceLogSplitPane); sourceLogSplitPane.setTopComponent(documentTabbedPane); documentTabbedPane.add(fileScrollPane); documentTabbedPane.setTitleAt(0, "Source"); browserPane = new BrowserPane(); previewScrollPane = new JScrollPane(browserPane); documentTabbedPane.addTab("Preview", null, previewScrollPane, null); console = new JConsole(); System.setErr(console.getErr()); System.setOut(console.getOut()); sourceLogSplitPane.setBottomComponent(console); executor = new AsciidocExecutor(); }
From source file:org.ldp4j.conformance.validation.LDPConformanceITest.java
@Before public void setUp() { this.buffer = new ByteArrayOutputStream(); System.setErr(new PrintStream(this.buffer)); }
From source file:science.atlarge.graphalytics.powergraph.PowergraphPlatform.java
private static void startPlatformLogging(Path fileName) { sysOut = System.out;/* w ww .j a va 2s. c o m*/ sysErr = System.err; try { File file = null; file = fileName.toFile(); file.getParentFile().mkdirs(); file.createNewFile(); FileOutputStream fos = new FileOutputStream(file); TeeOutputStream bothStream = new TeeOutputStream(System.out, fos); PrintStream ps = new PrintStream(bothStream); System.setOut(ps); System.setErr(ps); } catch (Exception e) { e.printStackTrace(); throw new IllegalArgumentException("cannot redirect to output file"); } System.out.println("StartTime: " + System.currentTimeMillis()); }
From source file:com.cisco.dvbu.ps.deploytool.dao.wsapi.ArchiveWSDAOImpl.java
public void takeArchiveAction(String actionName, ArchiveType archive, String serverId, String pathToServersXML, String prefix, String propertyFile) throws CompositeException { if (logger.isDebugEnabled()) { logger.debug(//from w w w . ja va2s .c o m "ArchiveWSDAOImpl.takeArchiveAction(actionName, archive, serverId, pathToServersXML, prefix, propertyFile). actionName=" + actionName + " archive object=" + archive.toString() + " serverId=" + serverId + " pathToServersXML=" + pathToServersXML + " prefix=" + prefix + " propertyFile=" + propertyFile); } // Set the debug options setDebug(); // Read target server properties from xml and build target server object based on target server name CompositeServer targetServer = WsApiHelperObjects.getServerLogger(serverId, pathToServersXML, "ArchiveWSDAOImpl.takeArchiveAction(" + actionName + ")", logger); // // DA@20120610 Comment unnecessary ping - if server is down the backup/restore command will fail as fast as ping // Ping the Server to make sure it is alive and the values are correct. // WsApiHelperObjects.pingServer(targetServer, true); // Get the offset location of the java.policy file [offset from PDTool home]. String javaPolicyOffset = CommonConstants.javaPolicy; String javaPolicyLocation = CommonUtils.extractVariable(prefix, CommonUtils.getFileOrSystemPropertyValue(propertyFile, "PROJECT_HOME_PHYSICAL"), propertyFile, true) + javaPolicyOffset; String identifier = "ArchiveWSDAOImpl.takeArchiveAction"; // some unique identifier that characterizes this invocation. try { if (logger.isDebugEnabled() || debug3) { CommonUtils.writeOutput(":: executing action: " + actionName, prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: executing action: "+actionName); } List<String> argsList = getCommonArchiveParameters(archive, targetServer); if (actionName.equalsIgnoreCase(ArchiveDAO.action.IMPORT.name())) { // pkg_import boolean archiveISNULL = false; if (archive == null) archiveISNULL = true; if (logger.isDebugEnabled() || debug3) { CommonUtils .writeOutput( identifier + ":: " + ArchiveDAO.action.IMPORT.name().toString() + " archiveISNULL=[" + archiveISNULL + "]", prefix, "-debug3", logger, debug1, debug2, debug3); } // Don't execute if -noop (NO_OPERATION) has been set otherwise execute under normal operation. // If so then force a no operation to happen by performing a -printcontents for pkg_import if (!CommonUtils.isExecOperation() || (archive.isPrintcontents() != null && !archive.isPrintcontents())) archive.setPrintcontents(true); // Construct the variable input for pacakged import List<String> parms = getPackageImportParameters(archive); argsList.addAll(parms); String[] args = argsList.toArray(new String[0]); String maskedArgList = CommonUtils.getArgumentListMasked(argsList); if (logger.isDebugEnabled() || debug3) { CommonUtils .writeOutput( identifier + ":: " + ArchiveDAO.action.IMPORT.name().toString() + " argument list=[" + maskedArgList + "]", prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: "+ArchiveDAO.action.IMPORT.name().toString()+" argument list=[" + maskedArgList+"]" ); } /* * 2014-02-14 (mtinius): Removed the PDTool Archive capability */ // ImportCommand.startCommand(".", ".", args); /* * 2014-02-14 (mtinius): Added security manager around the Composite native Archive code because * it has System.out.println and System.exit commands. Need to trap both. */ // Get the existing security manager SecurityManager sm = System.getSecurityManager(); PrintStream originalOut = System.out; PrintStream originalErr = System.err; String command = "ImportCommand.startCommand"; try { // Set the java security policy System.getProperties().setProperty("java.security.policy", javaPolicyLocation); // Create a new System.out Logger Logger importLogger = Logger.getLogger(ImportCommand.class); System.setOut(new PrintStream(new LogOutputStream(importLogger, Level.INFO))); System.setErr(new PrintStream(new LogOutputStream(importLogger, Level.ERROR))); // Create a new security manager System.setSecurityManager(new NoExitSecurityManager()); if (logger.isDebugEnabled()) { logger.debug(identifier + "(). Invoking ImportCommand.startCommand(\".\", \".\", args)."); } // Invoke the Composite native import command. ImportCommand.startCommand(".", ".", args); if (logger.isDebugEnabled()) { logger.debug(identifier + "(). Successfully imported."); } } catch (NoExitSecurityExceptionStatusNonZero nesesnz) { String error = identifier + ":: Exited with exception from System.exit(): " + command + "(\".\", \".\", " + maskedArgList + ")"; logger.error(error); throw new CompositeException(error); } catch (NoExitSecurityExceptionStatusZero nesezero) { if (logger.isDebugEnabled() || debug3) { CommonUtils.writeOutput( identifier + ":: Exited successfully from System.exit(): " + command + "(\".\", \".\", " + maskedArgList + ")", prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: Exited successfully from System.exit(): "+command+"(\".\", \".\", "+maskedArgList+")"); } } finally { System.setSecurityManager(sm); System.setOut(originalOut); System.setErr(originalErr); } } else if (actionName.equalsIgnoreCase(ArchiveDAO.action.RESTORE.name())) { // backup_import // Construct the variable input for backup import List<String> parms = getBackupImportParameters(archive); argsList.addAll(parms); String[] args = argsList.toArray(new String[0]); String maskedArgList = CommonUtils.getArgumentListMasked(argsList); if (logger.isDebugEnabled() || debug3) { CommonUtils .writeOutput( identifier + ":: " + ArchiveDAO.action.RESTORE.name().toString() + " argument list=[" + maskedArgList + "]", prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: "+ArchiveDAO.action.RESTORE.name().toString()+" argument list=[" + maskedArgList+"]" ); } /* * 2014-02-14 (mtinius): Removed the PDTool Archive capability */ // RestoreCommand.startCommand(".", ".", args) ; /* * 2014-02-14 (mtinius): Added security manager around the Composite native Archive code because * it has System.out.println and System.exit commands. Need to trap both. */ // Get the existing security manager SecurityManager sm = System.getSecurityManager(); PrintStream originalOut = System.out; PrintStream originalErr = System.err; String command = "RestoreCommand.startCommand"; try { // Set the java security policy System.getProperties().setProperty("java.security.policy", javaPolicyLocation); // Create a new System.out Logger Logger restoreLogger = Logger.getLogger(RestoreCommand.class); System.setOut(new PrintStream(new LogOutputStream(restoreLogger, Level.INFO))); System.setErr(new PrintStream(new LogOutputStream(restoreLogger, Level.ERROR))); // Create a new security manager System.setSecurityManager(new NoExitSecurityManager()); if (logger.isDebugEnabled()) { logger.debug(identifier + "(). Invoking RestoreCommand.startCommand(\".\", \".\", args)."); } // Don't execute if -noop (NO_OPERATION) has been set otherwise execute under normal operation. if (CommonUtils.isExecOperation()) { // Invoke the Composite native restore command. RestoreCommand.startCommand(".", ".", args); if (logger.isDebugEnabled()) { logger.debug(identifier + "(). Successfully restored."); } } else { logger.info("\n\nWARNING - NO_OPERATION: COMMAND [" + command + "], ACTION [" + actionName + "] WAS NOT PERFORMED.\n"); } } catch (NoExitSecurityExceptionStatusNonZero nesesnz) { String error = identifier + ":: Exited with exception from System.exit(): " + command + "(\".\", \".\", " + maskedArgList + ")"; logger.error(error); throw new CompositeException(error); } catch (NoExitSecurityExceptionStatusZero nesezero) { if (logger.isDebugEnabled() || debug3) { CommonUtils.writeOutput( identifier + ":: Exited successfully from System.exit(): " + command + "(\".\", \".\", " + maskedArgList + ")", prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: Exited successfully from System.exit(): "+command+"(\".\", \".\", "+maskedArgList+")"); } } finally { System.setSecurityManager(sm); System.setOut(originalOut); System.setErr(originalErr); } } else if (actionName.equalsIgnoreCase(ArchiveDAO.action.EXPORT.name())) { // pkg_export List<String> parms = getPackageExportParameters(archive); argsList.addAll(parms); String[] args = argsList.toArray(new String[0]); String maskedArgList = CommonUtils.getArgumentListMasked(argsList); if (logger.isDebugEnabled() || debug3) { CommonUtils .writeOutput( identifier + ":: " + ArchiveDAO.action.EXPORT.name().toString() + " argument list=[" + maskedArgList + "]", prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: "+ArchiveDAO.action.EXPORT.name().toString()+" argument list=[" + maskedArgList+"]" ); } /* * 2014-02-14 (mtinius): Removed the PDTool Archive capability */ // ExportCommand.startCommand(".", ".", args); /* * 2014-02-14 (mtinius): Added security manager around the Composite native Archive code because * it has System.out.println and System.exit commands. Need to trap both. */ // Get the existing security manager SecurityManager sm = System.getSecurityManager(); PrintStream originalOut = System.out; PrintStream originalErr = System.err; String command = "ExportCommand.startCommand"; try { // Set the java security policy System.getProperties().setProperty("java.security.policy", javaPolicyLocation); // Create a new System.out Logger Logger exportLogger = Logger.getLogger(ExportCommand.class); System.setOut(new PrintStream(new LogOutputStream(exportLogger, Level.INFO))); System.setErr(new PrintStream(new LogOutputStream(exportLogger, Level.ERROR))); // Create a new security manager System.setSecurityManager(new NoExitSecurityManager()); if (logger.isDebugEnabled()) { logger.debug(identifier + "(). Invoking ExportCommand.startCommand(\".\", \".\", args)."); } // Don't execute if -noop (NO_OPERATION) has been set otherwise execute under normal operation. if (CommonUtils.isExecOperation()) { // Invoke the Composite native export command. ExportCommand.startCommand(".", ".", args); if (logger.isDebugEnabled()) { logger.debug(identifier + "(). Successfully exported."); } } else { logger.info("\n\nWARNING - NO_OPERATION: COMMAND [" + command + "], ACTION [" + actionName + "] WAS NOT PERFORMED.\n"); } } catch (NoExitSecurityExceptionStatusNonZero nesesnz) { String error = identifier + ":: Exited with exception from System.exit(): " + command + "(\".\", \".\", " + maskedArgList + ")"; logger.error(error); throw new CompositeException(error); } catch (NoExitSecurityExceptionStatusZero nesezero) { if (logger.isDebugEnabled() || debug3) { CommonUtils.writeOutput( identifier + ":: Exited successfully from System.exit(): " + command + "(\".\", \".\", " + maskedArgList + ")", prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: Exited successfully from System.exit(): "+command+"(\".\", \".\", "+maskedArgList+")"); } } finally { System.setSecurityManager(sm); System.setOut(originalOut); System.setErr(originalErr); } } else if (actionName.equalsIgnoreCase(ArchiveDAO.action.BACKUP.name())) { // backup_export List<String> parms = getBackupExportParameters(archive); argsList.addAll(parms); String[] args = argsList.toArray(new String[0]); String maskedArgList = CommonUtils.getArgumentListMasked(argsList); if (logger.isDebugEnabled() || debug3) { CommonUtils .writeOutput( identifier + ":: " + ArchiveDAO.action.BACKUP.name().toString() + " argument list=[" + maskedArgList + "]", prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: "+ArchiveDAO.action.BACKUP.name().toString()+" argument list=[" + maskedArgList+"]" ); } /* * 2014-02-14 (mtinius): Removed the PDTool Archive capability */ // BackupCommand.startCommand(".", ".", args); /* * 2014-02-14 (mtinius): Added security manager around the Composite native Archive code because * it has System.out.println and System.exit commands. Need to trap both. */ // Get the existing security manager SecurityManager sm = System.getSecurityManager(); PrintStream originalOut = System.out; PrintStream originalErr = System.err; String command = "BackupCommand.startCommand"; try { // Set the java security policy System.getProperties().setProperty("java.security.policy", javaPolicyLocation); // Create a new System.out Logger Logger backupLogger = Logger.getLogger(BackupCommand.class); System.setOut(new PrintStream(new LogOutputStream(backupLogger, Level.INFO))); System.setErr(new PrintStream(new LogOutputStream(backupLogger, Level.ERROR))); // Create a new security manager System.setSecurityManager(new NoExitSecurityManager()); if (logger.isDebugEnabled()) { logger.debug(identifier + "(). Invoking BackupCommand.startCommand(\".\", \".\", args)."); } // Don't execute if -noop (NO_OPERATION) has been set otherwise execute under normal operation. if (CommonUtils.isExecOperation()) { // Invoke the Composite native backup command. BackupCommand.startCommand(".", ".", args); if (logger.isDebugEnabled()) { logger.debug(identifier + "(). Successfully backed up."); } } else { logger.info("\n\nWARNING - NO_OPERATION: COMMAND [" + command + "], ACTION [" + actionName + "] WAS NOT PERFORMED.\n"); } } catch (NoExitSecurityExceptionStatusNonZero nesesnz) { String error = identifier + ":: Exited with exception from System.exit(): " + command + "(\".\", \".\", " + maskedArgList + ")"; logger.error(error); throw new CompositeException(error); } catch (NoExitSecurityExceptionStatusZero nesezero) { if (logger.isDebugEnabled() || debug3) { CommonUtils.writeOutput( identifier + ":: Exited successfully from System.exit(): " + command + "(\".\", \".\", " + maskedArgList + ")", prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: Exited successfully from System.exit(): "+command+"(\".\", \".\", "+maskedArgList+")"); } } finally { System.setSecurityManager(sm); System.setOut(originalOut); System.setErr(originalErr); } } if (logger.isDebugEnabled() || debug3) { CommonUtils.writeOutput(identifier + ":: completed " + actionName, prefix, "-debug3", logger, debug1, debug2, debug3); //logger.debug(identifier+":: completed " + actionName ); } } // TO DO: Implement specific catch clauses based on implementation catch (Exception e) { // TODO: Be more specific about error messages being returned // TODO: null - this is where soap-faults get passed - modify if you return a soap-fault (e.g. e.getFaultInfo()) if (e.getCause() != null && e.getCause() instanceof WebapiException) { // CompositeLogger.logException(e, DeployUtil.constructMessage(DeployUtil.MessageType.ERROR.name(), actionName, "Archive", identifier, targetServer),e.getCause()); CompositeLogger.logException(e.getCause(), DeployUtil.constructMessage( DeployUtil.MessageType.ERROR.name(), actionName, "Archive", identifier, targetServer)); } else { CompositeLogger.logException(e, DeployUtil.constructMessage(DeployUtil.MessageType.ERROR.name(), actionName, "Archive", identifier, targetServer)); } throw new ApplicationException(e.getMessage(), e); } }
From source file:org.moeaframework.TestUtils.java
/** * Invokes the main method of the specified command line utility, * redirecting the output and error streams to the specified files. As * this method redirects the {@code System.out} and {@code System.err} * streams, this must be the only process writing to {@code System.out} * and {@code System.err}.// w w w.j ava 2 s.co m * * @param output the file for output redirection * @param error the file for error redirection * @param tool the command line utility class * @param args the command line arguments * @throws Exception if any of the many exceptions for reflection or * file writing occurred */ public static void pipeCommandLine(File output, File error, Class<?> tool, String... args) throws Exception { PrintStream oldErr = System.err; PrintStream newErr = null; try { newErr = new PrintStream(new FileOutputStream(error)); System.setErr(newErr); pipeCommandLine(output, tool, args); } finally { if (newErr != null) { newErr.close(); } System.setErr(oldErr); } }
From source file:science.atlarge.graphalytics.powergraph.PowergraphPlatform.java
private static void stopPlatformLogging() { System.out.println("EndTime: " + System.currentTimeMillis()); System.setOut(sysOut);/*from w w w .j a v a2 s. com*/ System.setErr(sysErr); }
From source file:org.p_vcd.model.Parameters.java
private void setGlobalLogFile(File logFile) throws Exception { // no changes if ((this.log_file == null && logFile == null) || (this.log_file != null && logFile != null && this.log_file.getAbsolutePath().equals(logFile.getAbsolutePath()))) return;/*from ww w . java 2 s.co m*/ // closing old file if (this.log_output != null) { this.log_output.close(); this.log_output = null; this.log_file = null; } // redirecting standard output if (logFile != null) { this.log_file = logFile; this.log_output = new PrintStream(new FileOutputStream(this.log_file, true), true); System.setOut(this.log_output); System.setErr(this.log_output); } }
From source file:org.apache.hive.beeline.TestSchemaTool.java
/** * Test schema upgrade//from ww w . j a v a2 s . co m * @throws Exception */ public void testSchemaUpgrade() throws Exception { boolean foundException = false; // Initialize 0.7.0 schema schemaTool.doInit("0.7.0"); // verify that driver fails due to older version schema try { schemaTool.verifySchemaVersion(); } catch (HiveMetaException e) { // Expected to fail due to old schema foundException = true; } if (!foundException) { throw new Exception("Hive operations shouldn't pass with older version schema"); } // Generate dummy pre-upgrade script with errors String invalidPreUpgradeScript = writeDummyPreUpgradeScript(0, "upgrade-0.11.0-to-0.12.0.derby.sql", "foo bar;"); // Generate dummy pre-upgrade scripts with valid SQL String validPreUpgradeScript0 = writeDummyPreUpgradeScript(0, "upgrade-0.12.0-to-0.13.0.derby.sql", "CREATE TABLE schema_test0 (id integer);"); String validPreUpgradeScript1 = writeDummyPreUpgradeScript(1, "upgrade-0.12.0-to-0.13.0.derby.sql", "CREATE TABLE schema_test1 (id integer);"); // Capture system out and err schemaTool.setVerbose(true); OutputStream stderr = new ByteArrayOutputStream(); PrintStream errPrintStream = new PrintStream(stderr); System.setErr(errPrintStream); OutputStream stdout = new ByteArrayOutputStream(); PrintStream outPrintStream = new PrintStream(stdout); System.setOut(outPrintStream); // Upgrade schema from 0.7.0 to latest schemaTool.doUpgrade("0.7.0"); // Verify that the schemaTool ran pre-upgrade scripts and ignored errors assertTrue(stderr.toString().contains(invalidPreUpgradeScript)); assertTrue(stderr.toString().contains("foo")); assertFalse(stderr.toString().contains(validPreUpgradeScript0)); assertFalse(stderr.toString().contains(validPreUpgradeScript1)); assertTrue(stdout.toString().contains(validPreUpgradeScript0)); assertTrue(stdout.toString().contains(validPreUpgradeScript1)); // Verify that driver works fine with latest schema schemaTool.verifySchemaVersion(); }