forked from hyphae/apis-main_controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataLogger.py
executable file
·37 lines (27 loc) · 969 Bytes
/
dataLogger.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
#!/usr/bin/env python
import time, requests, logging.config, sys
logger = logging.getLogger(__name__)
dburl='http://example.com/oes/'
#when called from main thread
def dbLogNow(area,jsonstring):
#json should be string
posturl=dburl+'push-'+area+ '.cgi'
logger.debug(posturl)
try:
#logger.debug(jsonstring)
p = requests.post (posturl, data = jsonstring, timeout=1)
#logger.debug("logging done "+p.text)
except:
logger.error(sys.exc_info()[0])
#independent process
def startLogger(interval):
while True :
r = requests.get('http://localhost:4382/get/log')
logger.debug(r.text)
p = requests.post (dburl+'push-emulator_old.cgi', data = r.text)
logger.debug(p.text)
time.sleep(interval)
if __name__ == "__main__":
logging.config.fileConfig("config/logger.conf",disable_existing_loggers=0)
logger = logging.getLogger(__name__)
startLogger(5)