|
Loading...
|
log4j-user@logging.apache.org
[Prev] Thread [Next] | [Prev] Date [Next]
RE: redirecting Stdout and stderr to a different log file Himanshu Gupta Wed Feb 01 22:08:31 2012
Hi Umesh,
You can define a custom appender and associated logger for this purpose and
then use that logger in your SysOutErrRedirector.
Sample code:
------------------------------
public class SysOutErrRedirector
{
private Logger logger;
public SysOutErrRedirector(Logger myLogger)
{
super();
logger = myLogger;
initialize();
}
/**
* Initialize the redirection.
*
* @param myLogger
*/
@SuppressWarnings("rawtypes")
private void initialize()
{
Enumeration e =
LogManager.getLoggerRepository().getRootLogger().getAllAppenders();
while (e.hasMoreElements())
{
Appender appender = (Appender) e.nextElement();
if (appender instanceof ConsoleAppender)
{
if (((ConsoleAppender)
appender).getFollow())
{
((ConsoleAppender)
appender).setFollow(false);
((ConsoleAppender)
appender).activateOptions();
}
logger.removeAppender(appender);
}
}
System.setOut(new PrintStream(new
LoggingOutputStream(logger, Level.DEBUG), true));
System.setErr(new PrintStream(new
LoggingOutputStream(logger, Level.ERROR), true));
}
}
-----------------
Thanks,
Himanshu
-----Original Message-----
From: Umesh Paliwal [mailto:[EMAIL PROTECTED]
Sent: Monday, January 16, 2012 9:58 PM
To: Log4J Users List
Subject: RE: redirecting Stdout and stderr to a different log file
Hi Himanshu,
I am able to redirect the sysouts and syserr to a file. But I need them in a
individual file so that it is not combined with other logs.
Can you help me out
Regards,
Umesh
-----Original Message-----
From: Himanshu Gupta [mailto:[EMAIL PROTECTED]
Sent: Tuesday, January 17, 2012 11:27 AM
To: 'Log4J Users List'
Subject: RE: redirecting Stdout and stderr to a different log file
Hi Umesh,
You can write a SysOutErrRedirector which can take out and err streams and
use log4j root logger (or any other defined logger) to move it to the
associated appender.
Thanks,
Himanshu
-----Original Message-----
From: Umesh Paliwal [mailto:[EMAIL PROTECTED]
Sent: Monday, January 16, 2012 9:38 PM
To: [EMAIL PROTECTED]
Subject: RE: redirecting Stdout and stderr to a different log file
Can anyone help me on the issue below. Please
From: Umesh Paliwal
Sent: Tuesday, January 10, 2012 9:47 AM
To: '[EMAIL PROTECTED]'
Subject: redirecting Stdout and stderr to a different log file
Hi All,
We have lot many sysouts in our project. The sysout are captured in file by
using a redirect operator when we launch the server.
The maintanence of the files a big issue as these logs keep on growing.
Can you please help me find out a strategy if I can redirect all the sysout
and stderr into a logging file using log4j.
Thanks and regards,
Umesh Paliwal
The information contained in this e-mail is private & confidential and may
also be legally privileged. If you are not the intended recipient, please
notify us, preferably by e-mail, and do not read, copy or disclose the
contents of this message to anyone.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
The information contained in this e-mail is private & confidential and may
also be legally privileged. If you are not the intended recipient, please
notify us, preferably by e-mail, and do not read, copy or disclose the
contents of this message to anyone.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
- redirecting Stdout and stderr to a different log file Umesh Paliwal 2012/02/01
- RE: redirecting Stdout and stderr to a different log file Umesh Paliwal 2012/02/01
- RE: redirecting Stdout and stderr to a different log file Himanshu Gupta 2012/02/01
- RE: redirecting Stdout and stderr to a different log file Umesh Paliwal 2012/02/01
- RE: redirecting Stdout and stderr to a different log file Douglas E Wegscheid 2012/02/01
- RE: redirecting Stdout and stderr to a different log file Umesh Paliwal 2012/02/01
- RE: redirecting Stdout and stderr to a different log file Douglas E Wegscheid 2012/02/01
- Re: redirecting Stdout and stderr to a different log file Tushar Kapila 2012/02/01
- RE: redirecting Stdout and stderr to a different log file Himanshu Gupta 2012/02/01 <=