summaryrefslogtreecommitdiffstats
path: root/storage/storage_log.py
blob: a52513d8c955f651a521ed504fa302e640f039f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import logging
import anaconda_log
import inspect

def log_method_call(d, *args, **kwargs):
    classname = d.__class__.__name__
    stack = inspect.stack()
    methodname = stack[1][3]

    spaces = len(stack) * ' '
    fmt = "%s%s.%s:"
    fmt_args = [spaces, classname, methodname]

    for arg in args:
        fmt += " %s ;"
        fmt_args.append(arg)

    for k, v in kwargs.items():
        fmt += " %s: %s ;"
        fmt_args.extend([k, v])

    logger.debug(fmt % tuple(fmt_args))


logger = logging.getLogger("storage")
logger.setLevel(logging.DEBUG)
anaconda_log.logger.addFileHandler("/tmp/storage.log", logger, logging.DEBUG)
anaconda_log.logger.addFileHandler("/dev/tty3", logger,
                                   anaconda_log.DEFAULT_TTY_LEVEL,
                                   anaconda_log.TTY_FORMAT,
                                   autoLevel=True)
anaconda_log.logger.forwardToSyslog(logger)