Reputation: 7384
Whenever I visit my django admin I see this in my logs
[2018-08-13 15:41:55 +0800] [95] [DEBUG] GET /admin/login/
172.18.0.4 - - [13/Aug/2018:15:41:55 +0800] "GET /admin/login/?next=/admin/ HTTP/1.0" 200 1859 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
[2018-08-13 15:41:55 +0800] [95] [DEBUG] Closing connection.
I want to manipulate the line which displays 172.18.0.4 - - [13/Aug/2018:15:41:55 +0800] "GET /admin/login/?next=/admin/ HTTP/1.0" 200 1859 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6)
. How can I change the format of that part?
UPDATE: I got it now, It was a gunicorn logs. I have to change the access_log configuration to solve my problem
Upvotes: 0
Views: 67
Reputation: 2483
You should check Django docs | Logging. There are specified some simple and few complex configurations of loging in django. This also answers your question about printing to stdout.
Try adding for example to your base settings.py
following lines and restart the server.
LOGGING = {
'version': 1,
'formatters': {
'simple': {
'format': 'LOG: {levelname} {message}',
'style': '{',
},
},
'handlers': {
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
},
'loggers': {
'django': {
'handlers': ['console'],
'propagate': True,
},
}
}
You should see the difference in the console. Check examples in the link I've provided. This should definitely work.
Upvotes: 1