WebFaction
Community site: login faq

When I run python manage.py shell. Logging works fine, inside my middleware the messages do not get logged to the file. Any ideas why?

Code is here

asked 25 Aug '11, 17:17

Paul Egges
1257
accept rate: 0%

edited 25 Aug '11, 17:21


Does sending the same data someplace else work? I would add a print to stderr wherever you have logging.debug,

print >> sys.stderr, 'foo'

That should send the output to the Apache log and you can verify the loop is executing.

You may also want to try printing some of the environment variables with that line to see what the live django stack is using, things like the logging module itself to make sure its importing from the correct path.

permanent link

answered 25 Aug '11, 18:25

johns
5.4k312
accept rate: 23%

edited 25 Aug '11, 18:25

The last portion of the function sends the same data to the bottom of the browser screen, and it shows up. so........ it is definitely executing. Earlier in the function is an if statement, and either the if or the else should output to the log file.

(25 Aug '11, 21:56) Paul Egges

I attempted to look for an official answer, since I assume it is some issue with both modules being middleware, but their google code page is down with a 500 error at the moment (http://code.google.com/p/django-logging/wiki/Overview). I did read this in the Django docs, "If a request middleware returns an HttpResponse object, Django won't bother calling any other middleware' "

http://www.djangobook.com/en/beta/chapter16/

Does the rest of that function return an HttpResponse?

(25 Aug '11, 22:12) johns

After calling the log function, the same function returns a response object. The middleware does get called. I put in the code you suggested (to stderr), and data(txt) does end up in the Apache Log file.

    print >> sys.stderr, txt
    logging.debug(txt)
    #logging.shutdown()
    return response
(25 Aug '11, 22:23) Paul Egges

Does that same logging code work from any other place within django, say a regular view?

If you use that same print command to print the logging module itself, does it work and show the path to the module? Is this path correct?

(25 Aug '11, 22:37) johns

The original code with some modification came from another user. I've not tried it in a view. when I bring it up within the python manage.py shell it is the same module that is being loaded when django/wsgi loads the module (checked by print >>sys.stderr, logging.file yielding the same path.

(26 Aug '11, 02:13) Paul Egges

That is a good plan. I did find some more info,

https://docs.djangoproject.com/en/dev/topics/logging/

Notice how in the example code it defines this line,

logger = logging.getLogger(__name__)

And than that variable is what is called for future code.

Your sample code has this commented out, and is calling the logging module directly.

You should try to adjust the code to be more in align with the example.

(26 Aug '11, 02:24) johns
showing 5 of 6 show 1 more comments
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×337
×10
×2

question asked: 25 Aug '11, 17:17

question was seen: 10,994 times

last updated: 26 Aug '11, 02:24

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM