ctdb-scripts: Improve update and listing code
[samba4-gss.git] / python / samba / kcc / debug.py
blob8a69bde43a7720546cd67ee167136e481d9cf696
1 # Debug utilities for samba_kcc
3 # Copyright (C) Andrew Bartlett 2015
5 # Although Andrew Bartlett owns the copyright, the actual work was
6 # performed by Douglas Bagnall and Garming Sam.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 import sys
22 import logging
23 from functools import partial
24 import traceback
26 logger = logging.getLogger("samba_kcc")
27 logger.addHandler(logging.StreamHandler(sys.stdout))
28 DEBUG = logger.debug
29 WARN = logger.warning
32 # colours for prettier logs
33 from samba.colour import C_NORMAL, REV_RED
34 from samba.colour import DARK_RED, RED
35 from samba.colour import DARK_GREEN, GREEN
36 from samba.colour import DARK_YELLOW, YELLOW
37 from samba.colour import DARK_BLUE, BLUE
38 from samba.colour import PURPLE, MAGENTA
39 from samba.colour import DARK_CYAN, CYAN
40 from samba.colour import GREY, WHITE
43 def _color_debug(*args, **kwargs):
44 DEBUG('%s%s%s' % (kwargs['color'], args[0], C_NORMAL), *args[1:])
47 _globals = globals()
48 for _color in ('DARK_RED', 'RED', 'DARK_GREEN', 'GREEN', 'YELLOW',
49 'DARK_YELLOW', 'DARK_BLUE', 'BLUE', 'PURPLE', 'MAGENTA',
50 'DARK_CYAN', 'CYAN', 'GREY', 'WHITE', 'REV_RED'):
51 _globals['DEBUG_' + _color] = partial(_color_debug, color=_globals[_color])
54 def DEBUG_FN(msg=''):
55 filename, lineno, function, text = traceback.extract_stack(None, 2)[0]
56 DEBUG("%s%s:%s%s %s%s()%s '%s'" % (CYAN, filename, BLUE, lineno,
57 CYAN, function, C_NORMAL, msg))
60 def null_debug(*args, **kwargs):
61 pass