-
Notifications
You must be signed in to change notification settings - Fork 20
/
pclogging.py
75 lines (49 loc) · 1.29 KB
/
pclogging.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#
#
# logging system from Project Curacao
# filename: pclogger.py
# Version 1.0 10/04/13
#
# contains logging data
#
CRITICAL=50
ERROR=40
WARNING=30
INFO=20
DEBUG=10
NOTSET=0
import sys
import time
# Check for user imports
try:
import conflocal as config
except ImportError:
import config
if (config.enable_MySQL_Logging == True):
import MySQLdb as mdb
def log(level, source, message):
if (config.enable_MySQL_Logging == True):
LOWESTDEBUG = 0
# open mysql database
# write log
# commit
# close
if (level >= LOWESTDEBUG):
try:
#print("trying database")
con = mdb.connect('localhost', 'root', config.MySQL_Password, 'SkyWeather');
cur = con.cursor()
#print "before query"
query = "INSERT INTO systemlog(TimeStamp, Level, Source, Message) VALUES(UTC_TIMESTAMP(), %i, '%s', '%s')" % (level, source, message)
#print("query=%s" % query)
cur.execute(query)
con.commit()
except mdb.Error, e:
print "Error %d: %s" % (e.args[0],e.args[1])
con.rollback()
#sys.exit(1)
finally:
cur.close()
con.close()
del cur
del con