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:AloneService.java

/**
 * init and destroy were added in jakarta-tomcat-daemon.
 *///from ww  w .  j  a  va2 s.c  o m
public void init(String[] arguments) throws Exception {
    /* Set the err */
    System.setErr(new PrintStream(new FileOutputStream(new File("/ServiceDaemon.err"), true)));
    System.err.println("ServiceDaemon: instance " + this.hashCode() + " init");

    /* read the properties file */
    prop = new ExtendedProperties("startfile");

    /* create an array to store the processes */
    int i = 0;
    for (Iterator e = prop.getKeys(); e.hasNext();) {
        e.next();
        i++;
    }
    System.err.println("ServiceDaemon: init for " + i + " processes");
    proc = new Process[i];
    readout = new ServiceDaemonReadThread[i];
    readerr = new ServiceDaemonReadThread[i];
    for (i = 0; i < proc.length; i++) {
        proc[i] = null;
        readout[i] = null;
        readerr[i] = null;
    }

    System.err.println("ServiceDaemon: init done ");

}

From source file:org.uimafit.testing.util.HideOutput.java

/**
 * calling this constructor will silence System.out and System.err until
 * {@link #restoreOutput()} is called by setting them to this OutputStream
 *//*from  ww  w .  java  2 s. c  o  m*/
public HideOutput() {
    this.out = System.out;
    this.err = System.err;
    System.setOut(new PrintStream(NullOutputStream.NULL_OUTPUT_STREAM));
    System.setErr(new PrintStream(NullOutputStream.NULL_OUTPUT_STREAM));
}

From source file:com.datatorrent.contrib.schema.parser.JsonParserTest.java

public JsonParserTest() {
    // So that the output is cleaner.
    System.setErr(new PrintStream(myOut));
}

From source file:com.datatorrent.contrib.schema.formatter.JsonFormatterTest.java

public JsonFormatterTest() {
    // So that the output is cleaner.
    System.setErr(new PrintStream(myOut));
}

From source file:com.kotcrab.vis.editor.Log.java

/** Initializes logging facility, called once by VisEditor. */
public static void init() {
    if (initialized)
        throw new IllegalStateException("Log cannot be initialized twice!");
    initialized = true;/*from   w  w w . j  a v a  2  s .c o  m*/
    prepareLogFile();
    System.setOut(new PrintStream(new TeeOutputStream(System.out, logFileStream)));
    System.setErr(new PrintStream(new TeeOutputStream(System.err, logFileStream)));
}

From source file:ServiceDaemon.java

/**
 * init and destroy were added in jakarta-tomcat-daemon.
 */// w w  w . j a v a 2s. co  m
public void init(DaemonContext context) throws Exception {
    /* Set the err */
    System.setErr(new PrintStream(new FileOutputStream(new File("ServiceDaemon.err")), true));
    System.err.println("ServiceDaemon: instance " + this.hashCode() + " init");

    /* read the properties file */
    prop = new Properties();
    try {
        prop.load(new FileInputStream("startfile"));
    } catch (Exception e) {
        // Cannot find startfile.properties.
        // XXX: Should we print something?
    }
    /* create an array to store the processes */
    int i = 0;
    for (Enumeration e = prop.keys(); e.hasMoreElements();) {
        e.nextElement();
        i++;
    }
    System.err.println("ServiceDaemon: init for " + i + " processes");
    proc = new Process[i];
    readout = new ServiceDaemonReadThread[i];
    readerr = new ServiceDaemonReadThread[i];
    for (i = 0; i < proc.length; i++) {
        proc[i] = null;
        readout[i] = null;
        readerr[i] = null;
    }

    System.err.println("ServiceDaemon: init done ");

}

From source file:org.sonar.batch.mediumtest.log.LogListenerTest.java

@AfterClass
public static void resumeStdStreams() {
    if (savedStdOut != null) {
        System.setOut(savedStdOut);
    }//from  ww  w  . j  a  v  a2s.  co  m
    if (savedStdErr != null) {
        System.setErr(savedStdErr);
    }
}

From source file:fr.gael.dhus.DHuS.java

/** Starts the DHuS (starts Tomcat, creates the Spring application context. */
public static void start() {
    // Transfer System.err in logger
    System.setErr(new PrintStream(new LoggingOutputStream(LOGGER), true));

    String version = DHuS.class.getPackage().getImplementationVersion();

    // Force ehcache not to call home
    System.setProperty("net.sf.ehcache.skipUpdateCheck", "true");
    System.setProperty("org.terracotta.quartz.skipUpdateCheck", "true");
    System.setProperty("user.timezone", "UTC");
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    System.setProperty("fr.gael.dhus.version", version == null ? "dev" : version);

    if (!SystemService.restore()) {
        LOGGER.error("Cannot run system restoration.");
        LOGGER.error("Check the restoration file \"" + SystemService.RESTORATION_PROPERTIES
                + "\" from the current directory.");
        System.exit(1);//from   w ww  . j  a  v a 2s  .c  o m
    }

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            if ((server != null) && server.isRunning()) {
                try {
                    server.stop();
                } catch (TomcatException e) {
                    e.printStackTrace();
                }
            }
        }
    }));

    // Always add JMSAppender
    //Logger rootLogger = LogManager.getRootLogger ();
    //org.apache.logging.log4j.core.Logger coreLogger =
    //(org.apache.logging.log4j.core.Logger)rootLogger;
    //JMSAppender jmsAppender = JMSAppender.createAppender ();
    //coreLogger.addAppender (jmsAppender);
    try {
        // Activates the resolver for Drb
        DrbFactoryResolver.setMetadataResolver(new DrbCortexMetadataResolver(DrbCortexModel.getDefaultModel()));
    } catch (IOException e) {
        LOGGER.error("Resolver cannot be handled.");
        //logger.error (new Message(MessageType.SYSTEM,
        //"Resolver cannot be handled."));
    }

    LOGGER.info("Launching Data Hub Service...");
    //logger.info (new Message(MessageType.SYSTEM,
    //"Loading Data Hub Service..."));

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:fr/gael/dhus/spring/dhus-core-context.xml");
    context.registerShutdownHook();

    // Registers ContextClosedEvent listeners to properly save states before
    // the Spring context is destroyed.
    ApplicationListener sync_sv = context.getBean(ISynchronizerService.class);
    context.addApplicationListener(sync_sv);

    // Initialize Database Incoming folder
    IncomingManager incoming_manager = (IncomingManager) context.getBean("incomingManager");
    incoming_manager.initIncoming();

    // Initialize DHuS loggers
    //jmsAppender.cleanWaitingLogs ();
    //logger.info (new Message(MessageType.SYSTEM, "DHuS Started"));
    try {
        //ftp = xml.getBean (FtpServer.class);
        //ftp.start ();

        server = ApplicationContextProvider.getBean(TomcatServer.class);
        server.init();

        LOGGER.info("Starting server " + server.getClass() + "...");
        //logger.info (new Message(MessageType.SYSTEM, "Starting server..."));
        server.start();
        //logger.info (new Message(MessageType.SYSTEM, "Server started."));

        LOGGER.info("Server started.");

        // Initialises SolrDAO
        SolrDao solr_dao = (SolrDao) context.getBean("solrDao");
        solr_dao.initServerStarted();

        Map<String, WebApplication> webapps = context.getBeansOfType(WebApplication.class);
        for (String beanName : webapps.keySet()) {
            server.install(webapps.get(beanName));
        }

        fr.gael.dhus.server.http.web.WebApplication.installAll(server);
        WebServlet.installAll(server);
        WebPostProcess.launchAll();

        LOGGER.info("Server is ready...");
        started = true;

        //InitializableComponent.initializeAll ();
        //logger.info (new Message(MessageType.SYSTEM, "Server is ready..."));
        server.await();
    } catch (Exception e) {
        LOGGER.error("Cannot start system.", e);
        //logger.error (new Message(MessageType.SYSTEM, "Cannot start DHuS."), e);
        //ftp.stop ();
        System.exit(1);
    }
}

From source file:org.apache.zookeeper.server.persistence.TxnLogToolkitTest.java

@Before
public void setUp() throws IOException {
    System.setOut(new PrintStream(outContent));
    System.setErr(new PrintStream(errContent));
    File snapDir = new File(testData, "invalidsnap");
    mySnapDir = ClientBase.createTmpDir();
    FileUtils.copyDirectory(snapDir, mySnapDir);
}

From source file:test.org.eclipse.dirigible.runtime.java.AbstractJavaExecutorTest.java

@Before
public void setUp() throws Exception {
    repository = new DBRepository(createLocal(), USER, true);
    executor = createExecutor();//from   w w  w. j  a  va  2 s.co m

    backupOut = System.out;
    backupErr = System.err;

    baos = new ByteArrayOutputStream();
    printStream = new PrintStream(baos);

    System.setOut(printStream);
    System.setErr(printStream);
}