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
cf9e2f24
Kaydet (Commit)
cf9e2f24
authored
Eki 09, 2012
tarafından
Vinay Sajip
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Closes #16110: fileConfig now accepts a pre-initialised ConfigParser instance.
üst
96df7da0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
9 deletions
+52
-9
logging.config.rst
Doc/library/logging.config.rst
+26
-5
config.py
Lib/logging/config.py
+7
-4
test_logging.py
Lib/test/test_logging.py
+19
-0
No files found.
Doc/library/logging.config.rst
Dosyayı görüntüle @
cf9e2f24
...
...
@@ -76,11 +76,23 @@ in :mod:`logging` itself) and defining handlers which are declared either in
..
function
::
fileConfig
(
fname
,
defaults
=
None
,
disable_existing_loggers
=
True
)
Reads
the
logging
configuration
from
a
:
mod
:`
configparser
`\-
format
file
named
*
fname
*.
This
function
can
be
called
several
times
from
an
application
,
allowing
an
end
user
to
select
from
various
pre
-
canned
configurations
(
if
the
developer
provides
a
mechanism
to
present
the
choices
and
load
the
chosen
configuration
).
Reads
the
logging
configuration
from
a
:
mod
:`
configparser
`\-
format
file
.
This
function
can
be
called
several
times
from
an
application
,
allowing
an
end
user
to
select
from
various
pre
-
canned
configurations
(
if
the
developer
provides
a
mechanism
to
present
the
choices
and
load
the
chosen
configuration
).
:
param
fname
:
A
filename
,
or
a
file
-
like
object
,
or
an
instance
derived
from
:
class
:`~
configparser
.
RawConfigParser
`.
If
a
``
RawConfigParser
``-
derived
instance
is
passed
,
it
is
used
as
is
.
Otherwise
,
a
:
class
:`~
configparser
.
Configparser
`
is
instantiated
,
and
the
configuration
read
by
it
from
the
object
passed
in
``
fname
``.
If
that
has
a
:
meth
:`
readline
`
method
,
it
is
assumed
to
be
a
file
-
like
object
and
read
using
:
meth
:`~
configparser
.
ConfigParser
.
read_file
`;
otherwise
,
it
is
assumed
to
be
a
filename
and
passed
to
:
meth
:`~
configparser
.
ConfigParser
.
read
`.
:
param
defaults
:
Defaults
to
be
passed
to
the
ConfigParser
can
be
specified
in
this
argument
.
...
...
@@ -94,6 +106,15 @@ in :mod:`logging` itself) and defining handlers which are declared either in
their
ancestors
are
explicitly
named
in
the
logging
configuration
.
..
versionchanged
::
3.4
An
instance
of
a
subclass
of
:
class
:`~
configparser
.
RawConfigParser
`
is
now
accepted
as
a
value
for
``
fname
``.
This
facilitates
:
*
Use
of
a
configuration
file
where
logging
configuration
is
just
part
of
the
overall
application
configuration
.
*
Use
of
a
configuration
read
from
a
file
,
and
then
modified
by
the
using
application
(
e
.
g
.
based
on
command
-
line
parameters
or
other
aspects
of
the
runtime
environment
)
before
being
passed
to
``
fileConfig
``.
..
function
::
listen
(
port
=
DEFAULT_LOGGING_CONFIG_PORT
,
verify
=
None
)
...
...
Lib/logging/config.py
Dosyayı görüntüle @
cf9e2f24
...
...
@@ -61,11 +61,14 @@ def fileConfig(fname, defaults=None, disable_existing_loggers=True):
"""
import
configparser
cp
=
configparser
.
ConfigParser
(
defaults
)
if
hasattr
(
fname
,
'readline'
):
cp
.
read_file
(
fname
)
if
isinstance
(
fname
,
configparser
.
RawConfigParser
):
cp
=
fname
else
:
cp
.
read
(
fname
)
cp
=
configparser
.
ConfigParser
(
defaults
)
if
hasattr
(
fname
,
'readline'
):
cp
.
read_file
(
fname
)
else
:
cp
.
read
(
fname
)
formatters
=
_create_formatters
(
cp
)
...
...
Lib/test/test_logging.py
Dosyayı görüntüle @
cf9e2f24
...
...
@@ -26,6 +26,7 @@ import logging.handlers
import
logging.config
import
codecs
import
configparser
import
datetime
import
pickle
import
io
...
...
@@ -1279,6 +1280,24 @@ class ConfigFileTest(BaseTest):
# Original logger output is empty.
self
.
assert_log_lines
([])
def
test_config0_using_cp_ok
(
self
):
# A simple config file which overrides the default settings.
with
captured_stdout
()
as
output
:
file
=
io
.
StringIO
(
textwrap
.
dedent
(
self
.
config0
))
cp
=
configparser
.
ConfigParser
()
cp
.
read_file
(
file
)
logging
.
config
.
fileConfig
(
cp
)
logger
=
logging
.
getLogger
()
# Won't output anything
logger
.
info
(
self
.
next_message
())
# Outputs a message
logger
.
error
(
self
.
next_message
())
self
.
assert_log_lines
([
(
'ERROR'
,
'2'
),
],
stream
=
output
)
# Original logger output is empty.
self
.
assert_log_lines
([])
def
test_config1_ok
(
self
,
config
=
config1
):
# A config file defining a sub-parser as well.
with
captured_stdout
()
as
output
:
...
...
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