42👍
From Python logging module documentation:
-
asctime:
%(asctime)s
Human-readable time when theLogRecord
was created. By default this is of the form ‘2003-07-08 16:49:45,896’ (the numbers after the comma are millisecond portion of the time). -
created:
%(created)f
Time when theLogRecord
was created (as returned bytime.time()
). -
filename:
%(filename)s
Filename portion of pathname. -
funcName:
%(funcName)s
Name of function containing the logging call. -
levelname:
%(levelname)s
Text logging level for the message (‘DEBUG’, ‘INFO’, ‘WARNING’, ‘ERROR’, ‘CRITICAL’). -
levelno:
%(levelno)s
Numeric logging level for the message (DEBUG, INFO, WARNING, ERROR, CRITICAL). -
lineno:
%(lineno)d
Source line number where the logging call was issued (if available). -
module:
%(module)s
Module (name portion of filename). -
msecs:
%(msecs)d
Millisecond portion of the time when theLogRecord
was created. -
message:
%(message)s
The logged message, computed asmsg % args
. This is set whenFormatter.format()
is invoked. -
name:
%(name)s
Name of the logger used to log the call. -
pathname:
%(pathname)s
Full pathname of the source file where the logging call was issued (if available). -
process:
%(process)d
Process ID (if available). -
processName:
%(processName)s
Process name (if available). -
relativeCreated:
%(relativeCreated)d
Time in milliseconds when theLogRecord
was created, relative to the time the logging module was loaded. -
thread:
%(thread)d
Thread ID (if available). -
threadName:
%(threadName)s
Thread name (if available).
The following arguments are also available to Formatter.format()
, although they are not intended to be included in the format string:
-
args:
The tuple of arguments merged into msg to produce message. -
exc_info:
Exception tuple (à lasys.exc_info
) or, if no exception has occurred,None
. -
msg:
The format string passed in the original logging call. Merged with args to produce message, or an arbitrary object (see Using arbitrary objects as messages).
4👍
Step1. Edit your settings.py file
$ cd mysite
$ vim mysite/settings.py
'formatters': {
'simple': {
'format': '%(levelname)s %(asctime)s %(name)s.%(funcName)s:%(lineno)s- %(message)s'
},
},
Step2. You should use logger in your coding like this:
import logging
logger = logging.getLogger(__name__)
def fn1() {
logger.info('great!')
logger.info(__name__)
}
Hope that helps you!
- Adding forgot-password feature to Django admin site
- Django: why are Django model fields class attributes?
- 'QuerySet' object has no attribute ERROR, trying to get related data on ManyToMany fields