Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
3f885b54
Kaydet (Commit)
3f885b54
authored
Mar 22, 2013
tarafından
Vinay Sajip
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #17508: Handled out-of-order handler configuration correctly.
üst
d5537d07
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
6 deletions
+60
-6
config.py
Lib/logging/config.py
+24
-4
test_logging.py
Lib/test/test_logging.py
+36
-2
No files found.
Lib/logging/config.py
Dosyayı görüntüle @
3f885b54
# Copyright 2001-201
0
by Vinay Sajip. All Rights Reserved.
# Copyright 2001-201
3
by Vinay Sajip. All Rights Reserved.
#
#
# Permission to use, copy, modify, and distribute this software and its
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# documentation for any purpose and without fee is hereby granted,
...
@@ -19,7 +19,7 @@ Configuration functions for the logging package for Python. The core package
...
@@ -19,7 +19,7 @@ Configuration functions for the logging package for Python. The core package
is based on PEP 282 and comments thereto in comp.lang.python, and influenced
is based on PEP 282 and comments thereto in comp.lang.python, and influenced
by Apache's log4j system.
by Apache's log4j system.
Copyright (C) 2001-201
0
Vinay Sajip. All Rights Reserved.
Copyright (C) 2001-201
3
Vinay Sajip. All Rights Reserved.
To use, simply 'import logging' and log away!
To use, simply 'import logging' and log away!
"""
"""
...
@@ -564,7 +564,21 @@ class DictConfigurator(BaseConfigurator):
...
@@ -564,7 +564,21 @@ class DictConfigurator(BaseConfigurator):
# As handlers can refer to other handlers, sort the keys
# As handlers can refer to other handlers, sort the keys
# to allow a deterministic order of configuration
# to allow a deterministic order of configuration
handlers
=
config
.
get
(
'handlers'
,
EMPTY_DICT
)
handlers
=
config
.
get
(
'handlers'
,
EMPTY_DICT
)
deferred
=
[]
for
name
in
sorted
(
handlers
):
for
name
in
sorted
(
handlers
):
try
:
handler
=
self
.
configure_handler
(
handlers
[
name
])
handler
.
name
=
name
handlers
[
name
]
=
handler
except
Exception
as
e
:
if
'target not configured yet'
in
str
(
e
):
deferred
.
append
(
name
)
else
:
raise
ValueError
(
'Unable to configure handler '
'
%
r:
%
s'
%
(
name
,
e
))
# Now do any that were deferred
for
name
in
deferred
:
try
:
try
:
handler
=
self
.
configure_handler
(
handlers
[
name
])
handler
=
self
.
configure_handler
(
handlers
[
name
])
handler
.
name
=
name
handler
.
name
=
name
...
@@ -572,6 +586,7 @@ class DictConfigurator(BaseConfigurator):
...
@@ -572,6 +586,7 @@ class DictConfigurator(BaseConfigurator):
except
Exception
as
e
:
except
Exception
as
e
:
raise
ValueError
(
'Unable to configure handler '
raise
ValueError
(
'Unable to configure handler '
'
%
r:
%
s'
%
(
name
,
e
))
'
%
r:
%
s'
%
(
name
,
e
))
# Next, do loggers - they refer to handlers and filters
# Next, do loggers - they refer to handlers and filters
#we don't want to lose the existing loggers,
#we don't want to lose the existing loggers,
...
@@ -694,12 +709,17 @@ class DictConfigurator(BaseConfigurator):
...
@@ -694,12 +709,17 @@ class DictConfigurator(BaseConfigurator):
c
=
self
.
resolve
(
c
)
c
=
self
.
resolve
(
c
)
factory
=
c
factory
=
c
else
:
else
:
klass
=
self
.
resolve
(
config
.
pop
(
'class'
))
cname
=
config
.
pop
(
'class'
)
klass
=
self
.
resolve
(
cname
)
#Special case for handler which refers to another handler
#Special case for handler which refers to another handler
if
issubclass
(
klass
,
logging
.
handlers
.
MemoryHandler
)
and
\
if
issubclass
(
klass
,
logging
.
handlers
.
MemoryHandler
)
and
\
'target'
in
config
:
'target'
in
config
:
try
:
try
:
config
[
'target'
]
=
self
.
config
[
'handlers'
][
config
[
'target'
]]
th
=
self
.
config
[
'handlers'
][
config
[
'target'
]]
if
not
isinstance
(
th
,
logging
.
Handler
):
config
[
'class'
]
=
cname
# restore for deferred configuration
raise
TypeError
(
'target not configured yet'
)
config
[
'target'
]
=
th
except
Exception
as
e
:
except
Exception
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
))
...
...
Lib/test/test_logging.py
Dosyayı görüntüle @
3f885b54
#!/usr/bin/env python
#!/usr/bin/env python
#
#
# Copyright 2001-201
2
by Vinay Sajip. All Rights Reserved.
# Copyright 2001-201
3
by Vinay Sajip. All Rights Reserved.
#
#
# Permission to use, copy, modify, and distribute this software and its
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# documentation for any purpose and without fee is hereby granted,
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
"""Test harness for the logging module. Run all tests.
"""Test harness for the logging module. Run all tests.
Copyright (C) 2001-201
2
Vinay Sajip. All Rights Reserved.
Copyright (C) 2001-201
3
Vinay Sajip. All Rights Reserved.
"""
"""
import
logging
import
logging
...
@@ -1696,6 +1696,36 @@ class ConfigDictTest(BaseTest):
...
@@ -1696,6 +1696,36 @@ class ConfigDictTest(BaseTest):
},
},
}
}
out_of_order
=
{
"version"
:
1
,
"formatters"
:
{
"mySimpleFormatter"
:
{
"format"
:
"
%(asctime)
s (
%(name)
s)
%(levelname)
s:
%(message)
s"
}
},
"handlers"
:
{
"fileGlobal"
:
{
"class"
:
"logging.StreamHandler"
,
"level"
:
"DEBUG"
,
"formatter"
:
"mySimpleFormatter"
},
"bufferGlobal"
:
{
"class"
:
"logging.handlers.MemoryHandler"
,
"capacity"
:
5
,
"formatter"
:
"mySimpleFormatter"
,
"target"
:
"fileGlobal"
,
"level"
:
"DEBUG"
}
},
"loggers"
:
{
"mymodule"
:
{
"level"
:
"DEBUG"
,
"handlers"
:
[
"bufferGlobal"
],
"propagate"
:
"true"
}
}
}
def
apply_config
(
self
,
conf
):
def
apply_config
(
self
,
conf
):
logging
.
config
.
dictConfig
(
conf
)
logging
.
config
.
dictConfig
(
conf
)
...
@@ -1994,6 +2024,10 @@ class ConfigDictTest(BaseTest):
...
@@ -1994,6 +2024,10 @@ class ConfigDictTest(BaseTest):
# Original logger output is empty.
# Original logger output is empty.
self
.
assert_log_lines
([])
self
.
assert_log_lines
([])
def
test_out_of_order
(
self
):
self
.
apply_config
(
self
.
out_of_order
)
handler
=
logging
.
getLogger
(
'mymodule'
)
.
handlers
[
0
]
self
.
assertIsInstance
(
handler
.
target
,
logging
.
Handler
)
class
ManagerTest
(
BaseTest
):
class
ManagerTest
(
BaseTest
):
def
test_manager_loggerclass
(
self
):
def
test_manager_loggerclass
(
self
):
...
...
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