Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6227811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:17:04+00:00 2026-05-24T09:17:04+00:00

I have a method which runs asynchronously after start, using OutputStream or Writer as

  • 0

I have a method which runs asynchronously after start, using OutputStream or Writer as parameter.

It acts as a recording adapter for an OutputStream or Writer (it’s a third party API I can’t change).

How could I pass Log4J’s internal OutputStream or Writer to that method?
…because Log4J swallows System.out and System.err, I was using before.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:17:04+00:00Added an answer on May 24, 2026 at 9:17 am

    My suggestion is, why dont you write your OutputStream then?! I was about to write one for you, but I found this good example on the net, check it out!

    LogOutputStream.java

    /*
     * Jacareto Copyright (c) 2002-2005
     * Applied Computer Science Research Group, Darmstadt University of
     * Technology, Institute of Mathematics & Computer Science,
     * Ludwigsburg University of Education, and Computer Based
     * Learning Research Group, Aachen University. All rights reserved.
     *
     * Jacareto is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public
     * License as published by the Free Software Foundation; either
     * version 2 of the License, or (at your option) any later version.
     *
     * Jacareto is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     * General Public License for more details.
     *
     * You should have received a copy of the GNU General Public
     * License along with Jacareto; if not, write to the Free
     * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     *
     */
    
    package jacareto.toolkit.log4j;
    
    
    import org.apache.log4j.Level;
    import org.apache.log4j.Logger;
    
    import java.io.OutputStream;
    
    /**
     * This class logs all bytes written to it as output stream with a specified logging level.
     *
     * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
     * @version 1.0
     */
    public class LogOutputStream extends OutputStream {
        /** The logger where to log the written bytes. */
        private Logger logger;
    
        /** The level. */
        private Level level;
    
        /** The internal memory for the written bytes. */
        private String mem;
    
        /**
         * Creates a new log output stream which logs bytes to the specified logger with the specified
         * level.
         *
         * @param logger the logger where to log the written bytes
         * @param level the level
         */
        public LogOutputStream (Logger logger, Level level) {
            setLogger (logger);
            setLevel (level);
            mem = "";
        }
    
        /**
         * Sets the logger where to log the bytes.
         *
         * @param logger the logger
         */
        public void setLogger (Logger logger) {
            this.logger = logger;
        }
    
        /**
         * Returns the logger.
         *
         * @return DOCUMENT ME!
         */
        public Logger getLogger () {
            return logger;
        }
    
        /**
         * Sets the logging level.
         *
         * @param level DOCUMENT ME!
         */
        public void setLevel (Level level) {
            this.level = level;
        }
    
        /**
         * Returns the logging level.
         *
         * @return DOCUMENT ME!
         */
        public Level getLevel () {
            return level;
        }
    
        /**
         * Writes a byte to the output stream. This method flushes automatically at the end of a line.
         *
         * @param b DOCUMENT ME!
         */
        public void write (int b) {
            byte[] bytes = new byte[1];
            bytes[0] = (byte) (b & 0xff);
            mem = mem + new String(bytes);
    
            if (mem.endsWith ("\n")) {
                mem = mem.substring (0, mem.length () - 1);
                flush ();
            }
        }
    
        /**
         * Flushes the output stream.
         */
        public void flush () {
            logger.log (level, mem);
            mem = "";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using VS2010 i have a test that calls a method which runs a command
I have the following call which runs a method within a cacheListener object asynchronously:
I have a method which runs this: Track* track = [[Track alloc] init:[obj objectForKey:@PersistentID]
I have a method which is given the parameter bool sortAscending. Now I want
I have a method which runs several rake commands. Does this method belong in
I have a Hibernate transactional method doImportImpl which runs multi-threaded. Certain records however need
So I have this builder that runs a buildClass method which should be public,
i have some jquery script which runs after the window has loaded $(window).load( function()
I have an AsyncTask which calls my LocationHandler class method getLocation() which runs a
I have made the following method which runs hard-coded xPath queries in a hard-coded

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.