Monday, January 23, 2017

Writing a custome Django Log Formatter.

Hi all,

I have a small issue with writing a Custom Log Formatter.

By default: log_format = '%(asctime)s %(module)s %(levelname)-8s- %(message)s'

This is the Log formatter being used.
But only in a few cases or rather in a few modules, i would like to include for ex: "some_id" as a seperator in the Logs.
Intended : log_format = '%(asctime)s %(module)s %(levelname)-8s- %(some_id)s %(message)s'

But this always raises a Key Error and i would not want to change each and every existing log and manually add the new log.

Is there a way to write this Custom Log format.???

I did try this:
log_format = '%(asctime)s %(module)s %(levelname)-8s- %(some_id)s %(message)s' %{'some_id': id}

This gives a Key Error "
asctime "

And During Logging setup, i setup the Logging :

formatter = logging.Formatter(data.get('logging.log_format', None))
file_handler.setFormatter(formatter)



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3275bad0-405b-4bbf-afe7-d0eeb1feb77f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment