Example usage for java.io FileDescriptor err

List of usage examples for java.io FileDescriptor err

Introduction

In this page you can find the example usage for java.io FileDescriptor err.

Prototype

FileDescriptor err

To view the source code for java.io FileDescriptor err.

Click Source Link

Document

A handle to the standard error stream.

Usage

From source file:Main.java

public static void main(String args[]) {
    FileDescriptor fd = FileDescriptor.err;
    System.out.println(fd.hashCode());
}

From source file:de.cosmocode.palava.core.Main.java

private static void printToStdErr(Exception e) {
    final OutputStream stream = new FileOutputStream(FileDescriptor.err);
    final PrintStream stderr = new PrintStream(stream);
    e.printStackTrace(stderr);/*w  w w  . j a  v a2  s .co m*/
    Closeables.closeQuietly(stderr);
}

From source file:org.apache.jackrabbit.oak.run.DataStoreCheckTest.java

@After
public void tearDown() {
    System.setErr(new PrintStream(new FileOutputStream(FileDescriptor.err)));
}

From source file:org.apache.jackrabbit.oak.run.DataStoreCheckTest.java

public static void testIncorrectParams(List<String> argList, String assertMsg) throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    System.setErr(new PrintStream(buffer, true, UTF_8.toString()));

    DataStoreCheckCommand checkCommand = new DataStoreCheckCommand();

    checkCommand.execute(argList.toArray(new String[0]));
    String message = buffer.toString(UTF_8.toString());
    log.info("Assert message: {}", assertMsg);
    log.info("Message logged in System.err: {}", message);

    Assert.assertTrue(message.contains(assertMsg));
    System.setErr(new PrintStream(new FileOutputStream(FileDescriptor.err)));
}

From source file:org.openconcerto.sql.PropsConfiguration.java

public void setupLogging(final String dirName, final boolean redirectToFile) {
    final File logDir;
    synchronized (this.restLock) {
        if (this.logDir != null)
            throw new IllegalStateException("Already set to " + this.logDir);
        logDir = getValidLogDir(dirName);
        this.logDir = logDir;
    }/*from  ww w.ja v a 2 s.c  om*/
    final String logNameBase = this.getAppName() + "_" + getLogDateFormat().format(new Date());

    // must be done before setUpConsoleHandler(), otherwise log output not redirected
    if (redirectToFile) {
        final File logFile = new File(logDir, (logNameBase + ".txt"));
        try {
            FileUtils.mkdir_p(logFile.getParentFile());
            System.out.println("Log file: " + logFile.getAbsolutePath());
            final OutputStream fileOut = new FileOutputStream(logFile, true);
            final OutputStream out, err;
            System.out.println("Java System console:" + System.console());
            boolean launchedFromEclipse = new File(".classpath").exists();
            if (launchedFromEclipse) {
                System.out.println("Launched from eclipse");
            }
            if ((System.console() != null || launchedFromEclipse)
                    && this.keepStandardStreamsWhenRedirectingToFile()) {
                System.out.println("Redirecting standard output to file and console");
                out = new MultipleOutputStream(fileOut, new FileOutputStream(FileDescriptor.out));
                System.out.println("Redirecting error output to file and console");
                err = new MultipleOutputStream(fileOut, new FileOutputStream(FileDescriptor.err));

            } else {
                out = fileOut;
                err = fileOut;
            }
            System.setErr(new PrintStream(new BufferedOutputStream(err, 128), true));
            System.setOut(new PrintStream(new BufferedOutputStream(out, 128), true));
            // Takes about 350ms so run it async
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        FileUtils.ln(logFile, new File(logDir, "last.log"));
                    } catch (final IOException e) {
                        // the link is not important
                        e.printStackTrace();
                    }
                }
            }).start();
        } catch (final Exception e) {
            ExceptionHandler.handle("Redirection des sorties standards impossible", e);
        }
    } else {
        System.out.println("Standard streams not redirected to file");
    }

    // removes default
    LogUtils.rmRootHandlers();
    // add console handler
    LogUtils.setUpConsoleHandler();
    // add file handler (supports concurrent launches, doesn't depend on date)
    try {
        final File logFile = new File(logDir, this.getAppName() + "-%u-age%g.log");
        FileUtils.mkdir_p(logFile.getParentFile());
        System.out.println("Logger logs: " + logFile.getAbsolutePath());
        // 2 files of at most 5M, each new launch append
        // if multiple concurrent launches %u is used
        final FileHandler fh = new FileHandler(logFile.getPath(), 5 * 1024 * 1024, 2, true);
        fh.setFormatter(new SimpleFormatter());
        Logger.getLogger("").addHandler(fh);
    } catch (final Exception e) {
        ExceptionHandler.handle("Enregistrement du Logger dsactiv", e);
    }

    this.setLoggersLevel();
}