Linux cpanel.rrshost.in 5.15.0-25-generic #25-Ubuntu SMP Wed Mar 30 15:54:22 UTC 2022 x86_64
Apache
: 109.123.238.221 | : 172.69.17.14
128 Domain
8.2.28
aev999
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
HASH IDENTIFIER
README
+ Create Folder
+ Create File
/
usr /
share /
doc /
python2.7 /
html /
library /
[ HOME SHELL ]
Name
Size
Permission
Action
2to3.html
63.71
KB
-rw-r--r--
__builtin__.html
11.79
KB
-rw-r--r--
__future__.html
15.58
KB
-rw-r--r--
__main__.html
8.33
KB
-rw-r--r--
_winreg.html
73.99
KB
-rw-r--r--
abc.html
26.82
KB
-rw-r--r--
aepack.html
15.47
KB
-rw-r--r--
aetools.html
18.79
KB
-rw-r--r--
aetypes.html
27.08
KB
-rw-r--r--
aifc.html
29.59
KB
-rw-r--r--
al.html
22.13
KB
-rw-r--r--
allos.html
35.48
KB
-rw-r--r--
anydbm.html
19.31
KB
-rw-r--r--
archiving.html
10.64
KB
-rw-r--r--
argparse.html
269.59
KB
-rw-r--r--
array.html
35.35
KB
-rw-r--r--
ast.html
42.42
KB
-rw-r--r--
asynchat.html
35.84
KB
-rw-r--r--
asyncore.html
43.22
KB
-rw-r--r--
atexit.html
19.23
KB
-rw-r--r--
audioop.html
41.32
KB
-rw-r--r--
autogil.html
9.77
KB
-rw-r--r--
base64.html
24.8
KB
-rw-r--r--
basehttpserver.html
40.6
KB
-rw-r--r--
bastion.html
13.02
KB
-rw-r--r--
bdb.html
50.06
KB
-rw-r--r--
binascii.html
26.64
KB
-rw-r--r--
binhex.html
12.66
KB
-rw-r--r--
bisect.html
28.52
KB
-rw-r--r--
bsddb.html
32.02
KB
-rw-r--r--
bz2.html
31.92
KB
-rw-r--r--
calendar.html
50.16
KB
-rw-r--r--
carbon.html
54.14
KB
-rw-r--r--
cd.html
35.24
KB
-rw-r--r--
cgi.html
58.4
KB
-rw-r--r--
cgihttpserver.html
15.12
KB
-rw-r--r--
cgitb.html
13.5
KB
-rw-r--r--
chunk.html
17.41
KB
-rw-r--r--
cmath.html
32.41
KB
-rw-r--r--
cmd.html
32.69
KB
-rw-r--r--
code.html
28.92
KB
-rw-r--r--
codecs.html
125.92
KB
-rw-r--r--
codeop.html
16.42
KB
-rw-r--r--
collections.html
150.36
KB
-rw-r--r--
colorpicker.html
9.02
KB
-rw-r--r--
colorsys.html
14.38
KB
-rw-r--r--
commands.html
16.63
KB
-rw-r--r--
compileall.html
21.18
KB
-rw-r--r--
compiler.html
78.14
KB
-rw-r--r--
configparser.html
73.92
KB
-rw-r--r--
constants.html
14.68
KB
-rw-r--r--
contextlib.html
22.91
KB
-rw-r--r--
cookie.html
45.38
KB
-rw-r--r--
cookielib.html
102.78
KB
-rw-r--r--
copy.html
14.21
KB
-rw-r--r--
copy_reg.html
15.82
KB
-rw-r--r--
crypt.html
11.62
KB
-rw-r--r--
crypto.html
8.35
KB
-rw-r--r--
csv.html
82.79
KB
-rw-r--r--
ctypes.html
280.57
KB
-rw-r--r--
curses.ascii.html
28.97
KB
-rw-r--r--
curses.html
200.94
KB
-rw-r--r--
curses.panel.html
18.43
KB
-rw-r--r--
custominterp.html
8.59
KB
-rw-r--r--
datatypes.html
18.84
KB
-rw-r--r--
datetime.html
261.02
KB
-rw-r--r--
dbhash.html
18.4
KB
-rw-r--r--
dbm.html
14.75
KB
-rw-r--r--
debug.html
11.28
KB
-rw-r--r--
decimal.html
239.14
KB
-rw-r--r--
development.html
15.27
KB
-rw-r--r--
difflib.html
96.93
KB
-rw-r--r--
dircache.html
13.66
KB
-rw-r--r--
dis.html
96.52
KB
-rw-r--r--
distribution.html
8.27
KB
-rw-r--r--
distutils.html
10.97
KB
-rw-r--r--
dl.html
19.27
KB
-rw-r--r--
doctest.html
193.18
KB
-rw-r--r--
docxmlrpcserver.html
20.02
KB
-rw-r--r--
dumbdbm.html
16.74
KB
-rw-r--r--
dummy_thread.html
11.04
KB
-rw-r--r--
dummy_threading.html
9.96
KB
-rw-r--r--
easydialogs.html
38.83
KB
-rw-r--r--
email-examples.html
47.2
KB
-rw-r--r--
email.charset.html
32.45
KB
-rw-r--r--
email.encoders.html
14.09
KB
-rw-r--r--
email.errors.html
19.2
KB
-rw-r--r--
email.generator.html
24.78
KB
-rw-r--r--
email.header.html
31.12
KB
-rw-r--r--
email.html
55.3
KB
-rw-r--r--
email.iterators.html
14.22
KB
-rw-r--r--
email.message.html
74.91
KB
-rw-r--r--
email.mime.html
34.51
KB
-rw-r--r--
email.parser.html
37.09
KB
-rw-r--r--
email.utils.html
30.04
KB
-rw-r--r--
ensurepip.html
20.21
KB
-rw-r--r--
errno.html
52.31
KB
-rw-r--r--
exceptions.html
73.4
KB
-rw-r--r--
fcntl.html
27.85
KB
-rw-r--r--
filecmp.html
26.49
KB
-rw-r--r--
fileformats.html
10.21
KB
-rw-r--r--
fileinput.html
29.36
KB
-rw-r--r--
filesys.html
11.55
KB
-rw-r--r--
fl.html
71.58
KB
-rw-r--r--
fm.html
15
KB
-rw-r--r--
fnmatch.html
17.78
KB
-rw-r--r--
formatter.html
43.91
KB
-rw-r--r--
fpectl.html
17.84
KB
-rw-r--r--
fpformat.html
12.65
KB
-rw-r--r--
fractions.html
27.17
KB
-rw-r--r--
framework.html
44.24
KB
-rw-r--r--
frameworks.html
8.11
KB
-rw-r--r--
ftplib.html
56.56
KB
-rw-r--r--
functions.html
216.84
KB
-rw-r--r--
functools.html
31.06
KB
-rw-r--r--
future_builtins.html
15.9
KB
-rw-r--r--
gc.html
30.74
KB
-rw-r--r--
gdbm.html
19.35
KB
-rw-r--r--
gensuitemodule.html
14.54
KB
-rw-r--r--
getopt.html
26.56
KB
-rw-r--r--
getpass.html
12.5
KB
-rw-r--r--
gettext.html
91.32
KB
-rw-r--r--
gl.html
26.71
KB
-rw-r--r--
glob.html
15.42
KB
-rw-r--r--
grp.html
12.33
KB
-rw-r--r--
gzip.html
21.95
KB
-rw-r--r--
hashlib.html
27.4
KB
-rw-r--r--
heapq.html
36.72
KB
-rw-r--r--
hmac.html
15.97
KB
-rw-r--r--
hotshot.html
22.69
KB
-rw-r--r--
htmllib.html
29.9
KB
-rw-r--r--
htmlparser.html
45.11
KB
-rw-r--r--
httplib.html
78.55
KB
-rw-r--r--
i18n.html
10.61
KB
-rw-r--r--
ic.html
22.03
KB
-rw-r--r--
idle.html
45.74
KB
-rw-r--r--
imageop.html
20.94
KB
-rw-r--r--
imaplib.html
69.9
KB
-rw-r--r--
imgfile.html
14.91
KB
-rw-r--r--
imghdr.html
13.43
KB
-rw-r--r--
imp.html
41.48
KB
-rw-r--r--
importlib.html
10.27
KB
-rw-r--r--
imputil.html
36.11
KB
-rw-r--r--
index.html
82.54
KB
-rw-r--r--
inspect.html
64.31
KB
-rw-r--r--
internet.html
26.77
KB
-rw-r--r--
intro.html
9.76
KB
-rw-r--r--
io.html
122.3
KB
-rw-r--r--
ipc.html
17.18
KB
-rw-r--r--
itertools.html
129.91
KB
-rw-r--r--
jpeg.html
15.36
KB
-rw-r--r--
json.html
79.09
KB
-rw-r--r--
keyword.html
9.27
KB
-rw-r--r--
language.html
12.35
KB
-rw-r--r--
linecache.html
12.7
KB
-rw-r--r--
locale.html
68.54
KB
-rw-r--r--
logging.config.html
82.23
KB
-rw-r--r--
logging.handlers.html
91.96
KB
-rw-r--r--
logging.html
123.15
KB
-rw-r--r--
mac.html
24.49
KB
-rw-r--r--
macos.html
18.51
KB
-rw-r--r--
macosa.html
14.55
KB
-rw-r--r--
macostools.html
19.67
KB
-rw-r--r--
macpath.html
9.19
KB
-rw-r--r--
mailbox.html
185.53
KB
-rw-r--r--
mailcap.html
15.3
KB
-rw-r--r--
markup.html
20.37
KB
-rw-r--r--
marshal.html
19.88
KB
-rw-r--r--
math.html
50.52
KB
-rw-r--r--
md5.html
16.65
KB
-rw-r--r--
mhlib.html
30.04
KB
-rw-r--r--
mimetools.html
23.84
KB
-rw-r--r--
mimetypes.html
35.82
KB
-rw-r--r--
mimewriter.html
18.19
KB
-rw-r--r--
mimify.html
16.96
KB
-rw-r--r--
miniaeframe.html
14.5
KB
-rw-r--r--
misc.html
7.77
KB
-rw-r--r--
mm.html
10.19
KB
-rw-r--r--
mmap.html
33.52
KB
-rw-r--r--
modulefinder.html
19.85
KB
-rw-r--r--
modules.html
9.68
KB
-rw-r--r--
msilib.html
72.78
KB
-rw-r--r--
msvcrt.html
24.1
KB
-rw-r--r--
multifile.html
28.82
KB
-rw-r--r--
multiprocessing.html
423.97
KB
-rw-r--r--
mutex.html
13.56
KB
-rw-r--r--
netdata.html
19.28
KB
-rw-r--r--
netrc.html
15.51
KB
-rw-r--r--
new.html
16.1
KB
-rw-r--r--
nis.html
13.19
KB
-rw-r--r--
nntplib.html
51.08
KB
-rw-r--r--
numbers.html
40.91
KB
-rw-r--r--
numeric.html
14.85
KB
-rw-r--r--
operator.html
118.32
KB
-rw-r--r--
optparse.html
251.08
KB
-rw-r--r--
os.html
270.49
KB
-rw-r--r--
os.path.html
48.87
KB
-rw-r--r--
ossaudiodev.html
49.79
KB
-rw-r--r--
othergui.html
9.98
KB
-rw-r--r--
parser.html
44.52
KB
-rw-r--r--
pdb.html
41.44
KB
-rw-r--r--
persistence.html
16.25
KB
-rw-r--r--
pickle.html
107.94
KB
-rw-r--r--
pickletools.html
13.21
KB
-rw-r--r--
pipes.html
21.85
KB
-rw-r--r--
pkgutil.html
30.59
KB
-rw-r--r--
platform.html
40.14
KB
-rw-r--r--
plistlib.html
20.96
KB
-rw-r--r--
popen2.html
30.13
KB
-rw-r--r--
poplib.html
27.93
KB
-rw-r--r--
posix.html
17.27
KB
-rw-r--r--
posixfile.html
23.68
KB
-rw-r--r--
pprint.html
36.42
KB
-rw-r--r--
profile.html
76.65
KB
-rw-r--r--
pty.html
11.42
KB
-rw-r--r--
pwd.html
13.53
KB
-rw-r--r--
py_compile.html
13.33
KB
-rw-r--r--
pyclbr.html
18.14
KB
-rw-r--r--
pydoc.html
14.33
KB
-rw-r--r--
pyexpat.html
93.28
KB
-rw-r--r--
python.html
13.53
KB
-rw-r--r--
queue.html
29.64
KB
-rw-r--r--
quopri.html
14.5
KB
-rw-r--r--
random.html
47.78
KB
-rw-r--r--
re.html
163.11
KB
-rw-r--r--
readline.html
41.2
KB
-rw-r--r--
repr.html
24.57
KB
-rw-r--r--
resource.html
30.86
KB
-rw-r--r--
restricted.html
12.69
KB
-rw-r--r--
rexec.html
43.59
KB
-rw-r--r--
rfc822.html
51.25
KB
-rw-r--r--
rlcompleter.html
15.29
KB
-rw-r--r--
robotparser.html
15.01
KB
-rw-r--r--
runpy.html
23.55
KB
-rw-r--r--
sched.html
21.76
KB
-rw-r--r--
scrolledtext.html
10.67
KB
-rw-r--r--
select.html
50.17
KB
-rw-r--r--
sets.html
39.92
KB
-rw-r--r--
sgi.html
11.09
KB
-rw-r--r--
sgmllib.html
38.77
KB
-rw-r--r--
sha.html
14.55
KB
-rw-r--r--
shelve.html
32.93
KB
-rw-r--r--
shlex.html
38.43
KB
-rw-r--r--
shutil.html
49.49
KB
-rw-r--r--
signal.html
36.52
KB
-rw-r--r--
simplehttpserver.html
21.57
KB
-rw-r--r--
simplexmlrpcserver.html
40.41
KB
-rw-r--r--
site.html
29
KB
-rw-r--r--
smtpd.html
15.64
KB
-rw-r--r--
smtplib.html
51.86
KB
-rw-r--r--
sndhdr.html
12.05
KB
-rw-r--r--
socket.html
126.94
KB
-rw-r--r--
socketserver.html
81.38
KB
-rw-r--r--
someos.html
17.09
KB
-rw-r--r--
spwd.html
12.25
KB
-rw-r--r--
sqlite3.html
154.12
KB
-rw-r--r--
ssl.html
214.5
KB
-rw-r--r--
stat.html
41.11
KB
-rw-r--r--
statvfs.html
13.24
KB
-rw-r--r--
stdtypes.html
309.83
KB
-rw-r--r--
string.html
129.58
KB
-rw-r--r--
stringio.html
21.1
KB
-rw-r--r--
stringprep.html
21.4
KB
-rw-r--r--
strings.html
16.42
KB
-rw-r--r--
struct.html
47.68
KB
-rw-r--r--
subprocess.html
117
KB
-rw-r--r--
sun.html
7.83
KB
-rw-r--r--
sunau.html
35.43
KB
-rw-r--r--
sunaudio.html
21.05
KB
-rw-r--r--
symbol.html
9.06
KB
-rw-r--r--
symtable.html
29.03
KB
-rw-r--r--
sys.html
118.12
KB
-rw-r--r--
sysconfig.html
28.8
KB
-rw-r--r--
syslog.html
21.29
KB
-rw-r--r--
tabnanny.html
12.78
KB
-rw-r--r--
tarfile.html
99.54
KB
-rw-r--r--
telnetlib.html
30.46
KB
-rw-r--r--
tempfile.html
35.02
KB
-rw-r--r--
termios.html
19.22
KB
-rw-r--r--
test.html
61.42
KB
-rw-r--r--
textwrap.html
32.28
KB
-rw-r--r--
thread.html
22.67
KB
-rw-r--r--
threading.html
92.04
KB
-rw-r--r--
time.html
65.55
KB
-rw-r--r--
timeit.html
44.38
KB
-rw-r--r--
tix.html
56.73
KB
-rw-r--r--
tk.html
26.76
KB
-rw-r--r--
tkinter.html
86.67
KB
-rw-r--r--
token.html
27.31
KB
-rw-r--r--
tokenize.html
21.69
KB
-rw-r--r--
trace.html
33.91
KB
-rw-r--r--
traceback.html
44.22
KB
-rw-r--r--
ttk.html
123.83
KB
-rw-r--r--
tty.html
10.95
KB
-rw-r--r--
turtle.html
246.17
KB
-rw-r--r--
types.html
33.66
KB
-rw-r--r--
undoc.html
25.54
KB
-rw-r--r--
unicodedata.html
22.64
KB
-rw-r--r--
unittest.html
246.75
KB
-rw-r--r--
unix.html
11.9
KB
-rw-r--r--
urllib.html
71.61
KB
-rw-r--r--
urllib2.html
128.77
KB
-rw-r--r--
urlparse.html
49.04
KB
-rw-r--r--
user.html
13.41
KB
-rw-r--r--
userdict.html
32.96
KB
-rw-r--r--
uu.html
13.25
KB
-rw-r--r--
uuid.html
33.55
KB
-rw-r--r--
warnings.html
51.86
KB
-rw-r--r--
wave.html
29.08
KB
-rw-r--r--
weakref.html
41.14
KB
-rw-r--r--
webbrowser.html
29.53
KB
-rw-r--r--
whichdb.html
10.44
KB
-rw-r--r--
windows.html
10.37
KB
-rw-r--r--
winsound.html
22.56
KB
-rw-r--r--
wsgiref.html
94.38
KB
-rw-r--r--
xdrlib.html
38.05
KB
-rw-r--r--
xml.dom.html
110.39
KB
-rw-r--r--
xml.dom.minidom.html
45.23
KB
-rw-r--r--
xml.dom.pulldom.html
16.32
KB
-rw-r--r--
xml.etree.elementtree.html
124.2
KB
-rw-r--r--
xml.html
18.76
KB
-rw-r--r--
xml.sax.handler.html
47.5
KB
-rw-r--r--
xml.sax.html
26.04
KB
-rw-r--r--
xml.sax.reader.html
51.4
KB
-rw-r--r--
xml.sax.utils.html
18.11
KB
-rw-r--r--
xmlrpclib.html
71.79
KB
-rw-r--r--
zipfile.html
67.26
KB
-rw-r--r--
zipimport.html
24.32
KB
-rw-r--r--
zlib.html
34.41
KB
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : logging.html
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> <title>15.7. logging — Logging facility for Python — Python 2.7.18 documentation</title> <link rel="stylesheet" type="text/css" href="../_static/pygments.css" /> <link rel="stylesheet" type="text/css" href="../_static/classic.css" /> <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script> <script src="../_static/jquery.js"></script> <script src="../_static/underscore.js"></script> <script src="../_static/doctools.js"></script> <script src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 2.7.18 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="next" title="15.8. logging.config — Logging configuration" href="logging.config.html" /> <link rel="prev" title="15.6. getopt — C-style parser for command line options" href="getopt.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <link rel="canonical" href="file:///usr/share/doc/python2.7/html/library/logging.html" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head><body> <div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;"> This document is for an old version of Python that is <a href="https://devguide.python.org/devcycle/#end-of-life-branches">no longer supported</a>. You should install the python3 and python3-doc packages and read the <a href="file:///usr/share/doc/python3-doc/html/library/logging.html"> Python documentation for the Python3 version packaged in this release</a>. </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="logging.config.html" title="15.8. logging.config — Logging configuration" accesskey="N">next</a> |</li> <li class="right" > <a href="getopt.html" title="15.6. getopt — C-style parser for command line options" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.18 documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="allos.html" accesskey="U"><span class="section-number">15. </span>Generic Operating System Services</a> »</li> <li class="nav-item nav-item-this"><a href=""><span class="section-number">15.7. </span><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code> — Logging facility for Python</a></li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <section id="module-logging"> <span id="logging-logging-facility-for-python"></span><h1><span class="section-number">15.7. </span><a class="reference internal" href="#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> — Logging facility for Python<a class="headerlink" href="#module-logging" title="Permalink to this headline">¶</a></h1> <aside class="sidebar" id="index-0"> <p class="sidebar-title">Important</p> <p>This page contains the API reference information. For tutorial information and discussion of more advanced topics, see</p> <ul class="simple"> <li><p><a class="reference internal" href="../howto/logging.html#logging-basic-tutorial"><span class="std std-ref">Basic Tutorial</span></a></p></li> <li><p><a class="reference internal" href="../howto/logging.html#logging-advanced-tutorial"><span class="std std-ref">Advanced Tutorial</span></a></p></li> <li><p><a class="reference internal" href="../howto/logging-cookbook.html#logging-cookbook"><span class="std std-ref">Logging Cookbook</span></a></p></li> </ul> </aside> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/2.7/Lib/logging/__init__.py">Lib/logging/__init__.py</a></p> <hr class="docutils" /> <div class="versionadded"> <p><span class="versionmodified added">New in version 2.3.</span></p> </div> <p>This module defines functions and classes which implement a flexible event logging system for applications and libraries.</p> <p>The key benefit of having the logging API provided by a standard library module is that all Python modules can participate in logging, so your application log can include your own messages integrated with messages from third-party modules.</p> <p>The module provides a lot of functionality and flexibility. If you are unfamiliar with logging, the best way to get to grips with it is to see the tutorials (see the links on the right).</p> <p>The basic classes defined by the module, together with their functions, are listed below.</p> <ul class="simple"> <li><p>Loggers expose the interface that application code directly uses.</p></li> <li><p>Handlers send the log records (created by loggers) to the appropriate destination.</p></li> <li><p>Filters provide a finer grained facility for determining which log records to output.</p></li> <li><p>Formatters specify the layout of log records in the final output.</p></li> </ul> <section id="logger-objects"> <span id="logger"></span><h2><span class="section-number">15.7.1. </span>Logger Objects<a class="headerlink" href="#logger-objects" title="Permalink to this headline">¶</a></h2> <p>Loggers have the following attributes and methods. Note that Loggers are never instantiated directly, but always through the module-level function <code class="docutils literal notranslate"><span class="pre">logging.getLogger(name)</span></code>. Multiple calls to <a class="reference internal" href="#logging.getLogger" title="logging.getLogger"><code class="xref py py-func docutils literal notranslate"><span class="pre">getLogger()</span></code></a> with the same name will always return a reference to the same Logger object.</p> <p>The <code class="docutils literal notranslate"><span class="pre">name</span></code> is potentially a period-separated hierarchical value, like <code class="docutils literal notranslate"><span class="pre">foo.bar.baz</span></code> (though it could also be just plain <code class="docutils literal notranslate"><span class="pre">foo</span></code>, for example). Loggers that are further down in the hierarchical list are children of loggers higher up in the list. For example, given a logger with a name of <code class="docutils literal notranslate"><span class="pre">foo</span></code>, loggers with names of <code class="docutils literal notranslate"><span class="pre">foo.bar</span></code>, <code class="docutils literal notranslate"><span class="pre">foo.bar.baz</span></code>, and <code class="docutils literal notranslate"><span class="pre">foo.bam</span></code> are all descendants of <code class="docutils literal notranslate"><span class="pre">foo</span></code>. The logger name hierarchy is analogous to the Python package hierarchy, and identical to it if you organise your loggers on a per-module basis using the recommended construction <code class="docutils literal notranslate"><span class="pre">logging.getLogger(__name__)</span></code>. That’s because in a module, <code class="docutils literal notranslate"><span class="pre">__name__</span></code> is the module’s name in the Python package namespace.</p> <dl class="py class"> <dt class="sig sig-object py" id="logging.Logger"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">Logger</span></span><a class="headerlink" href="#logging.Logger" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="logging.Logger.propagate"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">propagate</span></span><a class="headerlink" href="#logging.Logger.propagate" title="Permalink to this definition">¶</a></dt> <dd><p>If this evaluates to true, events logged to this logger will be passed to the handlers of higher level (ancestor) loggers, in addition to any handlers attached to this logger. Messages are passed directly to the ancestor loggers’ handlers - neither the level nor filters of the ancestor loggers in question are considered.</p> <p>If this evaluates to false, logging messages are not passed to the handlers of ancestor loggers.</p> <p>The constructor sets this attribute to <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>If you attach a handler to a logger <em>and</em> one or more of its ancestors, it may emit the same record multiple times. In general, you should not need to attach a handler to more than one logger - if you just attach it to the appropriate logger which is highest in the logger hierarchy, then it will see all events logged by all descendant loggers, provided that their propagate setting is left set to <code class="docutils literal notranslate"><span class="pre">True</span></code>. A common scenario is to attach handlers only to the root logger, and to let propagation take care of the rest.</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.setLevel"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">setLevel</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">level</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.setLevel" title="Permalink to this definition">¶</a></dt> <dd><p>Sets the threshold for this logger to <em>level</em>. Logging messages which are less severe than <em>level</em> will be ignored. When a logger is created, the level is set to <code class="xref py py-const docutils literal notranslate"><span class="pre">NOTSET</span></code> (which causes all messages to be processed when the logger is the root logger, or delegation to the parent when the logger is a non-root logger). Note that the root logger is created with level <code class="xref py py-const docutils literal notranslate"><span class="pre">WARNING</span></code>.</p> <p>The term ‘delegation to the parent’ means that if a logger has a level of NOTSET, its chain of ancestor loggers is traversed until either an ancestor with a level other than NOTSET is found, or the root is reached.</p> <p>If an ancestor is found with a level other than NOTSET, then that ancestor’s level is treated as the effective level of the logger where the ancestor search began, and is used to determine how a logging event is handled.</p> <p>If the root is reached, and it has a level of NOTSET, then all messages will be processed. Otherwise, the root’s level will be used as the effective level.</p> <p>See <a class="reference internal" href="#levels"><span class="std std-ref">Logging Levels</span></a> for a list of levels.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.isEnabledFor"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">isEnabledFor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">lvl</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.isEnabledFor" title="Permalink to this definition">¶</a></dt> <dd><p>Indicates if a message of severity <em>lvl</em> would be processed by this logger. This method checks first the module-level level set by <code class="docutils literal notranslate"><span class="pre">logging.disable(lvl)</span></code> and then the logger’s effective level as determined by <a class="reference internal" href="#logging.Logger.getEffectiveLevel" title="logging.Logger.getEffectiveLevel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getEffectiveLevel()</span></code></a>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.getEffectiveLevel"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">getEffectiveLevel</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.getEffectiveLevel" title="Permalink to this definition">¶</a></dt> <dd><p>Indicates the effective level for this logger. If a value other than <code class="xref py py-const docutils literal notranslate"><span class="pre">NOTSET</span></code> has been set using <a class="reference internal" href="#logging.Logger.setLevel" title="logging.Logger.setLevel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setLevel()</span></code></a>, it is returned. Otherwise, the hierarchy is traversed towards the root until a value other than <code class="xref py py-const docutils literal notranslate"><span class="pre">NOTSET</span></code> is found, and that value is returned. The value returned is an integer, typically one of <code class="xref py py-const docutils literal notranslate"><span class="pre">logging.DEBUG</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">logging.INFO</span></code> etc.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.getChild"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">getChild</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">suffix</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.getChild" title="Permalink to this definition">¶</a></dt> <dd><p>Returns a logger which is a descendant to this logger, as determined by the suffix. Thus, <code class="docutils literal notranslate"><span class="pre">logging.getLogger('abc').getChild('def.ghi')</span></code> would return the same logger as would be returned by <code class="docutils literal notranslate"><span class="pre">logging.getLogger('abc.def.ghi')</span></code>. This is a convenience method, useful when the parent logger is named using e.g. <code class="docutils literal notranslate"><span class="pre">__name__</span></code> rather than a literal string.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 2.7.</span></p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.debug"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">debug</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.debug" title="Permalink to this definition">¶</a></dt> <dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">DEBUG</span></code> on this logger. The <em>msg</em> is the message format string, and the <em>args</em> are the arguments which are merged into <em>msg</em> using the string formatting operator. (Note that this means that you can use keywords in the format string, together with a single dictionary argument.)</p> <p>There are two keyword arguments in <em>kwargs</em> which are inspected: <em>exc_info</em> which, if it does not evaluate as false, causes exception information to be added to the logging message. If an exception tuple (in the format returned by <a class="reference internal" href="sys.html#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exc_info()</span></code></a>) is provided, it is used; otherwise, <a class="reference internal" href="sys.html#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exc_info()</span></code></a> is called to get the exception information.</p> <p>The second keyword argument is <em>extra</em> which can be used to pass a dictionary which is used to populate the __dict__ of the LogRecord created for the logging event with user-defined attributes. These custom attributes can then be used as you like. For example, they could be incorporated into logged messages. For example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">FORMAT</span> <span class="o">=</span> <span class="s1">'</span><span class="si">%(asctime)-15s</span><span class="s1"> </span><span class="si">%(clientip)s</span><span class="s1"> </span><span class="si">%(user)-8s</span><span class="s1"> </span><span class="si">%(message)s</span><span class="s1">'</span> <span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="nb">format</span><span class="o">=</span><span class="n">FORMAT</span><span class="p">)</span> <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'clientip'</span><span class="p">:</span> <span class="s1">'192.168.0.1'</span><span class="p">,</span> <span class="s1">'user'</span><span class="p">:</span> <span class="s1">'fbloggs'</span><span class="p">}</span> <span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s1">'tcpserver'</span><span class="p">)</span> <span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">'Protocol problem: </span><span class="si">%s</span><span class="s1">'</span><span class="p">,</span> <span class="s1">'connection reset'</span><span class="p">,</span> <span class="n">extra</span><span class="o">=</span><span class="n">d</span><span class="p">)</span> </pre></div> </div> <p>would print something like</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="mi">2006</span><span class="o">-</span><span class="mi">02</span><span class="o">-</span><span class="mi">08</span> <span class="mi">22</span><span class="p">:</span><span class="mi">20</span><span class="p">:</span><span class="mi">02</span><span class="p">,</span><span class="mi">165</span> <span class="mf">192.168.0.1</span> <span class="n">fbloggs</span> <span class="n">Protocol</span> <span class="n">problem</span><span class="p">:</span> <span class="n">connection</span> <span class="n">reset</span> </pre></div> </div> <p>The keys in the dictionary passed in <em>extra</em> should not clash with the keys used by the logging system. (See the <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> documentation for more information on which keys are used by the logging system.)</p> <p>If you choose to use these attributes in logged messages, you need to exercise some care. In the above example, for instance, the <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> has been set up with a format string which expects ‘clientip’ and ‘user’ in the attribute dictionary of the LogRecord. If these are missing, the message will not be logged because a string formatting exception will occur. So in this case, you always need to pass the <em>extra</em> dictionary with these keys.</p> <p>While this might be annoying, this feature is intended for use in specialized circumstances, such as multi-threaded servers where the same code executes in many contexts, and interesting conditions which arise are dependent on this context (such as remote client IP address and authenticated user name, in the above example). In such circumstances, it is likely that specialized <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a>s would be used with particular <code class="xref py py-class docutils literal notranslate"><span class="pre">Handler</span></code>s.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.info"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">info</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.info" title="Permalink to this definition">¶</a></dt> <dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">INFO</span></code> on this logger. The arguments are interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.warning"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">warning</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.warning" title="Permalink to this definition">¶</a></dt> <dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">WARNING</span></code> on this logger. The arguments are interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.error"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">error</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.error" title="Permalink to this definition">¶</a></dt> <dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">ERROR</span></code> on this logger. The arguments are interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.critical"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">critical</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.critical" title="Permalink to this definition">¶</a></dt> <dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">CRITICAL</span></code> on this logger. The arguments are interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.log"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">log</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">lvl</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.log" title="Permalink to this definition">¶</a></dt> <dd><p>Logs a message with integer level <em>lvl</em> on this logger. The other arguments are interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.exception"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">exception</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.exception" title="Permalink to this definition">¶</a></dt> <dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">ERROR</span></code> on this logger. The arguments are interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>, except that any passed <em>exc_info</em> is not inspected. Exception info is always added to the logging message. This method should only be called from an exception handler.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.addFilter"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">addFilter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filter</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.addFilter" title="Permalink to this definition">¶</a></dt> <dd><p>Adds the specified filter <em>filter</em> to this logger.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.removeFilter"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">removeFilter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filter</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.removeFilter" title="Permalink to this definition">¶</a></dt> <dd><p>Removes the specified filter <em>filter</em> from this logger.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.filter"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">filter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.filter" title="Permalink to this definition">¶</a></dt> <dd><p>Applies this logger’s filters to the record and returns a true value if the record is to be processed. The filters are consulted in turn, until one of them returns a false value. If none of them return a false value, the record will be processed (passed to handlers). If one returns a false value, no further processing of the record occurs.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.addHandler"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">addHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">hdlr</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.addHandler" title="Permalink to this definition">¶</a></dt> <dd><p>Adds the specified handler <em>hdlr</em> to this logger.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.removeHandler"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">removeHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">hdlr</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.removeHandler" title="Permalink to this definition">¶</a></dt> <dd><p>Removes the specified handler <em>hdlr</em> from this logger.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.findCaller"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">findCaller</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.findCaller" title="Permalink to this definition">¶</a></dt> <dd><p>Finds the caller’s source filename and line number. Returns the filename, line number and function name as a 3-element tuple.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.4: </span>The function name was added. In earlier versions, the filename and line number were returned as a 2-element tuple.</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.handle"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">handle</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.handle" title="Permalink to this definition">¶</a></dt> <dd><p>Handles a record by passing it to all handlers associated with this logger and its ancestors (until a false value of <em>propagate</em> is found). This method is used for unpickled records received from a socket, as well as those created locally. Logger-level filtering is applied using <a class="reference internal" href="#logging.Logger.filter" title="logging.Logger.filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">filter()</span></code></a>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Logger.makeRecord"> <span class="sig-prename descclassname"><span class="pre">Logger.</span></span><span class="sig-name descname"><span class="pre">makeRecord</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lvl</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fn</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lno</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exc_info</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">func</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">extra</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Logger.makeRecord" title="Permalink to this definition">¶</a></dt> <dd><p>This is a factory method which can be overridden in subclasses to create specialized <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> instances.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.5: </span><em>func</em> and <em>extra</em> were added.</p> </div> </dd></dl> </section> <section id="logging-levels"> <span id="levels"></span><h2><span class="section-number">15.7.2. </span>Logging Levels<a class="headerlink" href="#logging-levels" title="Permalink to this headline">¶</a></h2> <p>The numeric values of logging levels are given in the following table. These are primarily of interest if you want to define your own levels, and need them to have specific values relative to the predefined levels. If you define a level with the same numeric value, it overwrites the predefined value; the predefined name is lost.</p> <table class="docutils align-default"> <colgroup> <col style="width: 48%" /> <col style="width: 52%" /> </colgroup> <thead> <tr class="row-odd"><th class="head"><p>Level</p></th> <th class="head"><p>Numeric value</p></th> </tr> </thead> <tbody> <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">CRITICAL</span></code></p></td> <td><p>50</p></td> </tr> <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">ERROR</span></code></p></td> <td><p>40</p></td> </tr> <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">WARNING</span></code></p></td> <td><p>30</p></td> </tr> <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">INFO</span></code></p></td> <td><p>20</p></td> </tr> <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">DEBUG</span></code></p></td> <td><p>10</p></td> </tr> <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">NOTSET</span></code></p></td> <td><p>0</p></td> </tr> </tbody> </table> </section> <section id="handler-objects"> <span id="handler"></span><h2><span class="section-number">15.7.3. </span>Handler Objects<a class="headerlink" href="#handler-objects" title="Permalink to this headline">¶</a></h2> <p>Handlers have the following attributes and methods. Note that <code class="xref py py-class docutils literal notranslate"><span class="pre">Handler</span></code> is never instantiated directly; this class acts as a base for more useful subclasses. However, the <code class="xref py py-meth docutils literal notranslate"><span class="pre">__init__()</span></code> method in subclasses needs to call <a class="reference internal" href="#logging.Handler.__init__" title="logging.Handler.__init__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Handler.__init__()</span></code></a>.</p> <dl class="py method"> <dt class="sig sig-object py" id="logging.Handler.__init__"> <span class="sig-prename descclassname"><span class="pre">Handler.</span></span><span class="sig-name descname"><span class="pre">__init__</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">level</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">NOTSET</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.__init__" title="Permalink to this definition">¶</a></dt> <dd><p>Initializes the <code class="xref py py-class docutils literal notranslate"><span class="pre">Handler</span></code> instance by setting its level, setting the list of filters to the empty list and creating a lock (using <a class="reference internal" href="#logging.Handler.createLock" title="logging.Handler.createLock"><code class="xref py py-meth docutils literal notranslate"><span class="pre">createLock()</span></code></a>) for serializing access to an I/O mechanism.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Handler.createLock"> <span class="sig-prename descclassname"><span class="pre">Handler.</span></span><span class="sig-name descname"><span class="pre">createLock</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.createLock" title="Permalink to this definition">¶</a></dt> <dd><p>Initializes a thread lock which can be used to serialize access to underlying I/O functionality which may not be threadsafe.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Handler.acquire"> <span class="sig-prename descclassname"><span class="pre">Handler.</span></span><span class="sig-name descname"><span class="pre">acquire</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.acquire" title="Permalink to this definition">¶</a></dt> <dd><p>Acquires the thread lock created with <a class="reference internal" href="#logging.Handler.createLock" title="logging.Handler.createLock"><code class="xref py py-meth docutils literal notranslate"><span class="pre">createLock()</span></code></a>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Handler.release"> <span class="sig-prename descclassname"><span class="pre">Handler.</span></span><span class="sig-name descname"><span class="pre">release</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.release" title="Permalink to this definition">¶</a></dt> <dd><p>Releases the thread lock acquired with <a class="reference internal" href="#logging.Handler.acquire" title="logging.Handler.acquire"><code class="xref py py-meth docutils literal notranslate"><span class="pre">acquire()</span></code></a>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Handler.setLevel"> <span class="sig-prename descclassname"><span class="pre">Handler.</span></span><span class="sig-name descname"><span class="pre">setLevel</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">level</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.setLevel" title="Permalink to this definition">¶</a></dt> <dd><p>Sets the threshold for this handler to <em>level</em>. Logging messages which are less severe than <em>level</em> will be ignored. When a handler is created, the level is set to <code class="xref py py-const docutils literal notranslate"><span class="pre">NOTSET</span></code> (which causes all messages to be processed).</p> <p>See <a class="reference internal" href="#levels"><span class="std std-ref">Logging Levels</span></a> for a list of levels.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Handler.setFormatter"> <span class="sig-prename descclassname"><span class="pre">Handler.</span></span><span class="sig-name descname"><span class="pre">setFormatter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fmt</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.setFormatter" title="Permalink to this definition">¶</a></dt> <dd><p>Sets the <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> for this handler to <em>fmt</em>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Handler.addFilter"> <span class="sig-prename descclassname"><span class="pre">Handler.</span></span><span class="sig-name descname"><span class="pre">addFilter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filter</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.addFilter" title="Permalink to this definition">¶</a></dt> <dd><p>Adds the specified filter <em>filter</em> to this handler.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Handler.removeFilter"> <span class="sig-prename descclassname"><span class="pre">Handler.</span></span><span class="sig-name descname"><span class="pre">removeFilter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filter</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.removeFilter" title="Permalink to this definition">¶</a></dt> <dd><p>Removes the specified filter <em>filter</em> from this handler.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Handler.filter"> <span class="sig-prename descclassname"><span class="pre">Handler.</span></span><span class="sig-name descname"><span class="pre">filter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.filter" title="Permalink to this definition">¶</a></dt> <dd><p>Applies this handler’s filters to the record and returns a true value if the record is to be processed. The filters are consulted in turn, until one of them returns a false value. If none of them return a false value, the record will be emitted. If one returns a false value, the handler will not emit the record.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Handler.flush"> <span class="sig-prename descclassname"><span class="pre">Handler.</span></span><span class="sig-name descname"><span class="pre">flush</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.flush" title="Permalink to this definition">¶</a></dt> <dd><p>Ensure all logging output has been flushed. This version does nothing and is intended to be implemented by subclasses.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Handler.close"> <span class="sig-prename descclassname"><span class="pre">Handler.</span></span><span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.close" title="Permalink to this definition">¶</a></dt> <dd><p>Tidy up any resources used by the handler. This version does no output but removes the handler from an internal list of handlers which is closed when <a class="reference internal" href="#logging.shutdown" title="logging.shutdown"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutdown()</span></code></a> is called. Subclasses should ensure that this gets called from overridden <a class="reference internal" href="#logging.Handler.close" title="logging.Handler.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a> methods.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Handler.handle"> <span class="sig-prename descclassname"><span class="pre">Handler.</span></span><span class="sig-name descname"><span class="pre">handle</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.handle" title="Permalink to this definition">¶</a></dt> <dd><p>Conditionally emits the specified logging record, depending on filters which may have been added to the handler. Wraps the actual emission of the record with acquisition/release of the I/O thread lock.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Handler.handleError"> <span class="sig-prename descclassname"><span class="pre">Handler.</span></span><span class="sig-name descname"><span class="pre">handleError</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.handleError" title="Permalink to this definition">¶</a></dt> <dd><p>This method should be called from handlers when an exception is encountered during an <a class="reference internal" href="#logging.Handler.emit" title="logging.Handler.emit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">emit()</span></code></a> call. If the module-level attribute <code class="docutils literal notranslate"><span class="pre">raiseExceptions</span></code> is <code class="docutils literal notranslate"><span class="pre">False</span></code>, exceptions get silently ignored. This is what is mostly wanted for a logging system - most users will not care about errors in the logging system, they are more interested in application errors. You could, however, replace this with a custom handler if you wish. The specified record is the one which was being processed when the exception occurred. (The default value of <code class="docutils literal notranslate"><span class="pre">raiseExceptions</span></code> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, as that is more useful during development).</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Handler.format"> <span class="sig-prename descclassname"><span class="pre">Handler.</span></span><span class="sig-name descname"><span class="pre">format</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.format" title="Permalink to this definition">¶</a></dt> <dd><p>Do formatting for a record - if a formatter is set, use it. Otherwise, use the default formatter for the module.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Handler.emit"> <span class="sig-prename descclassname"><span class="pre">Handler.</span></span><span class="sig-name descname"><span class="pre">emit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Handler.emit" title="Permalink to this definition">¶</a></dt> <dd><p>Do whatever it takes to actually log the specified logging record. This version is intended to be implemented by subclasses and so raises a <code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code>.</p> </dd></dl> <p>For a list of handlers included as standard, see <a class="reference internal" href="logging.handlers.html#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a>.</p> </section> <section id="formatter-objects"> <span id="id1"></span><h2><span class="section-number">15.7.4. </span>Formatter Objects<a class="headerlink" href="#formatter-objects" title="Permalink to this headline">¶</a></h2> <p><a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> objects have the following attributes and methods. They are responsible for converting a <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> to (usually) a string which can be interpreted by either a human or an external system. The base <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> allows a formatting string to be specified. If none is supplied, the default value of <code class="docutils literal notranslate"><span class="pre">'%(message)s'</span></code> is used, which just includes the message in the logging call. To have additional items of information in the formatted output (such as a timestamp), keep reading.</p> <p>A Formatter can be initialized with a format string which makes use of knowledge of the <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> attributes - such as the default value mentioned above making use of the fact that the user’s message and arguments are pre-formatted into a <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a>’s <em>message</em> attribute. This format string contains standard Python %-style mapping keys. See section <a class="reference internal" href="stdtypes.html#string-formatting"><span class="std std-ref">String Formatting Operations</span></a> for more information on string formatting.</p> <p>The useful mapping keys in a <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> are given in the section on <a class="reference internal" href="#logrecord-attributes"><span class="std std-ref">LogRecord attributes</span></a>.</p> <dl class="py class"> <dt class="sig sig-object py" id="logging.Formatter"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">Formatter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fmt</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">datefmt</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Formatter" title="Permalink to this definition">¶</a></dt> <dd><p>Returns a new instance of the <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> class. The instance is initialized with a format string for the message as a whole, as well as a format string for the date/time portion of a message. If no <em>fmt</em> is specified, <code class="docutils literal notranslate"><span class="pre">'%(message)s'</span></code> is used. If no <em>datefmt</em> is specified, the ISO8601 date format is used.</p> <dl class="py method"> <dt class="sig sig-object py" id="logging.Formatter.format"> <span class="sig-name descname"><span class="pre">format</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Formatter.format" title="Permalink to this definition">¶</a></dt> <dd><p>The record’s attribute dictionary is used as the operand to a string formatting operation. Returns the resulting string. Before formatting the dictionary, a couple of preparatory steps are carried out. The <em>message</em> attribute of the record is computed using <em>msg</em> % <em>args</em>. If the formatting string contains <code class="docutils literal notranslate"><span class="pre">'(asctime)'</span></code>, <a class="reference internal" href="#logging.Formatter.formatTime" title="logging.Formatter.formatTime"><code class="xref py py-meth docutils literal notranslate"><span class="pre">formatTime()</span></code></a> is called to format the event time. If there is exception information, it is formatted using <a class="reference internal" href="#logging.Formatter.formatException" title="logging.Formatter.formatException"><code class="xref py py-meth docutils literal notranslate"><span class="pre">formatException()</span></code></a> and appended to the message. Note that the formatted exception information is cached in attribute <em>exc_text</em>. This is useful because the exception information can be pickled and sent across the wire, but you should be careful if you have more than one <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> subclass which customizes the formatting of exception information. In this case, you will have to clear the cached value after a formatter has done its formatting, so that the next formatter to handle the event doesn’t use the cached value but recalculates it afresh.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Formatter.formatTime"> <span class="sig-name descname"><span class="pre">formatTime</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">datefmt</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Formatter.formatTime" title="Permalink to this definition">¶</a></dt> <dd><p>This method should be called from <a class="reference internal" href="functions.html#format" title="format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">format()</span></code></a> by a formatter which wants to make use of a formatted time. This method can be overridden in formatters to provide for any specific requirement, but the basic behavior is as follows: if <em>datefmt</em> (a string) is specified, it is used with <a class="reference internal" href="time.html#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.strftime()</span></code></a> to format the creation time of the record. Otherwise, the ISO8601 format is used. The resulting string is returned.</p> <p>This function uses a user-configurable function to convert the creation time to a tuple. By default, <a class="reference internal" href="time.html#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.localtime()</span></code></a> is used; to change this for a particular formatter instance, set the <code class="docutils literal notranslate"><span class="pre">converter</span></code> attribute to a function with the same signature as <a class="reference internal" href="time.html#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.localtime()</span></code></a> or <a class="reference internal" href="time.html#time.gmtime" title="time.gmtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.gmtime()</span></code></a>. To change it for all formatters, for example if you want all logging times to be shown in GMT, set the <code class="docutils literal notranslate"><span class="pre">converter</span></code> attribute in the <code class="docutils literal notranslate"><span class="pre">Formatter</span></code> class.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="logging.Formatter.formatException"> <span class="sig-name descname"><span class="pre">formatException</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">exc_info</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Formatter.formatException" title="Permalink to this definition">¶</a></dt> <dd><p>Formats the specified exception information (a standard exception tuple as returned by <a class="reference internal" href="sys.html#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exc_info()</span></code></a>) as a string. This default implementation just uses <a class="reference internal" href="traceback.html#traceback.print_exception" title="traceback.print_exception"><code class="xref py py-func docutils literal notranslate"><span class="pre">traceback.print_exception()</span></code></a>. The resulting string is returned.</p> </dd></dl> </dd></dl> </section> <section id="filter-objects"> <span id="filter"></span><h2><span class="section-number">15.7.5. </span>Filter Objects<a class="headerlink" href="#filter-objects" title="Permalink to this headline">¶</a></h2> <p><code class="docutils literal notranslate"><span class="pre">Filters</span></code> can be used by <code class="docutils literal notranslate"><span class="pre">Handlers</span></code> and <code class="docutils literal notranslate"><span class="pre">Loggers</span></code> for more sophisticated filtering than is provided by levels. The base filter class only allows events which are below a certain point in the logger hierarchy. For example, a filter initialized with ‘A.B’ will allow events logged by loggers ‘A.B’, ‘A.B.C’, ‘A.B.C.D’, ‘A.B.D’ etc. but not ‘A.BB’, ‘B.A.B’ etc. If initialized with the empty string, all events are passed.</p> <dl class="py class"> <dt class="sig sig-object py" id="logging.Filter"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">Filter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Filter" title="Permalink to this definition">¶</a></dt> <dd><p>Returns an instance of the <a class="reference internal" href="#logging.Filter" title="logging.Filter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Filter</span></code></a> class. If <em>name</em> is specified, it names a logger which, together with its children, will have its events allowed through the filter. If <em>name</em> is the empty string, allows every event.</p> <dl class="py method"> <dt class="sig sig-object py" id="logging.Filter.filter"> <span class="sig-name descname"><span class="pre">filter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.Filter.filter" title="Permalink to this definition">¶</a></dt> <dd><p>Is the specified record to be logged? Returns zero for no, nonzero for yes. If deemed appropriate, the record may be modified in-place by this method.</p> </dd></dl> </dd></dl> <p>Note that filters attached to handlers are consulted before an event is emitted by the handler, whereas filters attached to loggers are consulted whenever an event is logged (using <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>, <a class="reference internal" href="#logging.info" title="logging.info"><code class="xref py py-meth docutils literal notranslate"><span class="pre">info()</span></code></a>, etc.), before sending an event to handlers. This means that events which have been generated by descendant loggers will not be filtered by a logger’s filter setting, unless the filter has also been applied to those descendant loggers.</p> <p>You don’t actually need to subclass <code class="docutils literal notranslate"><span class="pre">Filter</span></code>: you can pass any instance which has a <code class="docutils literal notranslate"><span class="pre">filter</span></code> method with the same semantics.</p> <p>Although filters are used primarily to filter records based on more sophisticated criteria than levels, they get to see every record which is processed by the handler or logger they’re attached to: this can be useful if you want to do things like counting how many records were processed by a particular logger or handler, or adding, changing or removing attributes in the LogRecord being processed. Obviously changing the LogRecord needs to be done with some care, but it does allow the injection of contextual information into logs (see <a class="reference internal" href="../howto/logging-cookbook.html#filters-contextual"><span class="std std-ref">Using Filters to impart contextual information</span></a>).</p> </section> <section id="logrecord-objects"> <span id="log-record"></span><h2><span class="section-number">15.7.6. </span>LogRecord Objects<a class="headerlink" href="#logrecord-objects" title="Permalink to this headline">¶</a></h2> <p><a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> instances are created automatically by the <a class="reference internal" href="#logging.Logger" title="logging.Logger"><code class="xref py py-class docutils literal notranslate"><span class="pre">Logger</span></code></a> every time something is logged, and can be created manually via <a class="reference internal" href="#logging.makeLogRecord" title="logging.makeLogRecord"><code class="xref py py-func docutils literal notranslate"><span class="pre">makeLogRecord()</span></code></a> (for example, from a pickled event received over the wire).</p> <dl class="py class"> <dt class="sig sig-object py" id="logging.LogRecord"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">LogRecord</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">level</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pathname</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lineno</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exc_info</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">func</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.LogRecord" title="Permalink to this definition">¶</a></dt> <dd><p>Contains all the information pertinent to the event being logged.</p> <p>The primary information is passed in <code class="xref py py-attr docutils literal notranslate"><span class="pre">msg</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">args</span></code>, which are combined using <code class="docutils literal notranslate"><span class="pre">msg</span> <span class="pre">%</span> <span class="pre">args</span></code> to create the <code class="xref py py-attr docutils literal notranslate"><span class="pre">message</span></code> field of the record.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters</dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>name</strong> – The name of the logger used to log the event represented by this LogRecord. Note that this name will always have this value, even though it may be emitted by a handler attached to a different (ancestor) logger.</p></li> <li><p><strong>level</strong> – The numeric level of the logging event (one of DEBUG, INFO etc.) Note that this is converted to <em>two</em> attributes of the LogRecord: <code class="docutils literal notranslate"><span class="pre">levelno</span></code> for the numeric value and <code class="docutils literal notranslate"><span class="pre">levelname</span></code> for the corresponding level name.</p></li> <li><p><strong>pathname</strong> – The full pathname of the source file where the logging call was made.</p></li> <li><p><strong>lineno</strong> – The line number in the source file where the logging call was made.</p></li> <li><p><strong>msg</strong> – The event description message, possibly a format string with placeholders for variable data.</p></li> <li><p><strong>args</strong> – Variable data to merge into the <em>msg</em> argument to obtain the event description.</p></li> <li><p><strong>exc_info</strong> – An exception tuple with the current exception information, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if no exception information is available.</p></li> <li><p><strong>func</strong> – The name of the function or method from which the logging call was invoked.</p></li> </ul> </dd> </dl> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.5: </span><em>func</em> was added.</p> </div> <dl class="py method"> <dt class="sig sig-object py" id="logging.LogRecord.getMessage"> <span class="sig-name descname"><span class="pre">getMessage</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.LogRecord.getMessage" title="Permalink to this definition">¶</a></dt> <dd><p>Returns the message for this <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> instance after merging any user-supplied arguments with the message. If the user-supplied message argument to the logging call is not a string, <a class="reference internal" href="functions.html#str" title="str"><code class="xref py py-func docutils literal notranslate"><span class="pre">str()</span></code></a> is called on it to convert it to a string. This allows use of user-defined classes as messages, whose <code class="docutils literal notranslate"><span class="pre">__str__</span></code> method can return the actual format string to be used.</p> </dd></dl> </dd></dl> </section> <section id="logrecord-attributes"> <span id="id2"></span><h2><span class="section-number">15.7.7. </span>LogRecord attributes<a class="headerlink" href="#logrecord-attributes" title="Permalink to this headline">¶</a></h2> <p>The LogRecord has a number of attributes, most of which are derived from the parameters to the constructor. (Note that the names do not always correspond exactly between the LogRecord constructor parameters and the LogRecord attributes.) These attributes can be used to merge data from the record into the format string. The following table lists (in alphabetical order) the attribute names, their meanings and the corresponding placeholder in a %-style format string.</p> <table class="docutils align-default"> <colgroup> <col style="width: 18%" /> <col style="width: 28%" /> <col style="width: 53%" /> </colgroup> <thead> <tr class="row-odd"><th class="head"><p>Attribute name</p></th> <th class="head"><p>Format</p></th> <th class="head"><p>Description</p></th> </tr> </thead> <tbody> <tr class="row-even"><td><p>args</p></td> <td><p>You shouldn’t need to format this yourself.</p></td> <td><p>The tuple of arguments merged into <code class="docutils literal notranslate"><span class="pre">msg</span></code> to produce <code class="docutils literal notranslate"><span class="pre">message</span></code>, or a dict whose values are used for the merge (when there is only one argument, and it is a dictionary).</p></td> </tr> <tr class="row-odd"><td><p>asctime</p></td> <td><p><code class="docutils literal notranslate"><span class="pre">%(asctime)s</span></code></p></td> <td><p>Human-readable time when the <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> 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).</p></td> </tr> <tr class="row-even"><td><p>created</p></td> <td><p><code class="docutils literal notranslate"><span class="pre">%(created)f</span></code></p></td> <td><p>Time when the <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> was created (as returned by <a class="reference internal" href="time.html#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.time()</span></code></a>).</p></td> </tr> <tr class="row-odd"><td><p>exc_info</p></td> <td><p>You shouldn’t need to format this yourself.</p></td> <td><p>Exception tuple (à la <code class="docutils literal notranslate"><span class="pre">sys.exc_info</span></code>) or, if no exception has occurred, <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p></td> </tr> <tr class="row-even"><td><p>filename</p></td> <td><p><code class="docutils literal notranslate"><span class="pre">%(filename)s</span></code></p></td> <td><p>Filename portion of <code class="docutils literal notranslate"><span class="pre">pathname</span></code>.</p></td> </tr> <tr class="row-odd"><td><p>funcName</p></td> <td><p><code class="docutils literal notranslate"><span class="pre">%(funcName)s</span></code></p></td> <td><p>Name of function containing the logging call.</p></td> </tr> <tr class="row-even"><td><p>levelname</p></td> <td><p><code class="docutils literal notranslate"><span class="pre">%(levelname)s</span></code></p></td> <td><p>Text logging level for the message (<code class="docutils literal notranslate"><span class="pre">'DEBUG'</span></code>, <code class="docutils literal notranslate"><span class="pre">'INFO'</span></code>, <code class="docutils literal notranslate"><span class="pre">'WARNING'</span></code>, <code class="docutils literal notranslate"><span class="pre">'ERROR'</span></code>, <code class="docutils literal notranslate"><span class="pre">'CRITICAL'</span></code>).</p></td> </tr> <tr class="row-odd"><td><p>levelno</p></td> <td><p><code class="docutils literal notranslate"><span class="pre">%(levelno)s</span></code></p></td> <td><p>Numeric logging level for the message (<code class="xref py py-const docutils literal notranslate"><span class="pre">DEBUG</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">INFO</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">WARNING</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">ERROR</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">CRITICAL</span></code>).</p></td> </tr> <tr class="row-even"><td><p>lineno</p></td> <td><p><code class="docutils literal notranslate"><span class="pre">%(lineno)d</span></code></p></td> <td><p>Source line number where the logging call was issued (if available).</p></td> </tr> <tr class="row-odd"><td><p>module</p></td> <td><p><code class="docutils literal notranslate"><span class="pre">%(module)s</span></code></p></td> <td><p>Module (name portion of <code class="docutils literal notranslate"><span class="pre">filename</span></code>).</p></td> </tr> <tr class="row-even"><td><p>msecs</p></td> <td><p><code class="docutils literal notranslate"><span class="pre">%(msecs)d</span></code></p></td> <td><p>Millisecond portion of the time when the <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> was created.</p></td> </tr> <tr class="row-odd"><td><p>message</p></td> <td><p><code class="docutils literal notranslate"><span class="pre">%(message)s</span></code></p></td> <td><p>The logged message, computed as <code class="docutils literal notranslate"><span class="pre">msg</span> <span class="pre">%</span> <span class="pre">args</span></code>. This is set when <a class="reference internal" href="#logging.Formatter.format" title="logging.Formatter.format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Formatter.format()</span></code></a> is invoked.</p></td> </tr> <tr class="row-even"><td><p>msg</p></td> <td><p>You shouldn’t need to format this yourself.</p></td> <td><p>The format string passed in the original logging call. Merged with <code class="docutils literal notranslate"><span class="pre">args</span></code> to produce <code class="docutils literal notranslate"><span class="pre">message</span></code>, or an arbitrary object (see <a class="reference internal" href="../howto/logging.html#arbitrary-object-messages"><span class="std std-ref">Using arbitrary objects as messages</span></a>).</p></td> </tr> <tr class="row-odd"><td><p>name</p></td> <td><p><code class="docutils literal notranslate"><span class="pre">%(name)s</span></code></p></td> <td><p>Name of the logger used to log the call.</p></td> </tr> <tr class="row-even"><td><p>pathname</p></td> <td><p><code class="docutils literal notranslate"><span class="pre">%(pathname)s</span></code></p></td> <td><p>Full pathname of the source file where the logging call was issued (if available).</p></td> </tr> <tr class="row-odd"><td><p>process</p></td> <td><p><code class="docutils literal notranslate"><span class="pre">%(process)d</span></code></p></td> <td><p>Process ID (if available).</p></td> </tr> <tr class="row-even"><td><p>processName</p></td> <td><p><code class="docutils literal notranslate"><span class="pre">%(processName)s</span></code></p></td> <td><p>Process name (if available).</p></td> </tr> <tr class="row-odd"><td><p>relativeCreated</p></td> <td><p><code class="docutils literal notranslate"><span class="pre">%(relativeCreated)d</span></code></p></td> <td><p>Time in milliseconds when the LogRecord was created, relative to the time the logging module was loaded.</p></td> </tr> <tr class="row-even"><td><p>thread</p></td> <td><p><code class="docutils literal notranslate"><span class="pre">%(thread)d</span></code></p></td> <td><p>Thread ID (if available).</p></td> </tr> <tr class="row-odd"><td><p>threadName</p></td> <td><p><code class="docutils literal notranslate"><span class="pre">%(threadName)s</span></code></p></td> <td><p>Thread name (if available).</p></td> </tr> </tbody> </table> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.5: </span><em>funcName</em> was added.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.6: </span><em>processName</em> was added.</p> </div> </section> <section id="loggeradapter-objects"> <span id="logger-adapter"></span><h2><span class="section-number">15.7.8. </span>LoggerAdapter Objects<a class="headerlink" href="#loggeradapter-objects" title="Permalink to this headline">¶</a></h2> <p><a class="reference internal" href="#logging.LoggerAdapter" title="logging.LoggerAdapter"><code class="xref py py-class docutils literal notranslate"><span class="pre">LoggerAdapter</span></code></a> instances are used to conveniently pass contextual information into logging calls. For a usage example, see the section on <a class="reference internal" href="../howto/logging-cookbook.html#context-info"><span class="std std-ref">adding contextual information to your logging output</span></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 2.6.</span></p> </div> <dl class="py class"> <dt class="sig sig-object py" id="logging.LoggerAdapter"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">LoggerAdapter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">logger</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">extra</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.LoggerAdapter" title="Permalink to this definition">¶</a></dt> <dd><p>Returns an instance of <a class="reference internal" href="#logging.LoggerAdapter" title="logging.LoggerAdapter"><code class="xref py py-class docutils literal notranslate"><span class="pre">LoggerAdapter</span></code></a> initialized with an underlying <a class="reference internal" href="#logging.Logger" title="logging.Logger"><code class="xref py py-class docutils literal notranslate"><span class="pre">Logger</span></code></a> instance and a dict-like object.</p> <dl class="py method"> <dt class="sig sig-object py" id="logging.LoggerAdapter.process"> <span class="sig-name descname"><span class="pre">process</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.LoggerAdapter.process" title="Permalink to this definition">¶</a></dt> <dd><p>Modifies the message and/or keyword arguments passed to a logging call in order to insert contextual information. This implementation takes the object passed as <em>extra</em> to the constructor and adds it to <em>kwargs</em> using key ‘extra’. The return value is a (<em>msg</em>, <em>kwargs</em>) tuple which has the (possibly modified) versions of the arguments passed in.</p> </dd></dl> </dd></dl> <p>In addition to the above, <a class="reference internal" href="#logging.LoggerAdapter" title="logging.LoggerAdapter"><code class="xref py py-class docutils literal notranslate"><span class="pre">LoggerAdapter</span></code></a> supports the following methods of <a class="reference internal" href="#logging.Logger" title="logging.Logger"><code class="xref py py-class docutils literal notranslate"><span class="pre">Logger</span></code></a>: <a class="reference internal" href="#logging.Logger.debug" title="logging.Logger.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>, <a class="reference internal" href="#logging.Logger.info" title="logging.Logger.info"><code class="xref py py-meth docutils literal notranslate"><span class="pre">info()</span></code></a>, <a class="reference internal" href="#logging.Logger.warning" title="logging.Logger.warning"><code class="xref py py-meth docutils literal notranslate"><span class="pre">warning()</span></code></a>, <a class="reference internal" href="#logging.Logger.error" title="logging.Logger.error"><code class="xref py py-meth docutils literal notranslate"><span class="pre">error()</span></code></a>, <a class="reference internal" href="#logging.Logger.exception" title="logging.Logger.exception"><code class="xref py py-meth docutils literal notranslate"><span class="pre">exception()</span></code></a>, <a class="reference internal" href="#logging.Logger.critical" title="logging.Logger.critical"><code class="xref py py-meth docutils literal notranslate"><span class="pre">critical()</span></code></a>, <a class="reference internal" href="#logging.Logger.log" title="logging.Logger.log"><code class="xref py py-meth docutils literal notranslate"><span class="pre">log()</span></code></a> and <a class="reference internal" href="#logging.Logger.isEnabledFor" title="logging.Logger.isEnabledFor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">isEnabledFor()</span></code></a>. These methods have the same signatures as their counterparts in <a class="reference internal" href="#logging.Logger" title="logging.Logger"><code class="xref py py-class docutils literal notranslate"><span class="pre">Logger</span></code></a>, so you can use the two types of instances interchangeably for these calls.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.7: </span>The <a class="reference internal" href="#logging.Logger.isEnabledFor" title="logging.Logger.isEnabledFor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">isEnabledFor()</span></code></a> method was added to <a class="reference internal" href="#logging.LoggerAdapter" title="logging.LoggerAdapter"><code class="xref py py-class docutils literal notranslate"><span class="pre">LoggerAdapter</span></code></a>. This method delegates to the underlying logger.</p> </div> </section> <section id="thread-safety"> <h2><span class="section-number">15.7.9. </span>Thread Safety<a class="headerlink" href="#thread-safety" title="Permalink to this headline">¶</a></h2> <p>The logging module is intended to be thread-safe without any special work needing to be done by its clients. It achieves this though using threading locks; there is one lock to serialize access to the module’s shared data, and each handler also creates a lock to serialize access to its underlying I/O.</p> <p>If you are implementing asynchronous signal handlers using the <a class="reference internal" href="signal.html#module-signal" title="signal: Set handlers for asynchronous events."><code class="xref py py-mod docutils literal notranslate"><span class="pre">signal</span></code></a> module, you may not be able to use logging from within such handlers. This is because lock implementations in the <a class="reference internal" href="threading.html#module-threading" title="threading: Higher-level threading interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">threading</span></code></a> module are not always re-entrant, and so cannot be invoked from such signal handlers.</p> </section> <section id="module-level-functions"> <h2><span class="section-number">15.7.10. </span>Module-Level Functions<a class="headerlink" href="#module-level-functions" title="Permalink to this headline">¶</a></h2> <p>In addition to the classes described above, there are a number of module- level functions.</p> <dl class="py function"> <dt class="sig sig-object py" id="logging.getLogger"> <span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">getLogger</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.getLogger" title="Permalink to this definition">¶</a></dt> <dd><p>Return a logger with the specified name or, if no name is specified, return a logger which is the root logger of the hierarchy. If specified, the name is typically a dot-separated hierarchical name like <em>“a”</em>, <em>“a.b”</em> or <em>“a.b.c.d”</em>. Choice of these names is entirely up to the developer who is using logging.</p> <p>All calls to this function with a given name return the same logger instance. This means that logger instances never need to be passed between different parts of an application.</p> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="logging.getLoggerClass"> <span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">getLoggerClass</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.getLoggerClass" title="Permalink to this definition">¶</a></dt> <dd><p>Return either the standard <a class="reference internal" href="#logging.Logger" title="logging.Logger"><code class="xref py py-class docutils literal notranslate"><span class="pre">Logger</span></code></a> class, or the last class passed to <a class="reference internal" href="#logging.setLoggerClass" title="logging.setLoggerClass"><code class="xref py py-func docutils literal notranslate"><span class="pre">setLoggerClass()</span></code></a>. This function may be called from within a new class definition, to ensure that installing a customized <a class="reference internal" href="#logging.Logger" title="logging.Logger"><code class="xref py py-class docutils literal notranslate"><span class="pre">Logger</span></code></a> class will not undo customizations already applied by other code. For example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyLogger</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">getLoggerClass</span><span class="p">()):</span> <span class="c1"># ... override behaviour here</span> </pre></div> </div> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="logging.debug"> <span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">debug</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">*args</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">**kwargs</span></span></em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.debug" title="Permalink to this definition">¶</a></dt> <dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">DEBUG</span></code> on the root logger. The <em>msg</em> is the message format string, and the <em>args</em> are the arguments which are merged into <em>msg</em> using the string formatting operator. (Note that this means that you can use keywords in the format string, together with a single dictionary argument.)</p> <p>There are two keyword arguments in <em>kwargs</em> which are inspected: <em>exc_info</em> which, if it does not evaluate as false, causes exception information to be added to the logging message. If an exception tuple (in the format returned by <a class="reference internal" href="sys.html#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exc_info()</span></code></a>) is provided, it is used; otherwise, <a class="reference internal" href="sys.html#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exc_info()</span></code></a> is called to get the exception information.</p> <p>The other optional keyword argument is <em>extra</em> which can be used to pass a dictionary which is used to populate the __dict__ of the LogRecord created for the logging event with user-defined attributes. These custom attributes can then be used as you like. For example, they could be incorporated into logged messages. For example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">FORMAT</span> <span class="o">=</span> <span class="s2">"</span><span class="si">%(asctime)-15s</span><span class="s2"> </span><span class="si">%(clientip)s</span><span class="s2"> </span><span class="si">%(user)-8s</span><span class="s2"> </span><span class="si">%(message)s</span><span class="s2">"</span> <span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="nb">format</span><span class="o">=</span><span class="n">FORMAT</span><span class="p">)</span> <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'clientip'</span><span class="p">:</span> <span class="s1">'192.168.0.1'</span><span class="p">,</span> <span class="s1">'user'</span><span class="p">:</span> <span class="s1">'fbloggs'</span><span class="p">}</span> <span class="n">logging</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">"Protocol problem: </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="s2">"connection reset"</span><span class="p">,</span> <span class="n">extra</span><span class="o">=</span><span class="n">d</span><span class="p">)</span> </pre></div> </div> <p>would print something like:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="mi">2006</span><span class="o">-</span><span class="mi">02</span><span class="o">-</span><span class="mi">08</span> <span class="mi">22</span><span class="p">:</span><span class="mi">20</span><span class="p">:</span><span class="mi">02</span><span class="p">,</span><span class="mi">165</span> <span class="mf">192.168.0.1</span> <span class="n">fbloggs</span> <span class="n">Protocol</span> <span class="n">problem</span><span class="p">:</span> <span class="n">connection</span> <span class="n">reset</span> </pre></div> </div> <p>The keys in the dictionary passed in <em>extra</em> should not clash with the keys used by the logging system. (See the <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> documentation for more information on which keys are used by the logging system.)</p> <p>If you choose to use these attributes in logged messages, you need to exercise some care. In the above example, for instance, the <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> has been set up with a format string which expects ‘clientip’ and ‘user’ in the attribute dictionary of the LogRecord. If these are missing, the message will not be logged because a string formatting exception will occur. So in this case, you always need to pass the <em>extra</em> dictionary with these keys.</p> <p>While this might be annoying, this feature is intended for use in specialized circumstances, such as multi-threaded servers where the same code executes in many contexts, and interesting conditions which arise are dependent on this context (such as remote client IP address and authenticated user name, in the above example). In such circumstances, it is likely that specialized <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a>s would be used with particular <code class="xref py py-class docutils literal notranslate"><span class="pre">Handler</span></code>s.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.5: </span><em>extra</em> was added.</p> </div> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="logging.info"> <span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">info</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">*args</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">**kwargs</span></span></em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.info" title="Permalink to this definition">¶</a></dt> <dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">INFO</span></code> on the root logger. The arguments are interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-func docutils literal notranslate"><span class="pre">debug()</span></code></a>.</p> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="logging.warning"> <span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">warning</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">*args</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">**kwargs</span></span></em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.warning" title="Permalink to this definition">¶</a></dt> <dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">WARNING</span></code> on the root logger. The arguments are interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-func docutils literal notranslate"><span class="pre">debug()</span></code></a>.</p> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="logging.error"> <span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">error</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">*args</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">**kwargs</span></span></em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.error" title="Permalink to this definition">¶</a></dt> <dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">ERROR</span></code> on the root logger. The arguments are interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-func docutils literal notranslate"><span class="pre">debug()</span></code></a>.</p> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="logging.critical"> <span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">critical</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">*args</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">**kwargs</span></span></em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.critical" title="Permalink to this definition">¶</a></dt> <dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">CRITICAL</span></code> on the root logger. The arguments are interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-func docutils literal notranslate"><span class="pre">debug()</span></code></a>.</p> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="logging.exception"> <span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">exception</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">*args</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">**kwargs</span></span></em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.exception" title="Permalink to this definition">¶</a></dt> <dd><p>Logs a message with level <code class="xref py py-const docutils literal notranslate"><span class="pre">ERROR</span></code> on the root logger. The arguments are interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-func docutils literal notranslate"><span class="pre">debug()</span></code></a>, except that any passed <em>exc_info</em> is not inspected. Exception info is always added to the logging message. This function should only be called from an exception handler.</p> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="logging.log"> <span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">log</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">level</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">msg</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">*args</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">**kwargs</span></span></em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.log" title="Permalink to this definition">¶</a></dt> <dd><p>Logs a message with level <em>level</em> on the root logger. The other arguments are interpreted as for <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-func docutils literal notranslate"><span class="pre">debug()</span></code></a>.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>The above module-level convenience functions, which delegate to the root logger, call <a class="reference internal" href="#logging.basicConfig" title="logging.basicConfig"><code class="xref py py-func docutils literal notranslate"><span class="pre">basicConfig()</span></code></a> to ensure that at least one handler is available. Because of this, they should <em>not</em> be used in threads, in versions of Python earlier than 2.7.1 and 3.2, unless at least one handler has been added to the root logger <em>before</em> the threads are started. In earlier versions of Python, due to a thread safety shortcoming in <a class="reference internal" href="#logging.basicConfig" title="logging.basicConfig"><code class="xref py py-func docutils literal notranslate"><span class="pre">basicConfig()</span></code></a>, this can (under rare circumstances) lead to handlers being added multiple times to the root logger, which can in turn lead to multiple messages for the same event.</p> </div> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="logging.disable"> <span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">disable</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">lvl</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.disable" title="Permalink to this definition">¶</a></dt> <dd><p>Provides an overriding level <em>lvl</em> for all loggers which takes precedence over the logger’s own level. When the need arises to temporarily throttle logging output down across the whole application, this function can be useful. Its effect is to disable all logging calls of severity <em>lvl</em> and below, so that if you call it with a value of INFO, then all INFO and DEBUG events would be discarded, whereas those of severity WARNING and above would be processed according to the logger’s effective level. If <code class="docutils literal notranslate"><span class="pre">logging.disable(logging.NOTSET)</span></code> is called, it effectively removes this overriding level, so that logging output again depends on the effective levels of individual loggers.</p> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="logging.addLevelName"> <span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">addLevelName</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">lvl</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">levelName</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.addLevelName" title="Permalink to this definition">¶</a></dt> <dd><p>Associates level <em>lvl</em> with text <em>levelName</em> in an internal dictionary, which is used to map numeric levels to a textual representation, for example when a <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> formats a message. This function can also be used to define your own levels. The only constraints are that all levels used must be registered using this function, levels should be positive integers and they should increase in increasing order of severity.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>If you are thinking of defining your own levels, please see the section on <a class="reference internal" href="../howto/logging.html#custom-levels"><span class="std std-ref">Custom Levels</span></a>.</p> </div> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="logging.getLevelName"> <span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">getLevelName</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">lvl</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.getLevelName" title="Permalink to this definition">¶</a></dt> <dd><p>Returns the textual representation of logging level <em>lvl</em>. If the level is one of the predefined levels <code class="xref py py-const docutils literal notranslate"><span class="pre">CRITICAL</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">ERROR</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">WARNING</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">INFO</span></code> or <code class="xref py py-const docutils literal notranslate"><span class="pre">DEBUG</span></code> then you get the corresponding string. If you have associated levels with names using <a class="reference internal" href="#logging.addLevelName" title="logging.addLevelName"><code class="xref py py-func docutils literal notranslate"><span class="pre">addLevelName()</span></code></a> then the name you have associated with <em>lvl</em> is returned. If a numeric value corresponding to one of the defined levels is passed in, the corresponding string representation is returned. Otherwise, the string “Level %s” % lvl is returned.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>Integer levels should be used when e.g. setting levels on instances of <a class="reference internal" href="#logging.Logger" title="logging.Logger"><code class="xref py py-class docutils literal notranslate"><span class="pre">Logger</span></code></a> and handlers. This function is used to convert between an integer level and the level name displayed in the formatted log output by means of the <code class="docutils literal notranslate"><span class="pre">%(levelname)s</span></code> format specifier (see <a class="reference internal" href="#logrecord-attributes"><span class="std std-ref">LogRecord attributes</span></a>).</p> </div> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="logging.makeLogRecord"> <span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">makeLogRecord</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">attrdict</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.makeLogRecord" title="Permalink to this definition">¶</a></dt> <dd><p>Creates and returns a new <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> instance whose attributes are defined by <em>attrdict</em>. This function is useful for taking a pickled <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> attribute dictionary, sent over a socket, and reconstituting it as a <a class="reference internal" href="#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> instance at the receiving end.</p> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="logging.basicConfig"> <span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">basicConfig</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">**kwargs</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.basicConfig" title="Permalink to this definition">¶</a></dt> <dd><p>Does basic configuration for the logging system by creating a <a class="reference internal" href="logging.handlers.html#logging.StreamHandler" title="logging.StreamHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">StreamHandler</span></code></a> with a default <a class="reference internal" href="#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> and adding it to the root logger. The functions <a class="reference internal" href="#logging.debug" title="logging.debug"><code class="xref py py-func docutils literal notranslate"><span class="pre">debug()</span></code></a>, <a class="reference internal" href="#logging.info" title="logging.info"><code class="xref py py-func docutils literal notranslate"><span class="pre">info()</span></code></a>, <a class="reference internal" href="#logging.warning" title="logging.warning"><code class="xref py py-func docutils literal notranslate"><span class="pre">warning()</span></code></a>, <a class="reference internal" href="#logging.error" title="logging.error"><code class="xref py py-func docutils literal notranslate"><span class="pre">error()</span></code></a> and <a class="reference internal" href="#logging.critical" title="logging.critical"><code class="xref py py-func docutils literal notranslate"><span class="pre">critical()</span></code></a> will call <a class="reference internal" href="#logging.basicConfig" title="logging.basicConfig"><code class="xref py py-func docutils literal notranslate"><span class="pre">basicConfig()</span></code></a> automatically if no handlers are defined for the root logger.</p> <p>This function does nothing if the root logger already has handlers configured for it.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.4: </span>Formerly, <a class="reference internal" href="#logging.basicConfig" title="logging.basicConfig"><code class="xref py py-func docutils literal notranslate"><span class="pre">basicConfig()</span></code></a> did not take any keyword arguments.</p> </div> <div class="admonition note"> <p class="admonition-title">Note</p> <p>This function should be called from the main thread before other threads are started. In versions of Python prior to 2.7.1 and 3.2, if this function is called from multiple threads, it is possible (in rare circumstances) that a handler will be added to the root logger more than once, leading to unexpected results such as messages being duplicated in the log.</p> </div> <p>The following keyword arguments are supported.</p> <table class="docutils align-default"> <colgroup> <col style="width: 24%" /> <col style="width: 76%" /> </colgroup> <thead> <tr class="row-odd"><th class="head"><p>Format</p></th> <th class="head"><p>Description</p></th> </tr> </thead> <tbody> <tr class="row-even"><td><p><em>filename</em></p></td> <td><p>Specifies that a FileHandler be created, using the specified filename, rather than a StreamHandler.</p></td> </tr> <tr class="row-odd"><td><p><em>filemode</em></p></td> <td><p>If <em>filename</em> is specified, open the file in this mode. Defaults to <code class="docutils literal notranslate"><span class="pre">'a'</span></code>.</p></td> </tr> <tr class="row-even"><td><p><em>format</em></p></td> <td><p>Use the specified format string for the handler.</p></td> </tr> <tr class="row-odd"><td><p><em>datefmt</em></p></td> <td><p>Use the specified date/time format, as accepted by <a class="reference internal" href="time.html#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.strftime()</span></code></a>.</p></td> </tr> <tr class="row-even"><td><p><em>level</em></p></td> <td><p>Set the root logger level to the specified <a class="reference internal" href="#levels"><span class="std std-ref">level</span></a>.</p></td> </tr> <tr class="row-odd"><td><p><em>stream</em></p></td> <td><p>Use the specified stream to initialize the StreamHandler. Note that this argument is incompatible with <em>filename</em> - if both are present, <em>stream</em> is ignored.</p></td> </tr> </tbody> </table> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="logging.shutdown"> <span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">shutdown</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.shutdown" title="Permalink to this definition">¶</a></dt> <dd><p>Informs the logging system to perform an orderly shutdown by flushing and closing all handlers. This should be called at application exit and no further use of the logging system should be made after this call.</p> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="logging.setLoggerClass"> <span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">setLoggerClass</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">klass</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.setLoggerClass" title="Permalink to this definition">¶</a></dt> <dd><p>Tells the logging system to use the class <em>klass</em> when instantiating a logger. The class should define <code class="xref py py-meth docutils literal notranslate"><span class="pre">__init__()</span></code> such that only a name argument is required, and the <code class="xref py py-meth docutils literal notranslate"><span class="pre">__init__()</span></code> should call <code class="xref py py-meth docutils literal notranslate"><span class="pre">Logger.__init__()</span></code>. This function is typically called before any loggers are instantiated by applications which need to use custom logger behavior.</p> </dd></dl> </section> <section id="integration-with-the-warnings-module"> <h2><span class="section-number">15.7.11. </span>Integration with the warnings module<a class="headerlink" href="#integration-with-the-warnings-module" title="Permalink to this headline">¶</a></h2> <p>The <a class="reference internal" href="#logging.captureWarnings" title="logging.captureWarnings"><code class="xref py py-func docutils literal notranslate"><span class="pre">captureWarnings()</span></code></a> function can be used to integrate <a class="reference internal" href="#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> with the <a class="reference internal" href="warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-mod docutils literal notranslate"><span class="pre">warnings</span></code></a> module.</p> <dl class="py function"> <dt class="sig sig-object py" id="logging.captureWarnings"> <span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">captureWarnings</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">capture</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.captureWarnings" title="Permalink to this definition">¶</a></dt> <dd><p>This function is used to turn the capture of warnings by logging on and off.</p> <p>If <em>capture</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, warnings issued by the <a class="reference internal" href="warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-mod docutils literal notranslate"><span class="pre">warnings</span></code></a> module will be redirected to the logging system. Specifically, a warning will be formatted using <a class="reference internal" href="warnings.html#warnings.formatwarning" title="warnings.formatwarning"><code class="xref py py-func docutils literal notranslate"><span class="pre">warnings.formatwarning()</span></code></a> and the resulting string logged to a logger named <code class="docutils literal notranslate"><span class="pre">'py.warnings'</span></code> with a severity of <code class="xref py py-const docutils literal notranslate"><span class="pre">WARNING</span></code>.</p> <p>If <em>capture</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code>, the redirection of warnings to the logging system will stop, and warnings will be redirected to their original destinations (i.e. those in effect before <code class="docutils literal notranslate"><span class="pre">captureWarnings(True)</span></code> was called).</p> </dd></dl> <div class="admonition seealso"> <p class="admonition-title">See also</p> <dl class="simple"> <dt>Module <a class="reference internal" href="logging.config.html#module-logging.config" title="logging.config: Configuration of the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.config</span></code></a></dt><dd><p>Configuration API for the logging module.</p> </dd> <dt>Module <a class="reference internal" href="logging.handlers.html#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a></dt><dd><p>Useful handlers included with the logging module.</p> </dd> <dt><span class="target" id="index-1"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0282"><strong>PEP 282</strong></a> - A Logging System</dt><dd><p>The proposal which described this feature for inclusion in the Python standard library.</p> </dd> <dt><a class="reference external" href="https://www.red-dove.com/python_logging.html">Original Python logging package</a></dt><dd><p>This is the original source for the <a class="reference internal" href="#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> package. The version of the package available from this site is suitable for use with Python 1.5.2, 2.1.x and 2.2.x, which do not include the <a class="reference internal" href="#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> package in the standard library.</p> </dd> </dl> </div> </section> </section> <div class="clearer"></div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h3><a href="../contents.html">Table of Contents</a></h3> <ul> <li><a class="reference internal" href="#">15.7. <code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code> — Logging facility for Python</a><ul> <li><a class="reference internal" href="#logger-objects">15.7.1. Logger Objects</a></li> <li><a class="reference internal" href="#logging-levels">15.7.2. Logging Levels</a></li> <li><a class="reference internal" href="#handler-objects">15.7.3. Handler Objects</a></li> <li><a class="reference internal" href="#formatter-objects">15.7.4. Formatter Objects</a></li> <li><a class="reference internal" href="#filter-objects">15.7.5. Filter Objects</a></li> <li><a class="reference internal" href="#logrecord-objects">15.7.6. LogRecord Objects</a></li> <li><a class="reference internal" href="#logrecord-attributes">15.7.7. LogRecord attributes</a></li> <li><a class="reference internal" href="#loggeradapter-objects">15.7.8. LoggerAdapter Objects</a></li> <li><a class="reference internal" href="#thread-safety">15.7.9. Thread Safety</a></li> <li><a class="reference internal" href="#module-level-functions">15.7.10. Module-Level Functions</a></li> <li><a class="reference internal" href="#integration-with-the-warnings-module">15.7.11. Integration with the warnings module</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="getopt.html" title="previous chapter"><span class="section-number">15.6. </span><code class="xref py py-mod docutils literal notranslate"><span class="pre">getopt</span></code> — C-style parser for command line options</a></p> <h4>Next topic</h4> <p class="topless"><a href="logging.config.html" title="next chapter"><span class="section-number">15.8. </span><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.config</span></code> — Logging configuration</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/library/logging.rst.txt" rel="nofollow">Show Source</a></li> </ul> </div> <div id="searchbox" style="display: none" role="search"> <h3 id="searchlabel">Quick search</h3> <div class="searchformwrapper"> <form class="search" action="../search.html" method="get"> <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> <input type="submit" value="Go" /> </form> </div> </div> <script>$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="logging.config.html" title="15.8. logging.config — Logging configuration" >next</a> |</li> <li class="right" > <a href="getopt.html" title="15.6. getopt — C-style parser for command line options" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.18 documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="allos.html" ><span class="section-number">15. </span>Generic Operating System Services</a> »</li> <li class="nav-item nav-item-this"><a href=""><span class="section-number">15.7. </span><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code> — Logging facility for Python</a></li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 1990-2024, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="https://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on December 09, 2024. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 4.3.2. </div> </body> </html>
Close