P
P
Pavel-a87avfdv87isrh57ghh2020-05-22 15:42:35
Python
Pavel-a87avfdv87isrh57ghh, 2020-05-22 15:42:35

How to make the necessary getLogging registered?

Hello.

I have multiple getLogger. Namely: getLogger('a'), getLogger('b'), getLogger('c'), getLogger('d').
How can I make it so that only getLogger('b') and getLogger('c') are logged in now?

logging.basicConfig(level=logging.DEBUG , filename=path_logging,  format='%(lineno)d :: %(name)s :: %(levelname)s :: %(module)s :: %(asctime)s :: %(message)s')
logger = logging.getLogger('a')
logger_2 = logging.getLogger('b')
logger_3 = logging.getLogger('c')
logger_4 = logging.getLogger('d')


And then I read the documentation and I can’t understand it in any way ...

Help with good advice)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
ediboba, 2020-05-22
@Pavel-a87avfdv87isrh57ghh

do not through basicConfig, but write your own get_logger function in which we add the necessary handlers. Then we get what we need using our custom function.
For example:

def get_logger(logger_name: str) -> logging.Logger:
    logger = logging.getLogger(logger_name)
    logger.setLevel(logging.INFO)
    logger.addHandler(get_console_handler())
    logger.addHandler(get_file_handler())
    logger.propagate = False
    return logger

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question