At the end of my Python program, I want to be able to get a summary of the number of log-in items Specifically I want to be able to get a count for every specific name (and possibly its children). Like if I have:
input_logger = getLogger ('input') input_logger.debug ("input 1 is found") input_logger.debug ("found input2") input_logger.debug ("input3 Finally, I want to receive a summary: Input: 5 input.network: 2 Output: 1 < / Code>
I'm thinking, by calling getcount ()
method for a lodge or handler.
A good way to get it What will happen? I think in the logging module
One sub-class of one of the classes will be included, but I'm not sure what will be the best way to go.
Using decorator can be very elegant, I have not tested it but such a thing can work:
class myDecorator (object): def __init __ ( Self.log = name] = self.log.get (name, 0) 1 return gateway (self-winner, self, Name) def __setattr __ (self, name, value): Setter (self-winner, name, value)
I know that you do not want to log the number of calls on each method but each is different Calling the logger is all the same I think a decorator can be beautiful elegant.
I do not think I have enough sleep, this idea will be to wrap the caller to your logger, I'm using a decorator with decorator pattern (actually mixing patterns and syntax a great The answer will be)
Here's a more complete solution, I'm sorry, I realized I was.
class logger logger (object): def __init __ (self, internal, name): self. Manufacturer = Internal Self Coles = 0 Df __Coll __ (self, * Args, ** kwargs): self.calls + = 1 return self The winner (* argets, ** kwargs) def loggerDecorator (func): def internal (name): logger = func (name) logger.debug = LoggerLogger (Lojor.Debug, Name) Inner getLogger = Logger Decokerator (Mill Logger)
Comments
Post a Comment