Example usage for java.lang System setErr

List of usage examples for java.lang System setErr

Introduction

In this page you can find the example usage for java.lang System setErr.

Prototype

public static void setErr(PrintStream err) 

Source Link

Document

Reassigns the "standard" error output stream.

Usage

From source file:caarray.client.test.gui.GuiMain.java

public GuiMain() throws Exception {
    JFrame frame = new JFrame("API Test Suite");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.getContentPane().setLayout(new BorderLayout(6, 6));

    JPanel topPanel = new JPanel();

    /* ###### Text fields for modifiable parameters ##### */

    final JTextField javaHostText = new JTextField(TestProperties.getJavaServerHostname(), 20);
    JLabel javaHostLabel = new JLabel("Java Service Host");
    JButton save = new JButton("Save");
    save.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            TestProperties.setJavaServerHostname(javaHostText.getText());
        }//  w  ww  .j a  va2s.  co  m

    });

    JLabel javaPortLabel = new JLabel("Java Port");
    final JTextField javaPortText = new JTextField(Integer.toString(TestProperties.getJavaServerJndiPort()), 5);
    JButton save2 = new JButton("Save");
    save2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            try {
                int port = Integer.parseInt(javaPortText.getText());
                TestProperties.setJavaServerJndiPort(port);
            } catch (NumberFormatException e) {
                System.out.println(javaPortText.getText() + " is not a valid port number.");
            }
        }

    });

    JLabel gridHostLabel = new JLabel("Grid Service Host");
    final JTextField gridHostText = new JTextField(TestProperties.getGridServerHostname(), 20);
    JButton save3 = new JButton("Save");
    save3.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            TestProperties.setGridServerHostname(gridHostText.getText());
        }

    });

    JLabel gridPortLabel = new JLabel("Grid Service Port");
    final JTextField gridPortText = new JTextField(Integer.toString(TestProperties.getGridServerPort()), 5);
    JButton save4 = new JButton("Save");
    save4.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            try {
                int port = Integer.parseInt(gridPortText.getText());
                TestProperties.setGridServerPort(port);
            } catch (NumberFormatException e) {
                System.out.println(gridPortText.getText() + " is not a valid port number.");
            }

        }

    });

    JLabel excludeLabel = new JLabel("Exclude test cases (comma-separated list):");
    final JTextField excludeText = new JTextField("", 30);
    JButton save5 = new JButton("Save");
    save5.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            String testString = excludeText.getText();
            if (testString != null) {
                String[] testCases = testString.split(",");
                if (testCases != null && testCases.length > 0) {
                    List<Float> tests = new ArrayList<Float>();
                    for (String test : testCases) {
                        try {
                            tests.add(Float.parseFloat(test));
                        } catch (NumberFormatException e) {
                            System.out.println(test + " is not a valid test case.");
                        }
                    }
                    TestProperties.setExcludedTests(tests);
                }

            }

        }

    });

    JLabel includeLabel = new JLabel("Include only (comma-separated list):");
    final JTextField includeText = new JTextField("", 30);
    JButton save6 = new JButton("Save");
    save6.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            String testString = includeText.getText();
            if (testString != null) {
                String[] testCases = testString.split(",");
                if (testCases != null && testCases.length > 0) {
                    List<Float> tests = new ArrayList<Float>();
                    for (String test : testCases) {
                        try {
                            tests.add(Float.parseFloat(test));
                        } catch (NumberFormatException e) {
                            System.out.println(test + " is not a valid test case.");
                        }
                    }
                    TestProperties.setIncludeOnlyTests(tests);
                }

            }

        }

    });

    JLabel threadLabel = new JLabel("Number of threads:");
    final JTextField threadText = new JTextField(Integer.toString(TestProperties.getNumThreads()), 5);
    JButton save7 = new JButton("Save");
    save7.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            try {
                int threads = Integer.parseInt(threadText.getText());
                TestProperties.setNumThreads(threads);
            } catch (NumberFormatException e) {
                System.out.println(threadText.getText() + " is not a valid thread number.");
            }

        }

    });
    GridBagLayout topLayout = new GridBagLayout();
    topPanel.setLayout(topLayout);

    JLabel[] labels = new JLabel[] { javaHostLabel, javaPortLabel, gridHostLabel, gridPortLabel, excludeLabel,
            includeLabel, threadLabel };
    JTextField[] textFields = new JTextField[] { javaHostText, javaPortText, gridHostText, gridPortText,
            excludeText, includeText, threadText };
    JButton[] buttons = new JButton[] { save, save2, save3, save4, save5, save6, save7 };
    for (int i = 0; i < labels.length; i++) {
        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.NONE;
        c.gridx = 0;
        c.gridy = i;
        topPanel.add(labels[i], c);
        c.gridx = 1;
        topPanel.add(textFields[i], c);
        c.gridx = 2;
        topPanel.add(buttons[i], c);
    }

    frame.getContentPane().add(topPanel, BorderLayout.PAGE_START);

    GridLayout bottomLayout = new GridLayout(0, 4);
    selectionPanel.setLayout(bottomLayout);
    JCheckBox selectAll = new JCheckBox("Select/Deselect All");
    selectAll.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JCheckBox box = (JCheckBox) e.getSource();
            selectAll(box.isSelected());
        }
    });
    selectionPanel.add(selectAll);
    JCheckBox excludeLongTests = new JCheckBox("Exclude Long Tests");
    excludeLongTests.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JCheckBox box = (JCheckBox) e.getSource();
            if (box.isSelected()) {
                TestProperties.excludeLongTests();
            } else {
                TestProperties.removeExcludedLongTests();
            }
        }
    });
    TestProperties.excludeLongTests();
    excludeLongTests.setSelected(true);
    selectionPanel.add(excludeLongTests);

    //Initialize check boxes corresponding to test categories
    initializeTests();

    centerPanel.setLayout(new GridLayout(0, 1));
    centerPanel.add(selectionPanel);

    //Redirect System messages to gui     
    JScrollPane textScroll = new JScrollPane();
    textScroll.setViewportView(textDisplay);
    System.setOut(new PrintStream(new JTextAreaOutputStream(textDisplay)));
    System.setErr(new PrintStream(new JTextAreaOutputStream(textDisplay)));
    centerPanel.add(textScroll);
    JScrollPane scroll = new JScrollPane(centerPanel);

    frame.getContentPane().add(scroll, BorderLayout.CENTER);

    JButton runButton = new JButton("Run Tests");
    runButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            try {

                runTests();

            } catch (Exception e) {
                System.out.println("An error occured executing the tests: " + e.getClass()
                        + ". Check error log for details.");
                log.error("Exception encountered:", e);
            }
        }

    });

    JPanel bottomPanel = new JPanel();
    bottomPanel.add(runButton);
    frame.getContentPane().add(bottomPanel, BorderLayout.PAGE_END);

    frame.pack();
    frame.setVisible(true);
}

From source file:v800_trainer.JCicloTronic.java

/** Creates new form JCicloTronic */
public JCicloTronic() {

    ScreenSize = new Dimension();
    SelectionChanged = false;/*  ww  w.  ja v  a 2s. c o m*/
    ScreenSize.setSize(java.awt.Toolkit.getDefaultToolkit().getScreenSize().getWidth() - 50,
            java.awt.Toolkit.getDefaultToolkit().getScreenSize().getHeight() - 50);
    Size = new Dimension();

    Properties = new java.util.Properties();
    SystemProperties = java.lang.System.getProperties();
    chooser = new javax.swing.JFileChooser();
    RawData = new byte[98316];
    //        System.setProperty("jna.library.path" , "C:/WINDOWS/system32");

    try {
        FileInputStream in = new FileInputStream(SystemProperties.getProperty("user.dir")
                + SystemProperties.getProperty("file.separator") + "JCicloexp.cfg");
        Properties.load(in);
        in.close();
    } catch (Exception e) {
        FontSize = 20;
        setFontSizeGlobal("Tahoma", FontSize);

        JOptionPane.showMessageDialog(null,
                "Keine Config-Datei in:  " + SystemProperties.getProperty("user.dir"), "Achtung!",
                JOptionPane.ERROR_MESSAGE);
        Properties.put("working.dir", SystemProperties.getProperty("user.dir"));
        Eigenschaften = new Eigenschaften(new javax.swing.JFrame(), true, this);
        this.setExtendedState(Frame.MAXIMIZED_BOTH);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        double width = screenSize.getWidth();
        double height = screenSize.getHeight();
        this.setSize(new Dimension((int) width, (int) height));
        this.setPreferredSize(new Dimension((int) width, (int) height));
        this.setMinimumSize(new Dimension((int) width, (int) height));
        repaint();
    }
    try {

        UIManager.setLookAndFeel(Properties.getProperty("LookFeel"));
        SwingUtilities.updateComponentTreeUI(this);
        this.pack();
    } catch (Exception exc) {
    }

    if (debug) {
        try {
            System.setErr(new java.io.PrintStream(new FileOutputStream(Properties.getProperty("working.dir")
                    + SystemProperties.getProperty("file.separator") + "error.txt")));
            //        System.err =  new FileOutputStream(Properties.getProperty("working.dir") + SystemProperties.getProperty("file.separator") + "error.txt");
            System.setOut(new java.io.PrintStream(new FileOutputStream(Properties.getProperty("working.dir")
                    + SystemProperties.getProperty("file.separator") + "error.txt")));
        } catch (Exception err) {
        }
    }

    initComponents();

    setTitle("V800 Trainer    Datadir: " + Properties.getProperty("data.dir"));

    icon = new ImageIcon("hw.jpg");
    setIconImage(icon.getImage());

    if (Integer.parseInt(Properties.getProperty("View Geschw", "1")) == 1) {
        Graphik_check_Geschwindigkeit.setSelected(true);
    } else {
        Graphik_check_Geschwindigkeit.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Hhe", "1")) == 1) {
        Graphik_check_Hhe.setSelected(true);
    } else {
        Graphik_check_Hhe.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Hf", "1")) == 1) {
        Graphik_check_HF.setSelected(true);
    } else {
        Graphik_check_HF.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Temp", "1")) == 1) {
        Graphik_check_Temp.setSelected(true);
    } else {
        Graphik_check_Temp.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Steigp", "1")) == 1) {
        Graphik_check_Steigung_p.setSelected(true);
    } else {
        Graphik_check_Steigung_p.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Steigm", "1")) == 1) {
        Graphik_check_Steigung_m.setSelected(true);
    } else {
        Graphik_check_Steigung_m.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View av_Geschw", "1")) == 1) {
        Graphik_check_av_Geschw.setSelected(true);
    } else {
        Graphik_check_av_Geschw.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Cadence", "1")) == 1) {
        Graphik_check_Cadence.setSelected(true);
    } else {
        Graphik_check_Cadence.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Schrittlnge", "1")) == 1) {
        Graphik_check_Schrittlnge.setSelected(true);
    } else {
        Graphik_check_Schrittlnge.setSelected(false);
    }

    if (Integer.parseInt(Properties.getProperty("ZeitStreckeAbstnde", "1")) == 1) {
        Graphik_check_Abstand.setSelected(true);
    } else {
        Graphik_check_Abstand.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("SummenHisto", "1")) == 1) {
        Summenhistogramm_Check.setSelected(true);
    } else {
        Summenhistogramm_Check.setSelected(false);
    }

    if (Integer.parseInt(Properties.getProperty("xy_Strecke", "1")) == 1) {
        Graphik_Radio_Strecke.setSelected(true);
        Graphik_Radio_Zeit.setSelected(false);
    } else {
        Graphik_Radio_Strecke.setSelected(false);
        Graphik_Radio_Zeit.setSelected(true);
    }

    //Buttons fr XY-Darstellung   (ber Strecke oder ber Zeit)
    X_Axis = new ButtonGroup();
    X_Axis.add(Graphik_Radio_Strecke);
    X_Axis.add(Graphik_Radio_Zeit);

    //Buttons fr Jahresbersicht
    bersicht = new ButtonGroup();
    bersicht.add(jRadioButton_jahresverlauf);
    bersicht.add(jRadioButton_monatsbersicht);

    Datenliste_Zeitabschnitt.addItem("nicht aktiv");
    Datenliste_Zeitabschnitt.addItem("vergangene Woche");
    Datenliste_Zeitabschnitt.addItem("vergangener Monat");
    Datenliste_Zeitabschnitt.addItem("vergangenes Jahr");
    Datenliste_Zeitabschnitt.addItem("Alles");

    if (Datentabelle.getRowCount() != 0) {
        Datentabelle.addRowSelectionInterval(0, 0);
        Datenliste_scroll_Panel.getViewport().setViewPosition(new java.awt.Point(0, 0));
    }
    //        if (Properties.getProperty("CommPort").equals("nocom")) {
    //            jMenuReceive.setEnabled(false);
    //        } else {
    //            jMenuReceive.setEnabled(true);
    //        }

    jLabel69_Selektiert.setText(Datentabelle.getSelectedRowCount() + " / " + Datentabelle.getRowCount());

    setFileChooserFont(chooser.getComponents());
    locmap = true;
    Map_Type.removeAllItems();
    Map_Type.addItem("OpenStreetMap");
    Map_Type.addItem("Virtual Earth Map");
    Map_Type.addItem("Virtual Earth Satelite");
    Map_Type.addItem("Virtual Earth Hybrid");
    locmap = false;
    //    ChangeModel();
}

From source file:org.kie.workbench.common.services.backend.compiler.impl.external339.AFMavenCli.java

public int doMain(AFCliRequest cliRequest, ClassWorld classWorld) {

    PlexusContainer localContainer = null;
    PrintStream originalOut = System.out;
    PrintStream originalErr = System.err;
    try {/* www .j  a v  a2  s.c o m*/
        initialize(cliRequest);
        cli(cliRequest);
        logging(cliRequest);
        version(cliRequest);
        properties(cliRequest);
        localContainer = container(cliRequest, classWorld);
        commands(cliRequest);
        configure(cliRequest);
        toolchains(cliRequest);
        populateRequest(cliRequest);
        repository(cliRequest);
        return execute(cliRequest);
    } catch (ExitException e) {
        e.getStackTrace();
        return e.exitCode;
    } catch (UnrecognizedOptionException e) {
        e.getStackTrace();
        return 1;
    } catch (BuildAbort e) {
        e.getStackTrace();
        AFCLIReportingUtils.showError(slf4jLogger, "ABORTED", e, cliRequest.isShowErrors());
        return 2;
    } catch (Exception e) {
        e.getStackTrace();
        AFCLIReportingUtils.showError(slf4jLogger, "Error executing Maven.", e, cliRequest.isShowErrors());

        return 1;
    } finally {
        System.setOut(originalOut);
        System.setErr(originalErr);
        if (localContainer != null) {
            localContainer.dispose();
            localContainer = null;
        }
    }
}

From source file:org.apache.maven.cli.DefaultMavenExecutionRequestBuilder.java

/**
 * configure logging//from w  w  w .j  av  a2 s.  co  m
 */
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);

    slf4jLoggerFactory = LoggerFactory.getILoggerFactory();
    Slf4jConfiguration slf4jConfiguration = Slf4jConfigurationFactory.getConfiguration(slf4jLoggerFactory);

    if (cliRequest.debug) {
        cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_DEBUG);
        slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.DEBUG);
    } else if (cliRequest.quiet) {
        cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_ERROR);
        slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.ERROR);
    } else {
        cliRequest.request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_INFO);
        slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.INFO);
    }

    if (cliRequest.commandLine.hasOption(CLIManager.LOG_FILE)) {
        File logFile = new File(cliRequest.commandLine.getOptionValue(CLIManager.LOG_FILE));
        logFile = resolveFile(logFile, cliRequest.workingDirectory);

        // redirect stdout and stderr to file
        try {
            PrintStream ps = new PrintStream(new FileOutputStream(logFile));
            System.setOut(ps);
            System.setErr(ps);
        } catch (FileNotFoundException e) {
            //
            // Ignore
            //
        }
    }

    slf4jConfiguration.activate();

    plexusLoggerManager = new Slf4jLoggerManager();
    slf4jLogger = slf4jLoggerFactory.getLogger(this.getClass().getName());
}

From source file:nl.vu.psy.rite.Rite.java

public void run() {
    if (run) {/*from  w  w w .  j a va 2s  .c o m*/
        Recipe r = null;
        try {
            System.out.println("Starting work cycle..");
            long sleepTime = Long.parseLong(getProperty(PropertyKeys.INTERVAL));
            long scrubDelay = Long.parseLong(getProperty(PropertyKeys.SCRUBDELAY));
            long idleDelay = Long.parseLong(getProperty(PropertyKeys.IDLEDELAY));
            int maxFailures = Integer.parseInt(getProperty(PropertyKeys.MAXFAILURES));
            int maxScrubs = Integer.parseInt(getProperty(PropertyKeys.MAXSCRUBS));
            int maxRecipes = Integer.parseInt(getProperty(PropertyKeys.MAXRECIPES));
            while (!lifeTimeExceeded() && !halt) {
                // Check commands
                ClientCommand co = rh.getClientCommand(identifier);
                if (co == null) {
                    if (idle) {
                        System.out.println(
                                "-------------------------------------------------------------------------------");
                        System.out.println("Idle.");
                        System.out.println("Time: " + TimeStamp.dateToString(new Date()));
                        System.out.println(
                                "-------------------------------------------------------------------------------");
                        try {
                            Thread.sleep(idleDelay);
                        } catch (InterruptedException e) {
                            System.out.println("The work cycle was interrupted: " + e.getMessage());
                            System.out.println("=== MARK: " + TimeStamp.dateToString(new Date()) + " ===");
                            return;
                        }
                        System.out.println("=== MARK: " + TimeStamp.dateToString(new Date()) + " ===");
                    } else {
                        r = rh.lockRecipe(); // Lock and retrieve recipe
                        if (r == null) {
                            System.out.println(
                                    "-------------------------------------------------------------------------------");
                            System.out.println("No recipe. Scrubbing host.");
                            System.out.println("Time: " + TimeStamp.dateToString(new Date()));
                            System.out.println(
                                    "-------------------------------------------------------------------------------");
                            rh.scrubHost();
                            scrubs++;
                            if (scrubs > maxScrubs) {
                                System.out.println(
                                        "The maximum number of scrubs has been reached. This client will shutdown...");
                                halt = true;
                            }
                            System.out.println("=== MARK: " + TimeStamp.dateToString(new Date()) + " ===");
                            try {
                                Thread.sleep(scrubDelay);
                            } catch (InterruptedException e) {
                                System.out.println("The work cycle was interrupted: " + e.getMessage());
                                System.out.println("=== MARK: " + TimeStamp.dateToString(new Date()) + " ===");
                                return;
                            }
                        } else {
                            // Reset scrub counter
                            scrubs = 0;
                            // Set up streams for recipe output
                            PrintStream out = null;
                            PrintStream err = null;

                            try {
                                out = new PrintStream(
                                        new FileOutputStream("recipe." + r.getIdentifier() + ".stdout"));
                                PrintStream teeOut = new PrintStream(new TeeOutputStream(System.out, out));
                                System.setOut(teeOut);
                                err = new PrintStream(
                                        new FileOutputStream("recipe." + r.getIdentifier() + ".stderr"));
                                PrintStream teeErr = new PrintStream(new TeeOutputStream(System.err, err));
                                System.setErr(teeErr);
                            } catch (FileNotFoundException e) {
                                // Absorb
                                System.out.println(
                                        "Could not tee output streams to file. Outputting to main application streams only.");
                            }

                            System.out.println(
                                    "-------------------------------------------------------------------------------");
                            System.out.println("Starting recipe: " + r.getIdentifier() + ".");
                            System.out.println("Time: " + TimeStamp.dateToString(new Date()));
                            System.out.println(
                                    "-------------------------------------------------------------------------------");

                            recipeCooker.setRecipe(r); // Run recipe
                            // Wait for completion
                            while (!r.hasCompleted()) {
                                try {
                                    Thread.sleep(sleepTime);
                                } catch (InterruptedException e) {
                                    System.out.println("The work cycle was interrupted: " + e.getMessage());
                                    System.out.println("Attempting release of: " + r.getIdentifier());
                                    r = recipeCooker.getRecipe();
                                    recipeCooker.removeRecipe();
                                    rh.releaseRecipe(r);
                                    System.out.println(
                                            "=== MARK: " + TimeStamp.dateToString(new Date()) + " ===");
                                    return;
                                }
                            }
                            r = recipeCooker.getRecipe();
                            recipeCooker.removeRecipe();
                            rh.releaseRecipe(r);
                            recipes++;
                            if (r.hasFailed()) {
                                failures++;
                            }
                            if (failures >= maxFailures) {
                                System.out.println(
                                        "The maximum number of recipe failures has been reached. This client will shutdown...");
                                halt = true;
                            }
                            if (maxRecipes > -1 && recipes >= maxRecipes) {
                                System.out.println(
                                        "The maximum number of completed recipes has been reached. This client will shutdown...");
                                halt = true;
                            }

                            System.out.println("=== MARK: " + TimeStamp.dateToString(new Date()) + " ===");
                            System.setOut(System.out);
                            System.setErr(System.err);
                            if (out != null) {
                                out.close();
                                out = null;
                            }
                            if (err != null) {
                                err.close();
                                err = null;
                            }
                        }
                    }
                } else {
                    // Handle command
                    // FIXME not too fond of all these flags
                    System.out.println(
                            "-------------------------------------------------------------------------------");
                    System.out.println("Got command: " + co.getCommand());
                    System.out.println("Time: " + TimeStamp.dateToString(new Date()));
                    System.out.println(
                            "-------------------------------------------------------------------------------");
                    switch (co.getCommand()) {
                    case HALT:
                        System.out.println("Halting client...");
                        halt = true;
                        break;
                    case IDLE:
                        System.out.println("Setting client to idle...");
                        idle = true;
                        break;
                    case RUN:
                        System.out.println("Setting client to run...");
                        idle = false;
                        break;
                    default:
                        break;
                    }
                    System.out.println("=== MARK: " + TimeStamp.dateToString(new Date()) + " ===");
                }
            }
            //System.out.println("Shutting down...");
            if (rh.hasLock()) {
                System.out.println("Attempting release of: " + r.getIdentifier());
                r = recipeCooker.getRecipe();
                recipeCooker.removeRecipe();
                rh.releaseRecipe(r);
                System.out.println("=== MARK: " + TimeStamp.dateToString(new Date()) + " ===");
                return;
            }
        } catch (Exception e) {
            System.out.println("An exception was encountered while running: " + e.getMessage());
            System.out.println("Exiting!");
            return;
        }
    }
}

From source file:com.surfs.nas.log.LogFactory.java

/**
 * @param log
 */
public static void setSystemErr(Logger log) {
    System.setErr(new TextPrinter(System.err, log));
}

From source file:org.apache.geode.internal.cache.CacheServerLauncher.java

protected void restoreStdOut() {
    System.setErr(oldErr);
    System.setOut(oldOut);
}

From source file:org.dita.dost.AbstractIntegrationTest.java

/**
 * Run test conversion// w w  w  .  ja v  a  2 s. co  m
 *
 * @param d          test source directory
 * @param transtypes list of transtypes to test
 * @return list of log messages
 * @throws Exception if conversion failed
 */
private List<TestListener.Message> run(final File d, final String[] transtypes, final File resDir)
        throws Exception {
    if (transtypes.length == 0) {
        return emptyList();
    }

    final File tempDir = new File(baseTempDir, d.getName() + File.separator + "temp");
    deleteDirectory(resDir);
    deleteDirectory(tempDir);

    final TestListener listener = new TestListener(System.out, System.err);
    final PrintStream savedErr = System.err;
    final PrintStream savedOut = System.out;
    try {
        final File buildFile = new File(d, "build.xml");
        final Project project = new Project();
        project.addBuildListener(listener);
        System.setOut(new PrintStream(new DemuxOutputStream(project, false)));
        System.setErr(new PrintStream(new DemuxOutputStream(project, true)));
        project.fireBuildStarted();
        project.init();
        for (final String transtype : transtypes) {
            if (canCompare.contains(transtype)) {
                project.setUserProperty("run." + transtype, "true");
                if (transtype.equals("pdf") || transtype.equals("pdf2")) {
                    project.setUserProperty("pdf.formatter", "fop");
                    project.setUserProperty("fop.formatter.output-format", "text/plain");
                }
            }
        }
        project.setUserProperty("generate-debug-attributes", "false");
        project.setUserProperty("preprocess.copy-generated-files.skip", "true");
        project.setUserProperty("ant.file", buildFile.getAbsolutePath());
        project.setUserProperty("ant.file.type", "file");
        project.setUserProperty("dita.dir", ditaDir.getAbsolutePath());
        project.setUserProperty("result.dir", resDir.getAbsolutePath());
        project.setUserProperty("temp.dir", tempDir.getAbsolutePath());
        project.setKeepGoingMode(false);
        ProjectHelper.configureProject(project, buildFile);
        final Vector<String> targets = new Vector<>();
        targets.addElement(project.getDefaultTarget());
        project.executeTargets(targets);

        assertEquals("Warn message count does not match expected", getMessageCount(project, "warn"),
                countMessages(listener.messages, Project.MSG_WARN));
        assertEquals("Error message count does not match expected", getMessageCount(project, "error"),
                countMessages(listener.messages, Project.MSG_ERR));
    } finally {
        System.setOut(savedOut);
        System.setErr(savedErr);
        return listener.messages;
    }
}

From source file:org.apache.metron.dataloads.bulk.ElasticsearchDataPrunerTest.java

@Before
public void setUp() throws Exception {

    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MONTH, Calendar.MARCH);
    calendar.set(Calendar.YEAR, 2016);
    calendar.set(Calendar.DATE, 31);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    testDate = calendar.getTime();//from  www. j  a va2  s .  co  m

    when(indexClient.admin()).thenReturn(adminClient);
    when(adminClient.indices()).thenReturn(indicesAdminClient);
    when(deleteIndexRequestBuilder.request()).thenReturn(deleteIndexRequest);
    when(deleteIndexAction.actionGet()).thenReturn(deleteIndexResponse);

    File resourceFile = new File(TestConstants.SAMPLE_CONFIG_PATH);
    Path resourcePath = Paths.get(resourceFile.getCanonicalPath());

    configuration = new Configuration(resourcePath);

    outContent = new ByteArrayOutputStream();
    errContent = new ByteArrayOutputStream();

    System.setOut(new PrintStream(outContent));
    System.setErr(new PrintStream(errContent));

}

From source file:org.jkiss.dbeaver.core.application.DBeaverApplication.java

private void initDebugWriter() {
    File logPath = GeneralUtils.getMetadataFolder();
    File debugLogFile = new File(logPath, "dbeaver-debug.log"); //$NON-NLS-1$
    if (debugLogFile.exists()) {
        if (!debugLogFile.delete()) {
            System.err.println("Can't delete debug log file"); //$NON-NLS-1$
        }//from  w  w  w .jav a 2s.  c o m
    }
    try {
        debugWriter = new FileOutputStream(debugLogFile);
        oldSystemOut = System.out;
        oldSystemErr = System.err;
        System.setOut(new PrintStream(new ProxyPrintStream(debugWriter, oldSystemOut)));
        System.setErr(new PrintStream(new ProxyPrintStream(debugWriter, oldSystemErr)));
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
}