-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlog.py
More file actions
41 lines (36 loc) · 888 Bytes
/
log.py
File metadata and controls
41 lines (36 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import binascii
import machine
import time
logfile = "/flash/log_" + os.uname().sysname + "_" + binascii.hexlify(machine.unique_id()).decode()[-4:] + ".log"
def log(*messages):
# messages = ('eh', 'yo', 666, 'whazzzup!?')
f = open(logfile, 'a')
t = "[" + str(time.time()) + "]"
f.write(t)
f.write(' ')
for m in messages:
# print(m)
f.write(str(m))
f.write(' ')
f.write('\n')
f.close()
print(t, *messages)
def catlog():
f = open(logfile, 'r')
print(f.read())
f.close()
def rmlog():
try:
print("remove", logfile )
os.remove(logfile)
print("done")
except Exception as e:
print("couldn't remove {}: {}".format(logfile,e))
pass
if __name__ == "__main__":
# log('eh', 'yo', 666, 'whazzzup!?')
# print('---')
catlog()
if False:
rmlog()