On Mon, 2009-02-16 at 19:03 -0800, Polat Tuzla wrote: > Thanks a lot for your reply Malcolm. > It's OK if I don't understand the reason of different behaviours, but > I must find a proper way of writing log files on the linux server.
Aah, context certainly helps with understanding the broader issues. There are other ways to solve your problem that might be more robust. > > I think I should have clarified some more facts about my setup. > 1- On mac, django is running on dev mode, so stdout is the console. On > linux, it's mod_wsgi, so stdout is redirected to apache error log > files, on which I'm issuing a "tail -f" thorough ssh. I was a little surprised that stdout was redirected to the error logs in mod_wsgi, but it seems that that is indeed the case. I don't know what mod_wsgi might be doing to character encoding on output (maybe nothing, but maybe that's playing a role). However, instead of using print, I would recommend using Python's logging module and sending the results to a dedicated logging file. Apache error logs aren't a great place for audit-style logging, since there's so much other (Apache-specific) stuff in there. if you use the logging module, you'll have code the looks something like this to set things up (maybe in your settings file): LOGGER = logging.handlers.FileHandler(...) LOGGER.setFormatter(logging.Formatter('%(asctime)-24s %(name)-18s %(levelname)-8s %(message)s')) LOG_LEVEL = logging.DEBUG and then you can use it in your code like so: import logging log = logging.getLogger() log.log(logging.INFO, u"%s" % request.user) A couple of tests I did here suggest that will work fine with non-ASCII data, although I couldn't repeat your original problem initially here, either (I don't have time to play around setting up a mod_wsgi test project for this right now). > 2- If I test the same code in the djang shell, the two boxes behave > the same. > > To sum up, my main problem is error raising print statements on > production server, causing Http 500 responses, while they perfectly > work on the local box. And I can't remove the print statements due to > logging requirements. > > What's the proper way of 'printing' a model object? > print u"%s" % request.user > raises UnicodeEncodeError as I previously mentioned. The problem with that line is the "print" and the output encoding. The correct way to get a string form is definitely u"%s" % request.user (or even unicode(request.user)). The difficulty here apparently comes from using "print" to do logging in your particular setup. Consider switching to the logging module. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---