Hi,<br><br>Using log.startLogging(open(logname, 'w'), setStdout=False)<br>very well solves the issue.. of stdout remaining untouched and log.msg() calls going to log<br><br>Can we do this ?:<br>Log file gets -> both the log.msg() calls , the stdout +stderr<br>
console -> gets stdout +stderr as usual<br><br>Regards<br>Naman<br><br><br><div class="gmail_quote">On Fri, Oct 30, 2009 at 9:25 PM, David Bolen <span dir="ltr"><<a href="http://db3l.net">db3l.net</a>@<a href="http://gmail.com">gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">naman jain <<a href="mailto:namanvit@gmail.com">namanvit@gmail.com</a>> writes:<br>
<br>
> I wanted to log in a file and keep the console also going with it.<br>
<br>
</div>I can read this as either:<br>
<br>
* Keep file logs and stdout/console completely separate, or<br>
* File gets explicit logs and copies of stdout, but stdout also goes to<br>
console as well.<br>
<br>
The latter is something I'd more commonly do, but the former is what<br>
you explain further below with your rules.<br>
<div class="im"><br>
> I am using<br>
> log.startLogging(open(logname, 'w'))<br>
><br>
> whatever documentation I could find about this API, it suggested me to pass<br>
> setStdout=False(in order to keep stdout away from putting into log)<br>
> somewhere in the startlogging function.<br>
><br>
> Something like this I tried:<br>
> log.startLogging(sys.stdout,setStdout=False)<br>
<br>
</div>Why did you switch to sys.stdout here? While this will prevent<br>
sys.stdout and sys.stderr from being redirected, it will use<br>
sys.stdout for any log.msg() calls, so nothing would end up in your<br>
log file.<br>
<div class="im"><br>
> Doesnt help in solving the problem of getting both things:<br>
><br>
> Requirement:<br>
> log.msg("messageforlog") -> goes to log<br>
> print "message for console" -> goes to console<br>
><br>
> Could anyone give some ideas on this?<br>
<br>
</div>I think you had the right idea with setStdout, but changed more than<br>
just that when you tested it. If you use a call like<br>
log.startLogging(open(logname, 'w'), setStdout=False) I believe you'll<br>
get what you want. Only calls to log.msg() will go to the file, and<br>
stdout/stderr will be left unchanged.<br>
<br>
-- David<br>
<br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</blockquote></div><br>