Issue 26999: Add child separator keyword to logging.basicConfig and use it in Logger.getChild() (original) (raw)

Created on 2016-05-11 13:11 by Richard Neumann, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
logger.patch Richard Neumann,2016-05-12 10:34
Messages (6)
msg265312 - (view) Author: Richard Neumann (Richard Neumann) Date: 2016-05-11 13:11
Currently Python's logging library has the Child-Separator hard-coded in Logger.getChild() as '.'. It would be useful to have the ability to preset this via an optional basicConfig() argument like 'child_sep=' and preset it to '.' to retain the current behaviour. In my case I will need to monkey-patch the getChild() method to use a different separator ('->') because I use '.' for different purposes within the loggers' names. The current behaviour would lead to ugly and mistakable output.
msg265379 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2016-05-12 08:27
This is a change with wide-ranging ramifications. I don't propose to do this, as the use of '.' as a logging separator mirrors the separator used in the Python package namespace. Logger names are supposed to indicate the "where" of a logging event - nothing more.
msg265381 - (view) Author: Richard Neumann (Richard Neumann) Date: 2016-05-12 08:40
I am using loggers and sub-loggers (getChild()) in classes, which contain sub-classes, wich contain sub-sub-classes and so on for complex data processing. Hence I was using the logging library with sub-loggers to see in which of the (sub-)classes things happen. Most classes are, however, instanced for different configuration and are represented by strings like {instance_config}@{class_name} where {instance_config} often contains dots as separators for IDs. Example: INFO 1000@TerminalsSyncer : Aggregating customer data: 1031002@Facebook INFO 1000@TerminalsSyncer : Aggregating virtual data: v60.1031002@Config INFO 1000@TerminalsSyncer : Aggregating virtual data: v60.1031002@Presentation WARNING 1000@TerminalsSyncer->1.1000@TerminalSyncer: Terminal 1.1000 is offline However, if you still think that this is not, what the logging library is meant for, I'd appreciate to know.
msg265383 - (view) Author: Richard Neumann (Richard Neumann) Date: 2016-05-12 09:03
PS: @vinay.sajip You do realize that I want this argument to be optional and to retain '.' as default setting in order to keep the current behaviour?!
msg265385 - (view) Author: Richard Neumann (Richard Neumann) Date: 2016-05-12 09:16
Added proposed patch
msg265433 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2016-05-12 22:57
> However, if you still think that this is not, what the logging library is meant for, I'd appreciate to know. Confirmed. I would advise against using logger names in this way.
History
Date User Action Args
2022-04-11 14:58:30 admin set github: 71186
2016-05-12 22:57:27 vinay.sajip set messages: +
2016-05-12 10:34:22 Richard Neumann set files: + logger.patch
2016-05-12 09:34:56 Richard Neumann set files: - logger.patch
2016-05-12 09:16:17 Richard Neumann set files: + logger.patchkeywords: + patchmessages: +
2016-05-12 09:03:01 Richard Neumann set messages: +
2016-05-12 08:40:52 Richard Neumann set messages: +
2016-05-12 08:27:57 vinay.sajip set status: open -> closedresolution: wont fixmessages: +
2016-05-11 18:12:22 SilentGhost set nosy: + vinay.sajipversions: + Python 3.6, - Python 3.5
2016-05-11 13:11:54 Richard Neumann set title: Add child seperator keyword to logging.basicConfig and use it in Logger.getChild() -> Add child separator keyword to logging.basicConfig and use it in Logger.getChild()
2016-05-11 13:11:07 Richard Neumann create