-
Notifications
You must be signed in to change notification settings - Fork 2
/
pclogging.py
executable file
·79 lines (51 loc) · 1.4 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
75
76
77
78
#
#
# 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 pymysql
pymysql.install_as_MySQLdb()
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(config.MySQL_Address, config.MySQL_User, config.MySQL_Password, config.MySQL_Database2);
cur = con.cursor()
#print "before query"
query = "INSERT INTO systemlog(TimeStamp, Level, Source, Message) VALUES(CURRENT_TIMESTAMP, %i, '%s', '%s')" % (level, source, message)
#print("query=%s" % query)
cur.execute(query)
con.commit()
except mdb.Error as 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