[Twisted-Python] Logging to both console and file (using twisted logging API)?
naman jain
namanvit at gmail.com
Thu Nov 5 01:59:29 MST 2009
People,
Can anyone help me with this issue?
log.startLogging(open(logname,'w')
or
log.startLogging(open(logname,'w'), setStdout=True)
Both print the console output in the log. But nothing is displayed on
console! So I get a empty console
I would like to keep the console going also:
Precisely:
Console -> gets the print calls Not Happening
Log -> gets the print calls + log.msg calls Happening
I understand that this might be a trivial issue, but I am not able to figure
it out in the documentation available :(
Thanks for any help
Regards
Naman
On Wed, Nov 4, 2009 at 7:43 AM, naman jain <namanvit at gmail.com> wrote:
> Hi,
>
> Using log.startLogging(open(logname, 'w'), setStdout=False)
> very well solves the issue.. of stdout remaining untouched and log.msg()
> calls going to log
>
> Can we do this ?:
> Log file gets -> both the log.msg() calls , the stdout +stderr
> console -> gets stdout +stderr as usual
>
> Regards
> Naman
>
>
>
> On Fri, Oct 30, 2009 at 9:25 PM, David Bolen <db3l.net at gmail.com> wrote:
>
>> naman jain <namanvit at gmail.com> writes:
>>
>> > I wanted to log in a file and keep the console also going with it.
>>
>> I can read this as either:
>>
>> * Keep file logs and stdout/console completely separate, or
>> * File gets explicit logs and copies of stdout, but stdout also goes to
>> console as well.
>>
>> The latter is something I'd more commonly do, but the former is what
>> you explain further below with your rules.
>>
>> > I am using
>> > log.startLogging(open(logname, 'w'))
>> >
>> > whatever documentation I could find about this API, it suggested me to
>> pass
>> > setStdout=False(in order to keep stdout away from putting into log)
>> > somewhere in the startlogging function.
>> >
>> > Something like this I tried:
>> > log.startLogging(sys.stdout,setStdout=False)
>>
>> Why did you switch to sys.stdout here? While this will prevent
>> sys.stdout and sys.stderr from being redirected, it will use
>> sys.stdout for any log.msg() calls, so nothing would end up in your
>> log file.
>>
>> > Doesnt help in solving the problem of getting both things:
>> >
>> > Requirement:
>> > log.msg("messageforlog") -> goes to log
>> > print "message for console" -> goes to console
>> >
>> > Could anyone give some ideas on this?
>>
>> I think you had the right idea with setStdout, but changed more than
>> just that when you tested it. If you use a call like
>> log.startLogging(open(logname, 'w'), setStdout=False) I believe you'll
>> get what you want. Only calls to log.msg() will go to the file, and
>> stdout/stderr will be left unchanged.
>>
>> -- David
>>
>>
>> _______________________________________________
>> Twisted-Python mailing list
>> Twisted-Python at twistedmatrix.com
>> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20091105/a4526509/attachment.html>
More information about the Twisted-Python
mailing list