Reputation: 15
i write this logger
import logging
class ThreadLogger:
def __init__(self):
self.logger = logging.getLogger("ThreadsLogging")
f_handler = logging.FileHandler("logs/thread.log", mode="a")
f_handler.setLevel(logging.INFO)
f_format = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
f_handler.setFormatter(f_format)
self.logger.addHandler(f_handler)
def info_log(self, msg):
self.logger.info(msg)
But after call info_log(msg)
file threads.log is empty. I change and delete mode in FileHandler but it dosen't help me
Upvotes: 0
Views: 424
Reputation: 5195
Handlers and loggers both can have levels. You didn't set the level on the logger. Add self.logger.setLevel(logging.INFO)
inside of your __init__
and it will work.
Upvotes: 1