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
5b3cbcd4
Commit
5b3cbcd4
authored
Sep 25, 2018
by
Géry Ogam
Committed by
Vinay Sajip
Sep 25, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved the more elaborate multiprocessing example in the logging cookbook (GH-9326)
parent
f6c8007a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
29 deletions
+29
-29
Doc/howto/logging-cookbook.rst
Doc/howto/logging-cookbook.rst
+29
-29
No files found.
Doc/howto/logging-cookbook.rst
View file @
5b3cbcd4
...
...
@@ -1456,12 +1456,18 @@ works::
which then get dispatched, by the logging system, to the handlers
configured for those loggers.
"""
def handle(self, record):
logger = logging.getLogger(record.name)
# The process name is transformed just to show that it's the listener
# doing the logging to files and console
record.processName = '%s (for %s)' % (current_process().name, record.processName)
logger.handle(record)
if record.name == "root":
logger = logging.getLogger()
else:
logger = logging.getLogger(record.name)
if logger.isEnabledFor(record.levelno):
# The process name is transformed just to show that it's the listener
# doing the logging to files and console
record.processName = '%s (for %s)' % (current_process().name, record.processName)
logger.handle(record)
def listener_process(q, stop_event, config):
"""
...
...
@@ -1526,22 +1532,16 @@ works::
# The main process gets a simple configuration which prints to the console.
config_initial = {
'version': 1,
'formatters': {
'detailed': {
'class': 'logging.Formatter',
'format': '%(asctime)s %(name)-15s %(levelname)-8s %(processName)-10s %(message)s'
}
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'level': 'INFO'
,
}
,
'level': 'INFO'
}
},
'root': {
'
level': 'DEBUG'
,
'
handlers': ['console']
}
,
'
handlers': ['console']
,
'
level': 'DEBUG'
}
}
# The worker process configuration is just a QueueHandler attached to the
# root logger, which allows all messages to be sent to the queue.
...
...
@@ -1554,13 +1554,13 @@ works::
'handlers': {
'queue': {
'class': 'logging.handlers.QueueHandler',
'queue': q
,
}
,
'queue': q
}
},
'root': {
'
level': 'DEBUG'
,
'
handlers': ['queue']
}
,
'
handlers': ['queue']
,
'
level': 'DEBUG'
}
}
# The listener process configuration shows that the full flexibility of
# logging configuration is available to dispatch events to handlers however
...
...
@@ -1584,28 +1584,28 @@ works::
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'level': 'INFO',
'formatter': 'simple',
'level': 'INFO'
},
'file': {
'class': 'logging.FileHandler',
'filename': 'mplog.log',
'mode': 'w',
'formatter': 'detailed'
,
'formatter': 'detailed'
},
'foofile': {
'class': 'logging.FileHandler',
'filename': 'mplog-foo.log',
'mode': 'w',
'formatter': 'detailed'
,
'formatter': 'detailed'
},
'errors': {
'class': 'logging.FileHandler',
'filename': 'mplog-errors.log',
'mode': 'w',
'level': 'ERROR',
'formatter': 'detailed',
},
'level': 'ERROR'
}
},
'loggers': {
'foo': {
...
...
@@ -1613,9 +1613,9 @@ works::
}
},
'root': {
'
level': 'DEBUG'
,
'
handlers': ['console', 'file', 'errors']
}
,
'
handlers': ['console', 'file', 'errors']
,
'
level': 'DEBUG'
}
}
# Log some initial events, just to show that logging in the parent works
# normally.
...
...
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