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.
...
@@ -24,8 +24,18 @@ Copyright (C) 2001-2014 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging' and log away!
To use, simply 'import logging' and log away!
"""
"""
import
sys
,
logging
,
logging
.
handlers
,
socket
,
struct
,
os
,
traceback
,
re
import
cStringIO
import
types
,
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
:
try
:
import
thread
import
thread
...
@@ -38,10 +48,7 @@ from SocketServer import ThreadingTCPServer, StreamRequestHandler
...
@@ -38,10 +48,7 @@ from SocketServer import ThreadingTCPServer, StreamRequestHandler
DEFAULT_LOGGING_CONFIG_PORT
=
9030
DEFAULT_LOGGING_CONFIG_PORT
=
9030
if
sys
.
platform
==
"win32"
:
RESET_ERROR
=
errno
.
ECONNRESET
RESET_ERROR
=
10054
#WSAECONNRESET
else
:
RESET_ERROR
=
104
#ECONNRESET
#
#
# The following code implements a socket listener for on-the-fly
# The following code implements a socket listener for on-the-fly
...
@@ -510,21 +517,21 @@ class DictConfigurator(BaseConfigurator):
...
@@ -510,21 +517,21 @@ class DictConfigurator(BaseConfigurator):
level
=
handler_config
.
get
(
'level'
,
None
)
level
=
handler_config
.
get
(
'level'
,
None
)
if
level
:
if
level
:
handler
.
setLevel
(
logging
.
_checkLevel
(
level
))
handler
.
setLevel
(
logging
.
_checkLevel
(
level
))
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to configure handler '
raise
ValueError
(
'Unable to configure handler '
'%r: %s'
%
(
name
,
e
))
'%r: %s'
%
(
name
,
e
))
loggers
=
config
.
get
(
'loggers'
,
EMPTY_DICT
)
loggers
=
config
.
get
(
'loggers'
,
EMPTY_DICT
)
for
name
in
loggers
:
for
name
in
loggers
:
try
:
try
:
self
.
configure_logger
(
name
,
loggers
[
name
],
True
)
self
.
configure_logger
(
name
,
loggers
[
name
],
True
)
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to configure logger '
raise
ValueError
(
'Unable to configure logger '
'%r: %s'
%
(
name
,
e
))
'%r: %s'
%
(
name
,
e
))
root
=
config
.
get
(
'root'
,
None
)
root
=
config
.
get
(
'root'
,
None
)
if
root
:
if
root
:
try
:
try
:
self
.
configure_root
(
root
,
True
)
self
.
configure_root
(
root
,
True
)
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to configure root '
raise
ValueError
(
'Unable to configure root '
'logger: %s'
%
e
)
'logger: %s'
%
e
)
else
:
else
:
...
@@ -539,7 +546,7 @@ class DictConfigurator(BaseConfigurator):
...
@@ -539,7 +546,7 @@ class DictConfigurator(BaseConfigurator):
try
:
try
:
formatters
[
name
]
=
self
.
configure_formatter
(
formatters
[
name
]
=
self
.
configure_formatter
(
formatters
[
name
])
formatters
[
name
])
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to configure '
raise
ValueError
(
'Unable to configure '
'formatter %r: %s'
%
(
name
,
e
))
'formatter %r: %s'
%
(
name
,
e
))
# Next, do filters - they don't refer to anything else, either
# Next, do filters - they don't refer to anything else, either
...
@@ -547,7 +554,7 @@ class DictConfigurator(BaseConfigurator):
...
@@ -547,7 +554,7 @@ class DictConfigurator(BaseConfigurator):
for
name
in
filters
:
for
name
in
filters
:
try
:
try
:
filters
[
name
]
=
self
.
configure_filter
(
filters
[
name
])
filters
[
name
]
=
self
.
configure_filter
(
filters
[
name
])
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to configure '
raise
ValueError
(
'Unable to configure '
'filter %r: %s'
%
(
name
,
e
))
'filter %r: %s'
%
(
name
,
e
))
...
@@ -561,7 +568,7 @@ class DictConfigurator(BaseConfigurator):
...
@@ -561,7 +568,7 @@ class DictConfigurator(BaseConfigurator):
handler
=
self
.
configure_handler
(
handlers
[
name
])
handler
=
self
.
configure_handler
(
handlers
[
name
])
handler
.
name
=
name
handler
.
name
=
name
handlers
[
name
]
=
handler
handlers
[
name
]
=
handler
except
StandardError
,
e
:
except
StandardError
as
e
:
if
'target not configured yet'
in
str
(
e
):
if
'target not configured yet'
in
str
(
e
):
deferred
.
append
(
name
)
deferred
.
append
(
name
)
else
:
else
:
...
@@ -574,7 +581,7 @@ class DictConfigurator(BaseConfigurator):
...
@@ -574,7 +581,7 @@ class DictConfigurator(BaseConfigurator):
handler
=
self
.
configure_handler
(
handlers
[
name
])
handler
=
self
.
configure_handler
(
handlers
[
name
])
handler
.
name
=
name
handler
.
name
=
name
handlers
[
name
]
=
handler
handlers
[
name
]
=
handler
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to configure handler '
raise
ValueError
(
'Unable to configure handler '
'%r: %s'
%
(
name
,
e
))
'%r: %s'
%
(
name
,
e
))
...
@@ -615,7 +622,7 @@ class DictConfigurator(BaseConfigurator):
...
@@ -615,7 +622,7 @@ class DictConfigurator(BaseConfigurator):
existing
.
remove
(
name
)
existing
.
remove
(
name
)
try
:
try
:
self
.
configure_logger
(
name
,
loggers
[
name
])
self
.
configure_logger
(
name
,
loggers
[
name
])
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to configure logger '
raise
ValueError
(
'Unable to configure logger '
'%r: %s'
%
(
name
,
e
))
'%r: %s'
%
(
name
,
e
))
...
@@ -638,7 +645,7 @@ class DictConfigurator(BaseConfigurator):
...
@@ -638,7 +645,7 @@ class DictConfigurator(BaseConfigurator):
if
root
:
if
root
:
try
:
try
:
self
.
configure_root
(
root
)
self
.
configure_root
(
root
)
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to configure root '
raise
ValueError
(
'Unable to configure root '
'logger: %s'
%
e
)
'logger: %s'
%
e
)
finally
:
finally
:
...
@@ -650,7 +657,7 @@ class DictConfigurator(BaseConfigurator):
...
@@ -650,7 +657,7 @@ class DictConfigurator(BaseConfigurator):
factory
=
config
[
'()'
]
# for use in exception handler
factory
=
config
[
'()'
]
# for use in exception handler
try
:
try
:
result
=
self
.
configure_custom
(
config
)
result
=
self
.
configure_custom
(
config
)
except
TypeError
,
te
:
except
TypeError
as
te
:
if
"'format'"
not
in
str
(
te
):
if
"'format'"
not
in
str
(
te
):
raise
raise
#Name of parameter changed from fmt to format.
#Name of parameter changed from fmt to format.
...
@@ -680,7 +687,7 @@ class DictConfigurator(BaseConfigurator):
...
@@ -680,7 +687,7 @@ class DictConfigurator(BaseConfigurator):
for
f
in
filters
:
for
f
in
filters
:
try
:
try
:
filterer
.
addFilter
(
self
.
config
[
'filters'
][
f
])
filterer
.
addFilter
(
self
.
config
[
'filters'
][
f
])
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to add filter %r: %s'
%
(
f
,
e
))
raise
ValueError
(
'Unable to add filter %r: %s'
%
(
f
,
e
))
def
configure_handler
(
self
,
config
):
def
configure_handler
(
self
,
config
):
...
@@ -689,7 +696,7 @@ class DictConfigurator(BaseConfigurator):
...
@@ -689,7 +696,7 @@ class DictConfigurator(BaseConfigurator):
if
formatter
:
if
formatter
:
try
:
try
:
formatter
=
self
.
config
[
'formatters'
][
formatter
]
formatter
=
self
.
config
[
'formatters'
][
formatter
]
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to set formatter '
raise
ValueError
(
'Unable to set formatter '
'%r: %s'
%
(
formatter
,
e
))
'%r: %s'
%
(
formatter
,
e
))
level
=
config
.
pop
(
'level'
,
None
)
level
=
config
.
pop
(
'level'
,
None
)
...
@@ -711,7 +718,7 @@ class DictConfigurator(BaseConfigurator):
...
@@ -711,7 +718,7 @@ class DictConfigurator(BaseConfigurator):
config
[
'class'
]
=
cname
# restore for deferred configuration
config
[
'class'
]
=
cname
# restore for deferred configuration
raise
StandardError
(
'target not configured yet'
)
raise
StandardError
(
'target not configured yet'
)
config
[
'target'
]
=
th
config
[
'target'
]
=
th
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to set target handler '
raise
ValueError
(
'Unable to set target handler '
'%r: %s'
%
(
config
[
'target'
],
e
))
'%r: %s'
%
(
config
[
'target'
],
e
))
elif
issubclass
(
klass
,
logging
.
handlers
.
SMTPHandler
)
and
\
elif
issubclass
(
klass
,
logging
.
handlers
.
SMTPHandler
)
and
\
...
@@ -724,7 +731,7 @@ class DictConfigurator(BaseConfigurator):
...
@@ -724,7 +731,7 @@ class DictConfigurator(BaseConfigurator):
kwargs
=
dict
([(
k
,
config
[
k
])
for
k
in
config
if
valid_ident
(
k
)])
kwargs
=
dict
([(
k
,
config
[
k
])
for
k
in
config
if
valid_ident
(
k
)])
try
:
try
:
result
=
factory
(
**
kwargs
)
result
=
factory
(
**
kwargs
)
except
TypeError
,
te
:
except
TypeError
as
te
:
if
"'stream'"
not
in
str
(
te
):
if
"'stream'"
not
in
str
(
te
):
raise
raise
#The argument name changed from strm to stream
#The argument name changed from strm to stream
...
@@ -746,7 +753,7 @@ class DictConfigurator(BaseConfigurator):
...
@@ -746,7 +753,7 @@ class DictConfigurator(BaseConfigurator):
for
h
in
handlers
:
for
h
in
handlers
:
try
:
try
:
logger
.
addHandler
(
self
.
config
[
'handlers'
][
h
])
logger
.
addHandler
(
self
.
config
[
'handlers'
][
h
])
except
StandardError
,
e
:
except
StandardError
as
e
:
raise
ValueError
(
'Unable to add handler %r: %s'
%
(
h
,
e
))
raise
ValueError
(
'Unable to add handler %r: %s'
%
(
h
,
e
))
def
common_logger_config
(
self
,
logger
,
config
,
incremental
=
False
):
def
common_logger_config
(
self
,
logger
,
config
,
incremental
=
False
):
...
@@ -841,13 +848,9 @@ def listen(port=DEFAULT_LOGGING_CONFIG_PORT):
...
@@ -841,13 +848,9 @@ def listen(port=DEFAULT_LOGGING_CONFIG_PORT):
traceback
.
print_exc
()
traceback
.
print_exc
()
if
self
.
server
.
ready
:
if
self
.
server
.
ready
:
self
.
server
.
ready
.
set
()
self
.
server
.
ready
.
set
()
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
if
not
isinstance
(
e
.
args
,
tuple
)
:
if
e
.
errno
!=
RESET_ERROR
:
raise
raise
else
:
errcode
=
e
.
args
[
0
]
if
errcode
!=
RESET_ERROR
:
raise
class
ConfigSocketReceiver
(
ThreadingTCPServer
):
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