Simon
Simon

Reputation: 80759

How do I write to a log from mod_python under apache?

I seem to only be able to write to the Apache error log via stderr. Anyone know of a more structured logging architecture that I could use from my python web project, like commons?

Upvotes: 2

Views: 5422

Answers (4)

Andrew
Andrew

Reputation: 3061

This must have changed in the past four years. If you come across this question and want to do this then you can do it through the request object, i.e

def handler(req) :
  req.log_error('Hello apache')

Upvotes: 4

afternoon
afternoon

Reputation: 1285

I concur with Blair Conrad's post about the Python logging module. The standard log handlers sometimes drop messages however. It's worth using the logging module's SocketHandler and building a receiver to listen for messages and write them to file.

Here's mine: Example SocketHandler receiver.

Upvotes: 0

Jay
Jay

Reputation: 42632

There isn't any built in support for mod_python logging to Apache currently. If you really want to work within the Apache logs you can check out this thread (make sure you get the second version of the posted code, rather than the first):

If you're just looking to use a more structured logging system, the Python standard logging module referred to by Blair is very feature complete. Aside from the Python.org docs Blair linked, here's a more in-depth look at the module's features from onLamp:

And for a quickie example usage:

Upvotes: 3

Blair Conrad
Blair Conrad

Reputation: 241764

I've used the builtin Python logging module in (non-web) projects in the past, with success - it should work in a web-hosted environment as well.

Upvotes: 2

Related Questions