source: loggingpy/tudelft_utilities_logging/ReportToLogger.py@ 1271

Last change on this file since 1271 was 949, checked in by wouter, 4 months ago

#321 loggging python 1.1.0 now includes ReportToFile and ReportToLog now writes to stdout.

File size: 876 bytes
Line 
1from logging import Logger
2import logging
3from typing import cast
4
5from tudelft_utilities_logging.Reporter import Reporter
6
7
8# initialize the logging, otherwise it seems not to work properly
9logging.basicConfig()
10
11class ReportToLogger ( Reporter ):
12 '''
13 dumps the reported messages into a log file with the
14 given name.
15 This really tries hard to avoid any writing to
16 stdout/stderr, because those are used
17 for the communicatino to the party.
18 '''
19
20 def __init__(self, logname:str):
21 '''
22 @param logname the name for the Logger
23 '''
24 super().__init__()
25 self._logger:Logger = logging.getLogger(logname)
26
27 def log(self, level:int , msg:str, thrown: BaseException=None) -> None:
28 # We use the internal function, the only way to include our exception...
29 self._logger._log(level=level, msg=msg, args=[], exc_info=thrown,\
30 stack_info=True if thrown else False)
31
32
33
Note: See TracBrowser for help on using the repository browser.