Hi.

One point for the record...

Using the Python Logger module works OK except that you have to be careful 
to shut the StreamHandler down very thoroughly before returning from your 
app function.  It appeared from the Logger code that calling flush and 
close on the StreamHandler would stop it using the wsgi.error stream after 
it was shut down but this didn't seem to work as expected.  The Logger 
module installs an 'atexit' function that flushes the stream and hence 
provokes an exception in mod_wsgi.  I worked around this by explicitly 
setting the StreamHandler stream to None after flushing the stream before 
exiting.

Regards,
Elwyn


On Tuesday, November 20, 2012 12:22:54 PM UTC, elwynd wrote:
>
> [Moved to Google Group from private email]
>
> Thanks for the response Graham.
>
> Yes, the standalone version makes use of Python logging.  It seemed that 
> it was adding an
> additional and potentially unnecessary layer to use Python logging on top 
> of the existing
> Apache multilevel logging given that Apache logging has the leveling 
> needed.
>
> Is there anything inherently difficult or undesirable to making the Apache 
> logging level
> control accessible that I haven't spotted?  Threading comes to mind if the 
> level setting
> is not in the actual log write method - I am not sure whether the 
> wsgi.errors logger is 
> per-thread or shared in a multiple thread per-process situation.
>
> Regards,
> Elwyn
>
>  
>
>> Are you using:
>>
>> http://docs.python.org/2/library/logging.html
>>
>> It provides log levels and the output of what does get through can still 
>> be
>> sent to stderr and captured in the Apache error log.
>>
>> The logging module should be used in preference to using wsgi.errors.
>>
>> The only cosmetic issue is that in the Apache error log everything shows 
>> as
>> at error level that goes to stdout/stderr. This is something that can't be
>> changed.
>>
>> To see the proper log level you can still set the logging module logger
>> message format to include the logging module log level. It will end up
>> being part of the logged message. Thus the entries in the Apache error log
>> might end up looking like:
>>
>> [Fri Nov 16 05:02:40 2012] [error] 2012-11-16 05:02:40,095 (5010/Dummy-6)
>> newrelic.core.agent INFO - New Relic Python Agent Shutdown
>> [Fri Nov 16 05:02:40 2012] [error] 2012-11-16 05:02:40,119
>> (5010/NR-Harvest-Thread) newrelic.core.agent DEBUG - Commencing harvest of
>> all application data and forcing a shutdown at the same time.
>>
>> In this case the log format was still including its own date/time 
>> stamp,but
>> you could drop that to make it more compact.
>>
>> BTW, can you use the mod_wsgi mailing list in future.
>>
>>
>> http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Asking_Your_Questions
>>
>> Thanks.
>>
>> Graham
>>
>>
>>
>>
>>
>> On 20 November 2012 08:06, Elwyn Davies <[email protected]> wrote:
>>
>> > Hi.
>> >
>> > I am just starting out with mod_wsgi.
>> >
>> > I have an existing application which is currently running using a basic
>> > BaseHTTPServer/BaseHTTPHandler with a Python logger in a standalone
>> > program.  I am now moving the code to run as a mod_wsgi module.
>> >
>> > The code contains extensive logging both for debugging and monitoring
>> > using multiple logging levels to tune the amount of output according to 
>> my
>> > confidence in the code.  I would like to be able to set the logging 
>> level
>> > for each logged message.  As I understand mod_wsgi the 'wsgi.errors'
>> > logging object has a fixed logging level, so that whilst I can control
>> > whether any messages from the mod_wsgi application are logged by Apache
>> > using the log level setting in Apache, this is rather a blunt 
>> instrument.
>> >
>> > Having had a quick look at the code, it looks as if it would be very 
>> easy
>> > to add a getter/setter pair to allow adjustment of the 'level' value in 
>> the
>> > log structure.
>> >
>> > Would this be an effective and sane enhancement?  I have some code that 
>> I
>> > am currently trying out - not exactly a difficult mod!
>> >
>> > Regards,
>> > Elwyn Davies
>> > Folly Consulting/Trinity College Dublin
>> >
>> >
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/modwsgi/-/hyAjWh_4qaYJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/modwsgi?hl=en.

Reply via email to