| Index: emcore/trunk/tools/emcore.py | 
| — | — | @@ -65,26 +65,26 @@ | 
| 66 | 66 | cmddict = Commandline.cmddict | 
| 67 | 67 | doc = getfuncdoc(cmddict) | 
| 68 | 68 | if not specific: | 
| 69 |  | -        logger.log("Please provide a command and (if needed) parameters as command line arguments\n\n")
 | 
| 70 |  | -        logger.log("Available commands:\n\n")
 | 
|  | 69 | +        logger.write("Please provide a command and (if needed) parameters as command line arguments\n\n") | 
|  | 70 | +        logger.write("Available commands:\n\n") | 
| 71 | 71 | else: | 
| 72 |  | -        logger.log("\n")
 | 
|  | 72 | +        logger.write("\n") | 
| 73 | 73 | for function in sorted(doc.items()): | 
| 74 | 74 | function = function[0] | 
| 75 | 75 | if specific == False or specific == function: | 
| 76 |  | -            logger.log(function + " ", 2)
 | 
|  | 76 | +            logger.write(function + " ", 2) | 
| 77 | 77 | for arg in doc[function]['args']: | 
| 78 |  | -                logger.log("<" + arg + "> ")
 | 
|  | 78 | +                logger.write("<" + arg + "> ") | 
| 79 | 79 | if doc[function]['kwargs']: | 
| 80 | 80 | for kwarg, kwvalue in doc[function]['kwargs'].iteritems(): | 
| 81 |  | -                    logger.log("[" + kwarg + " = " + str(kwvalue) + "] ")
 | 
|  | 81 | +                    logger.write("[" + kwarg + " = " + str(kwvalue) + "] ") | 
| 82 | 82 | if doc[function]['varargs']: | 
| 83 |  | -                logger.log("<db1> ... <dbN>")
 | 
|  | 83 | +                logger.write("<db1> ... <dbN>") | 
| 84 | 84 | if docstring and doc[function]['documentation']: | 
| 85 |  | -                logger.log("\n")
 | 
| 86 |  | -                logger.log(doc[function]['documentation']+"\n", 4)
 | 
| 87 |  | -            logger.log("\n")
 | 
| 88 |  | -    logger.log("\n")
 | 
|  | 85 | +                logger.write("\n") | 
|  | 86 | +                logger.write(doc[function]['documentation']+"\n", 4) | 
|  | 87 | +            logger.write("\n") | 
|  | 88 | +    logger.write("\n") | 
| 89 | 89 |  | 
| 90 | 90 | if errormsg: | 
| 91 | 91 | logger.error(str(errormsg)+"\n") | 
| — | — | @@ -390,7 +390,7 @@ | 
| 391 | 391 | """ | 
| 392 | 392 | while True: | 
| 393 | 393 | resp = self.emcore.usbcread() | 
| 394 |  | -            self.logger.log(resp.data)
 | 
|  | 394 | +            self.logger.write(resp.data) | 
| 395 | 395 | time.sleep(0.1 / resp.maxsize * (resp.maxsize - len(resp.data))) | 
| 396 | 396 |  | 
| 397 | 397 | @command | 
| — | — | @@ -414,7 +414,7 @@ | 
| 415 | 415 | bitmask = self._hexint(bitmask) | 
| 416 | 416 | while True: | 
| 417 | 417 | resp = self.emcore.cread() | 
| 418 |  | -            self.logger.log(resp.data)
 | 
|  | 418 | +            self.logger.write(resp.data) | 
| 419 | 419 | time.sleep(0.1 / resp.maxsize * (resp.maxsize - len(resp.data))) | 
| 420 | 420 |  | 
| 421 | 421 | @command | 
| Index: emcore/trunk/tools/misc.py | 
| — | — | @@ -31,12 +31,12 @@ | 
| 32 | 32 |  | 
| 33 | 33 | class Logger(object): | 
| 34 | 34 | """ | 
| 35 |  | -        Simple stdout logger.
 | 
|  | 35 | +        Simple stdout/stderr/file logger. | 
| 36 | 36 | Loglevel 3 is most verbose, Loglevel 0: Only log something if there is an error. | 
| 37 | 37 | Loglevel -1 means that nothing is logged. | 
| 38 |  | -        The log function doesn't care about the loglevel and always logs to stdout.
 | 
|  | 38 | +        The write function doesn't care about the loglevel and always logs everything. | 
| 39 | 39 | """ | 
| 40 |  | -    def __init__(self, loglevel = 2, target = "stdout", logfile = "tools.log"):
 | 
|  | 40 | +    def __init__(self, loglevel = 2, target = "stderr", logfile = "tools.log"): | 
| 41 | 41 | """ | 
| 42 | 42 | loglevel: Possible values: 0 (only errors), 1 (warnings), 2 (info, | 
| 43 | 43 | recommended for production use), 3 and more (debug) | 
| — | — | @@ -47,13 +47,15 @@ | 
| 48 | 48 | self.logfile = logfile | 
| 49 | 49 | self.target = target | 
| 50 | 50 |  | 
| 51 |  | -    def log(self, text, indent = 0, target = None):
 | 
|  | 51 | +    def write(self, text, indent = 0, target = None): | 
| 52 | 52 | if self.loglevel >= 0: | 
| 53 | 53 | if target is None: target = self.target | 
| 54 | 54 | text = (indent * " ") + text | 
| 55 | 55 | text = text.replace("\n", "\n" + (indent * " "), text.count("\n") - 1) | 
| 56 | 56 | if target == "stdout": | 
| 57 |  | -                sys.stdout.write(text)
 | 
|  | 57 | +                sys.stderr.write(text) | 
|  | 58 | +            if target == "stderr": | 
|  | 59 | +                sys.stderr.write(text) | 
| 58 | 60 | elif target == "file": | 
| 59 | 61 | with open(self.logfile, 'a') as f: | 
| 60 | 62 | f.write(text) | 
| — | — | @@ -63,19 +65,19 @@ | 
| 64 | 66 |  | 
| 65 | 67 | def debug(self, text, indent = 0, target = None): | 
| 66 | 68 | if self.loglevel >= 3: | 
| 67 |  | -            self.log("DEBUG: " + text, indent, target)
 | 
|  | 69 | +            self.write("DEBUG: " + text, indent, target) | 
| 68 | 70 |  | 
| 69 | 71 | def info(self, text, indent = 0, target = None): | 
| 70 | 72 | if self.loglevel >= 2: | 
| 71 |  | -            self.log(text, indent, target)
 | 
|  | 73 | +            self.write(text, indent, target) | 
| 72 | 74 |  | 
| 73 | 75 | def warn(self, text, indent = 0, target = None): | 
| 74 | 76 | if self.loglevel >= 1: | 
| 75 |  | -            self.log("WARNING: " + text, indent, target)
 | 
|  | 77 | +            self.write("WARNING: " + text, indent, target) | 
| 76 | 78 |  | 
| 77 | 79 | def error(self, text, indent = 0, target = None): | 
| 78 | 80 | if self.loglevel >= 0: | 
| 79 |  | -            self.log("ERROR: " + text, indent, target)
 | 
|  | 81 | +            self.write("ERROR: " + text, indent, target) | 
| 80 | 82 |  | 
| 81 | 83 |  | 
| 82 | 84 | class Bunch(dict): | 
| Index: emcore/trunk/tools/libemcore.py | 
| — | — | @@ -1109,26 +1109,26 @@ | 
| 1110 | 1110 | if sys.argv[1] == "gendoc": | 
| 1111 | 1111 | # Generates Documentation | 
| 1112 | 1112 | from misc import gendoc | 
| 1113 |  | -        logger.log("Generating documentation\n")
 | 
|  | 1113 | +        logger.write("Generating documentation\n") | 
| 1114 | 1114 | cmddict = {} | 
| 1115 | 1115 | for attr, value in Emcore.__dict__.iteritems(): | 
| 1116 | 1116 | if getattr(value, 'func', False): | 
| 1117 | 1117 | if getattr(value.func, '_command', False): | 
| 1118 | 1118 | cmddict[value.func.__name__] = value | 
| 1119 |  | -        logger.log(gendoc(cmddict))
 | 
|  | 1119 | +        logger.write(gendoc(cmddict)) | 
| 1120 | 1120 |  | 
| 1121 | 1121 | elif sys.argv[1] == "malloctest": | 
| 1122 | 1122 | emcore = Emcore() | 
| 1123 |  | -        logger.log("Allocating 200 bytes of memory: ")
 | 
|  | 1123 | +        logger.write("Allocating 200 bytes of memory: ") | 
| 1124 | 1124 | addr = emcore.malloc(200) | 
| 1125 |  | -        logger.log("0x%x\n" % addr)
 | 
| 1126 |  | -        logger.log("Reallocating to 2000 bytes: ")
 | 
|  | 1125 | +        logger.write("0x%x\n" % addr) | 
|  | 1126 | +        logger.write("Reallocating to 2000 bytes: ") | 
| 1127 | 1127 | addr = emcore.realloc(addr, 2000) | 
| 1128 |  | -        logger.log("0x%x\n" % addr)
 | 
| 1129 |  | -        logger.log("Freeing 0x%x\n" % addr)
 | 
|  | 1128 | +        logger.write("0x%x\n" % addr) | 
|  | 1129 | +        logger.write("Freeing 0x%x\n" % addr) | 
| 1130 | 1130 | emcore.free(addr) | 
| 1131 |  | -        logger.log("Allocating 1000 bytes of memory aligned to 100 bytes: ")
 | 
|  | 1131 | +        logger.write("Allocating 1000 bytes of memory aligned to 100 bytes: ") | 
| 1132 | 1132 | addr = emcore.memalign(100, 1000) | 
| 1133 |  | -        logger.log("0x%x\n" % addr)
 | 
| 1134 |  | -        logger.log("Freeing 0x%x\n" % addr)
 | 
|  | 1133 | +        logger.write("0x%x\n" % addr) | 
|  | 1134 | +        logger.write("Freeing 0x%x\n" % addr) | 
| 1135 | 1135 | emcore.free(addr) | 
| \ No newline at end of file |