-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathodomLog.py
executable file
·56 lines (40 loc) · 1.12 KB
/
odomLog.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
52
#!/usr/bin/python3
#
# odomLog.py allow user scripts to
# log to odometer.log
#
# Formats message as:
# YYYY-MM-DD HH:MM|[<script.py>.<funcName>]<message>
#
# USAGE:
# import sys
# sys.path.append('/home/pi/HOME/plib')
# import odomLog
#
#
# def somefunc():
# strToLog = "*** Reset Encoders ***"
# odomLog.logger.info(strToLog) or
# odomLog.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/odometer.log')
# logformatter = logging.Formatter('%(asctime)s|[%(filename)s.%(funcName)s]%(message)s',"%Y-%m-%d %H:%M")
logformatter = logging.Formatter('%(asctime)s|%(message)s',"%Y-%m-%d %H:%M:%S")
loghandler.setFormatter(logformatter)
logger.addHandler(loghandler)
def testfunc():
strToLog = "*** odomLog.py testfunc() executed ***"
logger.info(strToLog)
print("odomLog.py testfunc() logged:",strToLog)
# test main
def main():
testfunc()
if __name__ == "__main__":
main()