Skip to content

Commit a7bea06

Browse files
committed
logging: Add very basic implementation.
1 parent 52ac430 commit a7bea06

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

logging/logging.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,61 @@
33
# Reason:
44
# Basic, useful module, by CPython impl depends on module "string" which
55
# uses metaclasses.
6+
7+
CRITICAL = 50
8+
ERROR = 40
9+
WARNING = 30
10+
INFO = 20
11+
DEBUG = 10
12+
NOTSET = 0
13+
14+
_level_dict = {
15+
CRITICAL: "CRIT",
16+
ERROR: "ERROR",
17+
WARNING: "WARN",
18+
INFO: "INFO",
19+
DEBUG: "DEBUG",
20+
}
21+
22+
class Logger:
23+
24+
def __init__(self, name):
25+
self.level = NOTSET
26+
self.name = name
27+
28+
def _level_str(self, level):
29+
if level in _level_dict:
30+
return _level_dict[level]
31+
return "LVL" + str(level)
32+
33+
def log(self, level, msg, *args):
34+
if level > self.level:
35+
print(("%s:%s:" + msg) % ((self._level_str(level), self.name) + args))
36+
37+
def debug(self, msg, *args):
38+
self.log(DEBUG, msg, *args)
39+
40+
def info(self, msg, *args):
41+
self.log(INFO, msg, *args)
42+
43+
def warning(self, msg, *args):
44+
self.log(WARNING, msg, *args)
45+
46+
def error(self, msg, *args):
47+
self.log(ERROR, msg, *args)
48+
49+
def critical(self, msg, *args):
50+
self.log(CRITICAL, msg, *args)
51+
52+
53+
_loggers = {}
54+
55+
def getLogger(name):
56+
if name in _loggers:
57+
return _loggers[name]
58+
l = Logger(name)
59+
_loggers[name] = l
60+
return l
61+
62+
def basicConfig(level):
63+
pass

logging/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from distutils.core import setup
22

33
setup(name='micropython-logging',
4-
version='0.0.1',
5-
description='Dummy logging package for MicroPython',
4+
version='0.0.2',
5+
description='logging package for MicroPython',
66
url='https://github.com/micropython/micropython/issues/405',
77
author='MicroPython Developers',
88
author_email='micro-python@googlegroups.com',

logging/test_logging.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import logging
2+
3+
logging.basicConfig(level=logging.DEBUG)
4+
log = logging.getLogger("test")
5+
log.debug("Test message: %d(%s)", 100, "foobar")
6+
log.info("Test message2: %d(%s)", 100, "foobar")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy