potluck.logging

Logging support.

logging.py

 1"""
 2Logging support.
 3
 4logging.py
 5"""
 6
 7# For Python2 cross-compatibility
 8from __future__ import print_function
 9
10import sys, traceback
11
12LOG_TO = sys.stdout
13"""
14Where log messages go (file-like).
15"""
16
17DEBUG = False
18"""
19Whether or not to actually show debugging messages.
20"""
21
22
23def set_log_target(stream):
24    """
25    Sets up logging messages to go to the specified stream (must be a
26    file-like object.
27    """
28    global LOG_TO
29    LOG_TO = stream
30
31
32def log(*args, **kwargs):
33    """
34    For now, nothing fancy: logging == printing.
35    """
36    kwargs['file'] = LOG_TO
37    print(*args, **kwargs)
38
39
40def debug_msg(*args, **kwargs):
41    """
42    Works like print, except it doesn't actually generate output unless
43    DEBUG is set to True.
44    """
45    if DEBUG:
46        kwargs['file'] = LOG_TO
47        print(*args, **kwargs)
48
49
50def log_current_exception():
51    """
52    Formatted logging of the currently-being-handled exception.
53    """
54    traceback.print_exc(file=LOG_TO)
LOG_TO = <_io.StringIO object>

Where log messages go (file-like).

DEBUG = False

Whether or not to actually show debugging messages.

def set_log_target(stream):
24def set_log_target(stream):
25    """
26    Sets up logging messages to go to the specified stream (must be a
27    file-like object.
28    """
29    global LOG_TO
30    LOG_TO = stream

Sets up logging messages to go to the specified stream (must be a file-like object.

def log(*args, **kwargs):
33def log(*args, **kwargs):
34    """
35    For now, nothing fancy: logging == printing.
36    """
37    kwargs['file'] = LOG_TO
38    print(*args, **kwargs)

For now, nothing fancy: logging == printing.

def debug_msg(*args, **kwargs):
41def debug_msg(*args, **kwargs):
42    """
43    Works like print, except it doesn't actually generate output unless
44    DEBUG is set to True.
45    """
46    if DEBUG:
47        kwargs['file'] = LOG_TO
48        print(*args, **kwargs)

Works like print, except it doesn't actually generate output unless DEBUG is set to True.

def log_current_exception():
51def log_current_exception():
52    """
53    Formatted logging of the currently-being-handled exception.
54    """
55    traceback.print_exc(file=LOG_TO)

Formatted logging of the currently-being-handled exception.