]> arthur.barton.de Git - netdata.git/blob - python.d/python_modules/msg.py
speed optimizations
[netdata.git] / python.d / python_modules / msg.py
1 # -*- coding: utf-8 -*-
2 # Description: logging for netdata python.d modules
3
4 import sys
5
6 DEBUG_FLAG = False
7 PROGRAM = ""
8
9
10 def log_msg(msg_type, *args):
11     """
12     Print message on stderr.
13     :param msg_type: str
14     """
15     msg = "%s %s: %s" % (PROGRAM, str(msg_type), " ".join(args))
16
17     sys.stderr.write(msg + "\n")
18     sys.stderr.flush()
19
20
21 def debug(*args):
22     """
23     Print debug message on stderr.
24     """
25     if not DEBUG_FLAG:
26         return
27
28     log_msg("DEBUG", *args)
29
30
31 def error(*args):
32     """
33     Print message on stderr.
34     """
35     log_msg("ERROR", *args)
36
37
38 def info(*args):
39     """
40     Print message on stderr.
41     """
42     log_msg("INFO", *args)
43
44
45 def fatal(*args):
46     """
47     Print message on stderr and exit.
48     """
49     log_msg("FATAL", *args)
50     sys.stdout.write('DISABLE\n')
51     sys.exit(1)