diff -r 301d738b1181 -r 70b6c13d084f lib/log.py --- a/lib/log.py Thu Jan 31 17:58:03 2008 +0000 +++ b/lib/log.py Thu Jan 31 19:13:00 2008 +0000 @@ -18,19 +18,64 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # -import logging - -logging.basicConfig( - level=logging.INFO, - format="%(message)s", -# format="%(name)8s %(levelname)8s %(lineno)3d %(message)s", +import logging, sys -) +log_level = logging.INFO +stack = [] -index = logging.getLogger('index') -render = logging.getLogger('render') -template = logging.getLogger('template') +class g : + out_depth = 0 + node = None -misc = logging.getLogger('misc') +def title (title, *args) : + stack.append(title) -template.setLevel(logging.ERROR) + print "%s- %s" % (" "*g.out_depth, title % args) + + g.out_depth += 1 + +def down (dir_name, *args) : + stack.append(dir_name % args) + g.node = None + +def next (fname, *args) : + g.node = fname % args + +def up () : + stack.pop(-1) + g.node = None + g.out_depth = min(g.out_depth, len(stack)) + +def done () : + print "done" + +def log (level, message, *args, **kwargs) : + wait = kwargs.get("wait", False) + + if level >= log_level : + if g.out_depth != len(stack) : + for segment in stack[g.out_depth:] : + print "%sd %s" % (" "*g.out_depth, segment) + g.out_depth += 1 + + if g.node : + print "%sf %s" % (" "*g.out_depth, g.node) + g.node = None + + if wait : + print "%s- %s..." % (" "*g.out_depth, message % args), + sys.stdout.flush() + else : + print "%s- %s" % (" "*g.out_depth, message % args) + +def _level (level) : + def _log_func (message, *args, **kwargs) : + log(level, message, *args, **kwargs) + + return _log_func + +debug = _level(logging.DEBUG) +info = _level(logging.INFO) +warning = _level(logging.WARNING) +error = _level(logging.ERROR) +