I amended the code with my own “file handler” - outside LO that works fine.
class LogHandler(logging.Handler):
"""
Class to write log files in a self defined source (string or calc sheet)
"""
def __init__(self):
logging.Handler.__init__(self)
def format(self, record: logging.LogRecord) -> str:
return record.__dict__
def emit(self, record):
print(format(record))
print(type(format(record)))
def close(self):
logging.Handler.close(self)
class Logger_decorator():
def __init__(self, function):
LOGLEVEL = 10
self.function = function
self.logger = logging.getLogger(self.function.__name__)
#self.fh = logging.FileHandler(log_path, mode='w')
self.fh = LogHandler()
#self.fh.setLevel(LOGLEVEL)
formatter = logging.Formatter(fmt='%(asctime)s:%(levelname)s:%(filename)s:%(lineno)d:%(message)s',
datefmt='%Y-%m-%d-%H:%M:%S')
self.fh.setFormatter(formatter)
self.format = formatter
self.logger.addHandler(self.fh)
def __call__(self, *args, **kwargs):
try:
return self.function(*args,**kwargs)
except Exception as ex:
self.logger.exception(ex)
But when I replace the print statements in emit with writing into calc-sheets I get a type error. I hope this only a conversion issue