]> arthur.barton.de Git - netdata.git/blob - python.d/python_modules/msg.py
comments
[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 = PROGRAM + " " + str(msg_type) + ":"
16     for i in args:
17         msg += " "
18         msg += str(i)
19     sys.stderr.write(msg + "\n")
20     sys.stderr.flush()
21
22
23 def debug(*args):
24     """
25     Print debug message on stderr.
26     """
27     if not DEBUG_FLAG:
28         return
29
30     log_msg("DEBUG", *args)
31
32
33 def error(*args):
34     """
35     Print message on stderr.
36     """
37     log_msg("ERROR", *args)
38
39
40 def info(*args):
41     """
42     Print message on stderr.
43     """
44     log_msg("INFO", *args)
45
46
47 def fatal(*args):
48     """
49     Print message on stderr and exit.
50     """
51     log_msg("FATAL", *args)
52     sys.stdout.write('DISABLE\n')
53     sys.exit(1)