Pricey
Pricey

Reputation: 538

Logging web.ctx

I'm using web.py & python's logging module.

I would like to log add lots of logging. To make things more useful, I would like to add as standard the ip address of the client to the logging format (web.ctx.ip)

Now I 'could' do this by just writing every logging line a little like...

logging.debug(web.ctx.ip + "something else here")

... but yeah... no...

I'm not the most seasoned pythonista but am happy reading documentation. The python documentation seems to give this exact usecase as an example for when to use logging.LoggerAdapter or logging.Filter but I'm struggling to:

  1. Chose whether I want to use an Adapter or a Filter?
  2. and go from their examples to a working solution with web.ctx.

Would someone be able to give me a nudge? Do I need to clarify what I'm asking?

Upvotes: 0

Views: 600

Answers (1)

Vinay Sajip
Vinay Sajip

Reputation: 99317

Use a Filter, there's an example in this post (not web.py specific, but you should be able to adapt it).

Update: You can use either Filter or LoggerAdapter, so pick one, like I did :-). I just picked it because there was an example handy. You really can use either, as the docs indicate.

Upvotes: 1

Related Questions