I have a function that should print in terminal a message and append it to file. It uses Python Logger.
@staticmethod
def Log(iv_level, iv_style, iv_domain, iv_number, *args):
"""
Log messages
"""
# Do not log message with insufficient level
lv_log_level = Logger.LOG_LEVEL
if lv_log_level > iv_level:
return
if iv_level == Logger.VERBOSE:
iv_level = logging.DEBUG
# Default output format
try:
logging.basicConfig(filename='logs/logs.log', level=lv_log_level, format='%(asctime)s | %(levelname)s | %(message)s')
except:
logging.basicConfig(filename='server/logs/logs.log', level=lv_log_level, format='%(asctime)s | %(levelname)s | %(message)s')
lo_logger = logging.getLogger(iv_domain)
# Fetch message from database and log it to file
# Log message are always in English
ev_message = FrontendMessage.get(iv_domain, iv_number, *args, lang="en", buffer=True)['short_text']
# Log into file only if environment is local
if settings.SERVER_ENVIRONMENT == "-local":
if platform == "win32" :
# ! When I execute it pass thought the next step but doesn't write in logs/logs.log as it should
lo_logger.log(iv_level, iv_domain + ' | ' + str(iv_number) + ' | ' + ev_message.replace('\U0001f4be','').replace('\U0001f3e2','').replace('\U0001f538','').replace('\U0001f535','').replace('\U0001f50e','').replace('\u2705','').replace('\u200d','').replace('\U0001F469','').replace('\u2695','').replace('\uFE0F','').replace('\U0001f464',''), extra={
"message_info": {
"domain": iv_domain,
"number": iv_number
}
})
else:
lo_logger.log(iv_level, iv_domain + ' | ' + str(iv_number) + ' | ' + ev_message, extra={
"message_info": {
"domain": iv_domain,
"number": iv_number
}
})
# Print message
print(stylize(ev_message, iv_style))
return ev_message
When I execute this code, it works fine and pass thought lo_logger.log(...) but nothing is written in file. I can't find or understand what I missed...