kopia lustrzana https://github.com/micropython/micropython-lib
logging: Add very basic implementation.
rodzic
52ac4308f7
commit
a7bea0674c
|
@ -3,3 +3,61 @@
|
|||
# Reason:
|
||||
# Basic, useful module, by CPython impl depends on module "string" which
|
||||
# uses metaclasses.
|
||||
|
||||
CRITICAL = 50
|
||||
ERROR = 40
|
||||
WARNING = 30
|
||||
INFO = 20
|
||||
DEBUG = 10
|
||||
NOTSET = 0
|
||||
|
||||
_level_dict = {
|
||||
CRITICAL: "CRIT",
|
||||
ERROR: "ERROR",
|
||||
WARNING: "WARN",
|
||||
INFO: "INFO",
|
||||
DEBUG: "DEBUG",
|
||||
}
|
||||
|
||||
class Logger:
|
||||
|
||||
def __init__(self, name):
|
||||
self.level = NOTSET
|
||||
self.name = name
|
||||
|
||||
def _level_str(self, level):
|
||||
if level in _level_dict:
|
||||
return _level_dict[level]
|
||||
return "LVL" + str(level)
|
||||
|
||||
def log(self, level, msg, *args):
|
||||
if level > self.level:
|
||||
print(("%s:%s:" + msg) % ((self._level_str(level), self.name) + args))
|
||||
|
||||
def debug(self, msg, *args):
|
||||
self.log(DEBUG, msg, *args)
|
||||
|
||||
def info(self, msg, *args):
|
||||
self.log(INFO, msg, *args)
|
||||
|
||||
def warning(self, msg, *args):
|
||||
self.log(WARNING, msg, *args)
|
||||
|
||||
def error(self, msg, *args):
|
||||
self.log(ERROR, msg, *args)
|
||||
|
||||
def critical(self, msg, *args):
|
||||
self.log(CRITICAL, msg, *args)
|
||||
|
||||
|
||||
_loggers = {}
|
||||
|
||||
def getLogger(name):
|
||||
if name in _loggers:
|
||||
return _loggers[name]
|
||||
l = Logger(name)
|
||||
_loggers[name] = l
|
||||
return l
|
||||
|
||||
def basicConfig(level):
|
||||
pass
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
from distutils.core import setup
|
||||
|
||||
setup(name='micropython-logging',
|
||||
version='0.0.1',
|
||||
description='Dummy logging package for MicroPython',
|
||||
version='0.0.2',
|
||||
description='logging package for MicroPython',
|
||||
url='https://github.com/micropython/micropython/issues/405',
|
||||
author='MicroPython Developers',
|
||||
author_email='micro-python@googlegroups.com',
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
import logging
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
log = logging.getLogger("test")
|
||||
log.debug("Test message: %d(%s)", 100, "foobar")
|
||||
log.info("Test message2: %d(%s)", 100, "foobar")
|
Ładowanie…
Reference in New Issue