Saturday, October 20, 2012

how to use a customized logging formatter class

I have written this custom formatter which inherits from logging.Formatter, how can I configure logging settings so that I can use this for a logger. I see the example in docs where I can update the formatter string but dont know how to link a class to do that.

class UniqueRequestIdFormatter(logging.Formatter):
    def format(self, record):
        record.message = record.msg % record.args
        record.asctime = self.formatTime(record)
        format = u'%s %s %-10s %s +%s %s' % (
        record.levelname,
            record.request.META['REMOTE_ADDR'],
            record.request.user.id if record.request.user.id else record.request.user,
            record.asctime,
            record.request.method,
            record.request.path,
            record.message
            ).encode('utf-8')
        pprint.pprint(record.__dict__)
        return format % record.__dict__

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/i-q8eEVHIpMJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate