~vcs-imports/clientcookie/trunk

« back to all changes in this revision

Viewing changes to ClientCookie/_Debug.py

  • Committer: jjlee
  • Date: 2004-03-31 19:36:11 UTC
  • Revision ID: svn-v4:fd0d7bf2-dfb6-0310-8d31-b7ecfe96aada:user/jjlee/wwwsearch/ClientCookie:3571
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import ClientCookie
 
2
 
 
3
try:
 
4
    import warnings
 
5
except ImportError:
 
6
    def warn(text):
 
7
        ClientCookie.DEBUG_STREAM.write("WARNING: "+text)
 
8
else:
 
9
    def warn(text):
 
10
        print "HELLOOOOOOOO!"
 
11
        warnings.warn(text, stacklevel=2)
 
12
 
 
13
try:
 
14
    import logging
 
15
except:
 
16
    NOTSET = None
 
17
    INFO = 20
 
18
    DEBUG = 10
 
19
    class Logger:
 
20
        def __init__(self):
 
21
            self.level = NOTSET
 
22
        def log(self, level, text, *args):
 
23
            if args:
 
24
                text = text % args
 
25
            if self.level is not None and level < self.level:
 
26
                ClientCookie.DEBUG_STREAM.write(text+"\n")
 
27
        def debug(self, text, *args):
 
28
            apply(self.log, (DEBUG, text)+args)
 
29
        def info(self, text, *args):
 
30
            apply(self.log, (INFO, text)+args)
 
31
        def setLevel(self, lvl):
 
32
            self.level = lvl
 
33
    LOGGER = Logger()
 
34
    def getLogger(name): return LOGGER
 
35
else:
 
36
    from logging import getLogger, INFO, DEBUG, NOTSET
 
37
    getLogger("ClientCookie").addHandler(
 
38
        logging.StreamHandler(ClientCookie.DEBUG_STREAM))
 
39
 
 
40
## def _debug(text, *args):
 
41
##     if args:
 
42
##         text = text % args
 
43
##     ClientCookie.DEBUG_STREAM.write(text+"\n")