Reputation: 2310
Logging sql queries is useful for debugging but in some cases, it's useless to log the whole query, especially for big inserts. In this case, display only first N caracters would be enough.
Is there a simple way to truncate sql queries when they are logged ?
Upvotes: 2
Views: 246
Reputation: 2310
It's quite simple actually:
in settings.py, let's say your logger is based on a handler which formatter is named 'simple'.
'formatters': { ... 'simple': { 'format': '%(asctime)s %(message).150s' }, ... },
The message will now be truncated to the first 150 caracters. Playing with handlers will allow you to specify this parameter per each logger. Thanks Python!
Upvotes: 2