comparison velib_python/tracing.py @ 8:9c0435a617db

Import velib_python
author Daniel O'Connor <darius@dons.net.au>
date Sun, 05 Dec 2021 14:35:36 +1030
parents
children
comparison
equal deleted inserted replaced
5:982eeffe9d95 8:9c0435a617db
1 ## IMPORTANT NOTE - MVA 2015-2-5
2 # This file is deprecated. Use the standard logging package of Python instead
3
4 ## @package tracing
5 # The tracing module for debug-purpose.
6
7 log = None
8
9 ## Setup the debug traces.
10 # The traces can be logged to console and/or file.
11 # When logged to file a logrotate is used.
12 # @param enabled When True traces are enabled.
13 # @param path The path for the trace-file.
14 # @param fileName The trace-file-name.
15 # @param toConsole When True show traces to console.
16 # @param debugOn When True show debug-traces.
17 def setupTraces(enabled, path, fileName, toConsole, toFile, debugOn):
18 global log
19
20 if enabled:
21 import logging
22 import logging.handlers
23
24 log = logging.getLogger(fileName)
25 if debugOn == True:
26 level = logging.DEBUG
27 else:
28 level = logging.INFO
29 log.setLevel(level)
30 log.disabled = not enabled
31 if toConsole == True:
32 sth = logging.StreamHandler()
33 fmt = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
34 sth.setFormatter(fmt)
35 sth.setLevel(level)
36 log.addHandler(sth)
37 if toFile == True:
38 fd = logging.handlers.RotatingFileHandler(path + fileName, maxBytes=1048576, backupCount=5)
39 fmt = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
40 fd.setFormatter(fmt)
41 fd.setLevel(level)
42 log.addHandler(fd)
43 else:
44 log = LogDummy()
45
46 class LogDummy(object):
47 def __init__(self):
48 self._str = ''
49
50 def info(self, str, *args):
51 self._str = str
52
53 def debug(self, str, *args):
54 self._str = str
55
56 def warning(self, str, *args):
57 print("Warning: " + (str % args))
58
59 def error(self, str, *args):
60 print("Error: " + (str % args))