-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlifeLog.py
executable file
·55 lines (39 loc) · 1.02 KB
/
lifeLog.py
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
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python3
#
# lifeLog.py allow user scripts to
# log to life.log
#
# Formats message as:
# YYYY-MM-DD HH:MM|[<script.py>.<funcName>]<message>
#
# USAGE:
# import sys
# sys.path.append('/home/pi/HOME/plib')
# import lifeLog
#
#
# def somefunc():
# strToLog = "message"
# lifeLog.logger.info(strToLog) or
# lifeLog.logger.info("message")
#
from __future__ import print_function
import sys
import logging
HOME="GoPi5Go"
# create logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
loghandler = logging.FileHandler('/home/pi/'+HOME+'/logs/life.log')
logformatter = logging.Formatter('%(asctime)s|[%(filename)s.%(funcName)s]%(message)s',"%Y-%m-%d %H:%M")
loghandler.setFormatter(logformatter)
logger.addHandler(loghandler)
def testfunc():
strToLog = "---- lifeLog.py testfunc() executed"
logger.info(strToLog)
print("lifeLog.py testfunc() logged:",strToLog)
# test main
def main():
testfunc()
if __name__ == "__main__":
main()