Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 698abe7

Browse files
committed
Closes #20918: Added handling for exceptions during fallback output of logging exceptions.
1 parent a0b9eeb commit 698abe7

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

Lib/logging/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2001-2013 by Vinay Sajip. All Rights Reserved.
1+
# Copyright 2001-2014 by Vinay Sajip. All Rights Reserved.
22
#
33
# Permission to use, copy, modify, and distribute this software and its
44
# documentation for any purpose and without fee is hereby granted,
@@ -18,7 +18,7 @@
1818
Logging package for Python. Based on PEP 282 and comments thereto in
1919
comp.lang.python.
2020
21-
Copyright (C) 2001-2013 Vinay Sajip. All Rights Reserved.
21+
Copyright (C) 2001-2014 Vinay Sajip. All Rights Reserved.
2222
2323
To use, simply 'import logging' and log away!
2424
"""
@@ -42,6 +42,7 @@
4242

4343
__author__ = "Vinay Sajip <[email protected]>"
4444
__status__ = "production"
45+
# The following module attributes are no longer updated.
4546
__version__ = "0.5.1.2"
4647
__date__ = "07 February 2010"
4748

@@ -902,8 +903,15 @@ def handleError(self, record):
902903
sys.stderr.write('Logged from file %s, line %s\n' % (
903904
record.filename, record.lineno))
904905
# Issue 18671: output logging message and arguments
905-
sys.stderr.write('Message: %r\n'
906-
'Arguments: %s\n' % (record.msg, record.args))
906+
try:
907+
sys.stderr.write('Message: %r\n'
908+
'Arguments: %s\n' % (record.msg,
909+
record.args))
910+
except Exception:
911+
sys.stderr.write('Unable to print the message and arguments'
912+
' - possible formatting error.\nUse the'
913+
' traceback above to help find the error.\n'
914+
)
907915
except OSError: #pragma: no cover
908916
pass # see issue 5971
909917
finally:

0 commit comments

Comments
 (0)