Skip to content

Commit

Permalink
Added support for shunting logs to file, and turned on boot logging t…
Browse files Browse the repository at this point in the history
…o boot.log (for now)
  • Loading branch information
psychogenic committed Dec 20, 2024
1 parent 32a5fc3 commit 45dc41b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
import ttboard.log as logging
# logging.ticksStart() # start-up tick delta counter

logging.basicConfig(level=logging.DEBUG, filename='boot.log')


import micropython
import ttboard.util.time as time
from ttboard.boot.demoboard_detect import DemoboardDetect
Expand Down Expand Up @@ -97,6 +100,7 @@ def stopClocking():
tt = startup()


logging.basicConfig(filename=None)
gc.collect()
colors.color_start('magenta', False)
print("Mem info")
Expand Down
34 changes: 29 additions & 5 deletions src/ttboard/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,38 @@
WARNING = 30
ERROR = 40
class Logger:

OutFile = None
colorMap = {
10: 'yellow',
20: 'green',
30: 'yellow',
40: 'red'
}

@classmethod
def set_out_file(cls, path_to:str=None):
if cls.OutFile is not None:
cls.OutFile.close()
cls.OutFile = None

if path_to is not None:
cls.OutFile = open(path_to, 'w')


def __init__(self, name):
self.name = name
self.loglevel = DefaultLogLevel

def out(self, s, level:int):
global LoggingPrefix
if self.loglevel <= level:
if LoggingPrefix:
prefix = LoggingPrefix
else:
prefix = self.name
if self.OutFile is not None:
print(f'{prefix}: {s}', file=self.OutFile)

print(f'{prefix}: {colors.color(s, self.colorMap[level])}')

def debug(self, s):
Expand Down Expand Up @@ -73,12 +88,21 @@ def getLogger(name:str):
RPLoggers[name] = Logger(name)
return RPLoggers[name]

def basicConfig(level:int):
def basicConfig(level:int=None, filename:str=None):
global DefaultLogLevel
global RPLoggers
DefaultLogLevel = level
for logger in RPLoggers.values():
logger.loglevel = level
if level is not None:
DefaultLogLevel = level
for logger in RPLoggers.values():
logger.loglevel = level

Logger.set_out_file(filename)








else:
Expand Down

0 comments on commit 45dc41b

Please sign in to comment.