You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "John C. Turnbull" <oz...@ozemail.com.au> on 2002/10/03 00:08:26 UTC

Separating stdout and stderr

This is my first use of log4j so please excuse me if this is a lame
question.

We need to log to stdout in some places and stderr in others and both in
some other places.  What's the best way to handle this?  Will I need
separate loggers for each type of output or is this somehow handled by
appenders?

Thanks,

John


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Separating stdout and stderr

Posted by "John C. Turnbull" <oz...@ozemail.com.au>.
----- Original Message -----
From: "Colin MacDonald" <co...@templarcorp.com>
To: "Log4J Users List" <lo...@jakarta.apache.org>
Sent: Friday, October 04, 2002 12:52 AM
Subject: RE: Separating stdout and stderr


> I'm still puzzled by why you want to do this.  If stdout and stderr are
both
> just writing to the screen, why differentiate them?  And if one is being
> redirected to a file, why not use a file appender?

I have to replace lines like the following with log4j calls instead.

System.out.println("This line goes only to stdout");
...
System.err.println("This line goes only to stderr");

So the question is how to send some output to stdout and some to stderr
only.

John


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Separating stdout and stderr

Posted by Colin MacDonald <co...@templarcorp.com>.
> -----Original Message-----
>
> There is actually no need to log to both stdout and stderr at the
> same time
> so it's just a matter of sending some output to one or the other
> from within
> the same class.  Maybe I should simply be logging at different
> levels?  Just
> want to know what the "standard" way of doing this is.

Sorry, I was making an incorrect assumption about how ConsoleAppender works.
It looks like you should be able to define two console appenders like so:

  <appender name="CONSOLE_OUT" class="org.apache.log4j.ConsoleAppender">
    <param name="target" value="System.out" />
    <layout ...
    </layout>
  </appender>

  <appender name="CONSOLE_ERR" class="org.apache.log4j.ConsoleAppender">
    <param name="target"    value="System.err" />
    <param name="threshold" value="ERROR" />
    <layout ...
    </layout>
  </appender>

I don't know how to keep ERROR and FATAL messages from going to System.out.
So if they're both just writing to the screen, you'll see duplicates of the
lower priority messages.  Also, I haven't tried this myself, so I can't
really vouch for it, but this should at least point you in the right
direction.

I'm still puzzled by why you want to do this.  If stdout and stderr are both
just writing to the screen, why differentiate them?  And if one is being
redirected to a file, why not use a file appender?

Anyway, I hope this helps.

-----------------------------------------------------------------
Colin MacDonald  |  Software Developer  |  Templar Corporation  |
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.393 / Virus Database: 223 - Release Date: 9/30/2002


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Separating stdout and stderr

Posted by "John C. Turnbull" <oz...@ozemail.com.au>.
There is actually no need to log to both stdout and stderr at the same time
so it's just a matter of sending some output to one or the other from within
the same class.  Maybe I should simply be logging at different levels?  Just
want to know what the "standard" way of doing this is.

----- Original Message -----
From: "Colin MacDonald" <co...@templarcorp.com>
To: "Log4J Users List" <lo...@jakarta.apache.org>
Sent: Thursday, October 03, 2002 8:34 AM
Subject: RE: Separating stdout and stderr


> > -----Original Message-----
> >
> > We need to log to stdout in some places and stderr in others and both in
> > some other places.  What's the best way to handle this?  Will I need
> > separate loggers for each type of output or is this somehow handled by
> > appenders?
>
> Well, first, why are you writing to both stdout and stderr?  I mean,
> normally you do that so you can redirect one to a file, in which case you
> should just use a file appender of some sort.
>
> -----------------------------------------------------------------
> Colin MacDonald  |  Software Developer  |  Templar Corporation  |
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.393 / Virus Database: 223 - Release Date: 9/30/2002
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Separating stdout and stderr

Posted by Colin MacDonald <co...@templarcorp.com>.
> -----Original Message-----
>
> We need to log to stdout in some places and stderr in others and both in
> some other places.  What's the best way to handle this?  Will I need
> separate loggers for each type of output or is this somehow handled by
> appenders?

Well, first, why are you writing to both stdout and stderr?  I mean,
normally you do that so you can redirect one to a file, in which case you
should just use a file appender of some sort.

-----------------------------------------------------------------
Colin MacDonald  |  Software Developer  |  Templar Corporation  |
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.393 / Virus Database: 223 - Release Date: 9/30/2002


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>