@@ -1456,12 +1456,18 @@ works::
1456
1456
which then get dispatched, by the logging system, to the handlers
1457
1457
configured for those loggers.
1458
1458
"""
1459
+
1459
1460
def handle(self, record):
1460
- logger = logging.getLogger(record.name)
1461
- # The process name is transformed just to show that it's the listener
1462
- # doing the logging to files and console
1463
- record.processName = '%s (for %s)' % (current_process().name, record.processName)
1464
- logger.handle(record)
1461
+ if record.name == "root":
1462
+ logger = logging.getLogger()
1463
+ else:
1464
+ logger = logging.getLogger(record.name)
1465
+
1466
+ if logger.isEnabledFor(record.levelno):
1467
+ # The process name is transformed just to show that it's the listener
1468
+ # doing the logging to files and console
1469
+ record.processName = '%s (for %s)' % (current_process().name, record.processName)
1470
+ logger.handle(record)
1465
1471
1466
1472
def listener_process(q, stop_event, config):
1467
1473
"""
@@ -1526,22 +1532,16 @@ works::
1526
1532
# The main process gets a simple configuration which prints to the console.
1527
1533
config_initial = {
1528
1534
'version': 1,
1529
- 'formatters': {
1530
- 'detailed': {
1531
- 'class': 'logging.Formatter',
1532
- 'format': '%(asctime)s %(name)-15s %(levelname)-8s %(processName)-10s %(message)s'
1533
- }
1534
- },
1535
1535
'handlers': {
1536
1536
'console': {
1537
1537
'class': 'logging.StreamHandler',
1538
- 'level': 'INFO',
1539
- },
1538
+ 'level': 'INFO'
1539
+ }
1540
1540
},
1541
1541
'root': {
1542
- 'level ': 'DEBUG' ,
1543
- 'handlers ': ['console']
1544
- },
1542
+ 'handlers ': ['console'] ,
1543
+ 'level ': 'DEBUG'
1544
+ }
1545
1545
}
1546
1546
# The worker process configuration is just a QueueHandler attached to the
1547
1547
# root logger, which allows all messages to be sent to the queue.
@@ -1554,13 +1554,13 @@ works::
1554
1554
'handlers': {
1555
1555
'queue': {
1556
1556
'class': 'logging.handlers.QueueHandler',
1557
- 'queue': q,
1558
- },
1557
+ 'queue': q
1558
+ }
1559
1559
},
1560
1560
'root': {
1561
- 'level ': 'DEBUG' ,
1562
- 'handlers ': ['queue']
1563
- },
1561
+ 'handlers ': ['queue'] ,
1562
+ 'level ': 'DEBUG'
1563
+ }
1564
1564
}
1565
1565
# The listener process configuration shows that the full flexibility of
1566
1566
# logging configuration is available to dispatch events to handlers however
@@ -1584,38 +1584,38 @@ works::
1584
1584
'handlers': {
1585
1585
'console': {
1586
1586
'class': 'logging.StreamHandler',
1587
- 'level': 'INFO',
1588
1587
'formatter': 'simple',
1588
+ 'level': 'INFO'
1589
1589
},
1590
1590
'file': {
1591
1591
'class': 'logging.FileHandler',
1592
1592
'filename': 'mplog.log',
1593
1593
'mode': 'w',
1594
- 'formatter': 'detailed',
1594
+ 'formatter': 'detailed'
1595
1595
},
1596
1596
'foofile': {
1597
1597
'class': 'logging.FileHandler',
1598
1598
'filename': 'mplog-foo.log',
1599
1599
'mode': 'w',
1600
- 'formatter': 'detailed',
1600
+ 'formatter': 'detailed'
1601
1601
},
1602
1602
'errors': {
1603
1603
'class': 'logging.FileHandler',
1604
1604
'filename': 'mplog-errors.log',
1605
1605
'mode': 'w',
1606
- 'level': 'ERROR',
1607
1606
'formatter': 'detailed',
1608
- },
1607
+ 'level': 'ERROR'
1608
+ }
1609
1609
},
1610
1610
'loggers': {
1611
1611
'foo': {
1612
1612
'handlers': ['foofile']
1613
1613
}
1614
1614
},
1615
1615
'root': {
1616
- 'level ': 'DEBUG' ,
1617
- 'handlers ': ['console', 'file', 'errors']
1618
- },
1616
+ 'handlers ': ['console', 'file', 'errors'] ,
1617
+ 'level ': 'DEBUG'
1618
+ }
1619
1619
}
1620
1620
# Log some initial events, just to show that logging in the parent works
1621
1621
# normally.
0 commit comments