Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
79ce12e0
Commit
79ce12e0
authored
Feb 11, 2014
by
Vinay Sajip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #20558: Improved implementation of error handling.
parent
a4b9c878
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
27 deletions
+30
-27
Lib/logging/config.py
Lib/logging/config.py
+30
-27
No files found.
Lib/logging/config.py
View file @
79ce12e0
...
...
@@ -24,8 +24,18 @@ Copyright (C) 2001-2014 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging' and log away!
"""
import
sys
,
logging
,
logging
.
handlers
,
socket
,
struct
,
os
,
traceback
,
re
import
types
,
cStringIO
import
cStringIO
import
errno
import
io
import
logging
import
logging.handlers
import
os
import
re
import
socket
import
struct
import
sys
import
traceback
import
types
try
:
import
thread
...
...
@@ -38,10 +48,7 @@ from SocketServer import ThreadingTCPServer, StreamRequestHandler
DEFAULT_LOGGING_CONFIG_PORT
=
9030
if
sys
.
platform
==
"win32"
:
RESET_ERROR
=
10054
#WSAECONNRESET
else
:
RESET_ERROR
=
104
#ECONNRESET
RESET_ERROR
=
errno
.
ECONNRESET
#
# The following code implements a socket listener for on-the-fly
...
...
@@ -510,21 +517,21 @@ class DictConfigurator(BaseConfigurator):
level
=
handler_config
.
get
(
'level'
,
None
)
if
level
:
handler
.
setLevel
(
logging
.
_checkLevel
(
level
))
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to configure handler '
'%r: %s'
%
(
name
,
e
))
loggers
=
config
.
get
(
'loggers'
,
EMPTY_DICT
)
for
name
in
loggers
:
try
:
self
.
configure_logger
(
name
,
loggers
[
name
],
True
)
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to configure logger '
'%r: %s'
%
(
name
,
e
))
root
=
config
.
get
(
'root'
,
None
)
if
root
:
try
:
self
.
configure_root
(
root
,
True
)
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to configure root '
'logger: %s'
%
e
)
else
:
...
...
@@ -539,7 +546,7 @@ class DictConfigurator(BaseConfigurator):
try
:
formatters
[
name
]
=
self
.
configure_formatter
(
formatters
[
name
])
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to configure '
'formatter %r: %s'
%
(
name
,
e
))
# Next, do filters - they don't refer to anything else, either
...
...
@@ -547,7 +554,7 @@ class DictConfigurator(BaseConfigurator):
for
name
in
filters
:
try
:
filters
[
name
]
=
self
.
configure_filter
(
filters
[
name
])
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to configure '
'filter %r: %s'
%
(
name
,
e
))
...
...
@@ -561,7 +568,7 @@ class DictConfigurator(BaseConfigurator):
handler
=
self
.
configure_handler
(
handlers
[
name
])
handler
.
name
=
name
handlers
[
name
]
=
handler
except
StandardError
,
e
:
except
StandardError
as
e
:
if
'target not configured yet'
in
str
(
e
):
deferred
.
append
(
name
)
else
:
...
...
@@ -574,7 +581,7 @@ class DictConfigurator(BaseConfigurator):
handler
=
self
.
configure_handler
(
handlers
[
name
])
handler
.
name
=
name
handlers
[
name
]
=
handler
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to configure handler '
'%r: %s'
%
(
name
,
e
))
...
...
@@ -615,7 +622,7 @@ class DictConfigurator(BaseConfigurator):
existing
.
remove
(
name
)
try
:
self
.
configure_logger
(
name
,
loggers
[
name
])
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to configure logger '
'%r: %s'
%
(
name
,
e
))
...
...
@@ -638,7 +645,7 @@ class DictConfigurator(BaseConfigurator):
if
root
:
try
:
self
.
configure_root
(
root
)
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to configure root '
'logger: %s'
%
e
)
finally
:
...
...
@@ -650,7 +657,7 @@ class DictConfigurator(BaseConfigurator):
factory
=
config
[
'()'
]
# for use in exception handler
try
:
result
=
self
.
configure_custom
(
config
)
except
TypeError
,
te
:
except
TypeError
as
te
:
if
"'format'"
not
in
str
(
te
):
raise
#Name of parameter changed from fmt to format.
...
...
@@ -680,7 +687,7 @@ class DictConfigurator(BaseConfigurator):
for
f
in
filters
:
try
:
filterer
.
addFilter
(
self
.
config
[
'filters'
][
f
])
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to add filter %r: %s'
%
(
f
,
e
))
def
configure_handler
(
self
,
config
):
...
...
@@ -689,7 +696,7 @@ class DictConfigurator(BaseConfigurator):
if
formatter
:
try
:
formatter
=
self
.
config
[
'formatters'
][
formatter
]
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to set formatter '
'%r: %s'
%
(
formatter
,
e
))
level
=
config
.
pop
(
'level'
,
None
)
...
...
@@ -711,7 +718,7 @@ class DictConfigurator(BaseConfigurator):
config
[
'class'
]
=
cname
# restore for deferred configuration
raise
StandardError
(
'target not configured yet'
)
config
[
'target'
]
=
th
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to set target handler '
'%r: %s'
%
(
config
[
'target'
],
e
))
elif
issubclass
(
klass
,
logging
.
handlers
.
SMTPHandler
)
and
\
...
...
@@ -724,7 +731,7 @@ class DictConfigurator(BaseConfigurator):
kwargs
=
dict
([(
k
,
config
[
k
])
for
k
in
config
if
valid_ident
(
k
)])
try
:
result
=
factory
(
**
kwargs
)
except
TypeError
,
te
:
except
TypeError
as
te
:
if
"'stream'"
not
in
str
(
te
):
raise
#The argument name changed from strm to stream
...
...
@@ -746,7 +753,7 @@ class DictConfigurator(BaseConfigurator):
for
h
in
handlers
:
try
:
logger
.
addHandler
(
self
.
config
[
'handlers'
][
h
])
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to add handler %r: %s'
%
(
h
,
e
))
def
common_logger_config
(
self
,
logger
,
config
,
incremental
=
False
):
...
...
@@ -841,13 +848,9 @@ def listen(port=DEFAULT_LOGGING_CONFIG_PORT):
traceback
.
print_exc
()
if
self
.
server
.
ready
:
self
.
server
.
ready
.
set
()
except
socket
.
error
,
e
:
if
not
isinstance
(
e
.
args
,
tuple
)
:
except
socket
.
error
as
e
:
if
e
.
errno
!=
RESET_ERROR
:
raise
else
:
errcode
=
e
.
args
[
0
]
if
errcode
!=
RESET_ERROR
:
raise
class
ConfigSocketReceiver
(
ThreadingTCPServer
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment