Skip to content

Commit

Permalink
add ability to set log file path
Browse files Browse the repository at this point in the history
  • Loading branch information
jon committed Aug 2, 2022
1 parent bb3deed commit 1a0fe28
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion phew/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ def datetime_string():
dt = machine.RTC().datetime()
return "{0:04d}-{1:02d}-{2:02d} {4:02d}:{5:02d}:{6:02d}".format(*dt)

_log_file = "log.txt"
def log_file(file):
global _log_file
_log_file = file

def log(level, text):
datetime = datetime_string()
log_entry = "{0} [{1:8} /{2:>8}] {3}".format(datetime, level, gc.mem_free(), text)
print(log_entry)
with open("log.txt", "a") as logfile:
with open(_log_file, "a") as logfile:
logfile.write(log_entry + '\n')

def info(*items):
Expand Down

0 comments on commit 1a0fe28

Please sign in to comment.