Skip to content

Commit

Permalink
v1.1
Browse files Browse the repository at this point in the history
Use bytearray in teplate map instead of list to reduce overhead
  • Loading branch information
M-Jay committed Jun 27, 2021
1 parent e1dcf32 commit 91d12aa
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions ulogger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
try: import time
except: import utime as time

try: import re
except: import ure as re

try: from micropython import const
except: const = lambda x:x # for debug

from io import TextIOWrapper

__version__ = "v1.0"
__version__ = "v1.1"

DEBUG: int = const(10)
INFO: int = const(20)
Expand Down Expand Up @@ -74,7 +71,7 @@ class Handler():
"""The Handler for logger.
"""
_template: str
_map: list
_map: bytes
level: int
_direction: int
_clock: BaseClock
Expand Down Expand Up @@ -135,7 +132,6 @@ def __init__(self,
:type max_file_size: str
"""
#TODO: 文件按日期存储, 最大份数的设置.
self._map = []
self._direction = direction
self.level = level
self._clock = clock if clock else BaseClock()
Expand Down Expand Up @@ -173,7 +169,7 @@ def __init__(self,
# i += 1

# 添加映射

self._map = bytearray()
idx = 0
while True:
idx = fmt.find("&(", idx)
Expand Down Expand Up @@ -206,7 +202,7 @@ def __init__(self,
.replace("&(time)%", "%s")\
.replace("&(name)%", "%s")\
.replace("&(fnname)%", "%s")\
+ "\n" if fmt[:-1] is not '\n' else ''
+ "\n" if fmt[:-1] != '\n' else ''

def _msg(self, *args, level: int, name: str, fnname: str):
"""
Expand Down Expand Up @@ -283,10 +279,10 @@ def handlers(self):
def _msg(self, *args, level: int, fn: str):

for item in self._handlers:
try:
item._msg(*args, level=level, fnname=fn, name=self.name)
except:
print("Failed while trying to record")
#try:
item._msg(*args, level=level, fnname=fn, name=self.name)
#except:
# print("Failed while trying to record")

def debug(self, *args, fn: str = None):
self._msg(*args, level=DEBUG, fn=fn)
Expand Down

0 comments on commit 91d12aa

Please sign in to comment.