1

I want to disable my script to print the INFO, DEBUG, WARNING or ERROR from logging commands and just have this inside the .log or .err. Here is the configuration I have:

def log(routine_name):
    """ Logging configuration """
    logger = logging.getLogger(_name_)
    logger.setLevel(logging.INFO)
    logging.StreamHandler(stream=None)

    formatter = logging.Formatter("%(asctime)s:%(levelname)s:%(name)s:%(message)s")

    file_handler = logging.FileHandler(routine_name)
    file_handler.setFormatter(formatter)

    error_handler = logging.FileHandler(routine_name.replace("log", "err"))
    error_handler.setFormatter(formatter)
    error_handler.setLevel(logging.ERROR)

    stream_handler = logging.StreamHandler()
    stream_handler.setFormatter(formatter)

    logger.addHandler(file_handler)
    logger.addHandler(stream_handler)
    logger.addHandler(error_handler)
    
    return logger

I have tried to set logger.propagate = False from this post but didn't work, it still printing everything.

Thanks

1 Answer 1

1

For me this did work with module.submodule issuing the logging commands

logger = logging.getLogger("module.submodule")
fh = logging.FileHandler("logfile")
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)
logger.disabled = True
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.