At the end of my Python program, I'd like to be able to get a summary of the number of items logged through the standard logging
module. I'd specifically like to be able to get a count for each specified name (and possibly its children). E.g. if I have:
input_logger = getLogger('input')
input_logger.debug("got input1")
input_logger.debug("got input2")
input_logger.debug("got input3")
network_input_logger = getLogger('input.network')
network_input_logger.debug("got network input1")
network_input_logger.debug("got network input2")
getLogger('output')
output_logger.debug("sent output1")
Then at the end I'd like to get a summary such as:
input: 5
input.network: 2
output: 1
I'm thinking, by calling a getcount()
method for a logger or a handler.
What would be a good way to achieve this? I imagine it would involve a sub-class of one of the classes in the logging
module, but I'm not sure what would be the best way to go.