I’m using code to generate the log like this:
# coding: utf-8
from __future__ import unicode_literals
import uno
from pathlib import Path
import logging
#====== Logging
log_all_disabled = False
my_log_level = 10 #'CRITICAL':50, 'ERROR':40, 'WARNING':30, 'INFO':20, 'DEBUG':10, 'NOTSET':0
doc = XSCRIPTCONTEXT.getDocument()
this_doc_url = doc.URL
this_doc_sys_path = uno.fileUrlToSystemPath(this_doc_url)
this_doc_parent_path = Path(this_doc_sys_path).parent
base_name = Path(this_doc_sys_path).name
only_name = str(base_name).rsplit('.ods')[0]
log_file_path = Path(this_doc_parent_path, f'''{only_name}.log''')
logger = logging.getLogger(__name__)
logger.setLevel(my_log_level)
logger.disabled = log_all_disabled
fh = logging.FileHandler(str(log_file_path), mode='w')
fh.setLevel(my_log_level)
formatter = logging.Formatter(fmt='%(asctime)s:%(levelname)s:%(filename)s:%(lineno)d:%(message)s', datefmt='%d-%m-%Y:%H:%M:%S')
fh.setFormatter(formatter)
logger.addHandler(fh)
#======
def sum(a, b, c):
print(d) #variable d is not defined
return a + b + c
def hello(*args):
logger.warning("Atention!")
def test(*args):
hello()
sum(1,2,3)
On line 32 I purposely asked to print the variable d which is not defined.
print(d) #variable d is not defined
I would like when this type of error occurred to be stored in my custom log.
How to do this?
example
logging python.ods (9,0,KB)