Logging and configuration loading
This commit is contained in:
parent
603c16b0a2
commit
879ad65f14
2 changed files with 33 additions and 4 deletions
|
@ -1,3 +1,4 @@
|
||||||
## Required python packages
|
## Required python packages
|
||||||
* bottle
|
* bottle
|
||||||
|
* bottlejwt
|
||||||
* psycopg2
|
* psycopg2
|
36
server.py
36
server.py
|
@ -1,12 +1,40 @@
|
||||||
from bottle import route, run,template
|
from bottle import route, run,template,app,default_app
|
||||||
|
import logging
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.DEBUG,)
|
||||||
|
log=logging.getLogger("rudemaps")
|
||||||
|
CONFIG={}
|
||||||
|
|
||||||
|
|
||||||
|
def load_config(config_file="config.json"):
|
||||||
|
global CONFIG
|
||||||
|
log.debug("loading configuration file")
|
||||||
|
with open(config_file, "r") as f:
|
||||||
|
try:
|
||||||
|
CONFIG = json.load(f)
|
||||||
|
log.debug("CONFIG:\n %s" % str(CONFIG))
|
||||||
|
except Exception, e:
|
||||||
|
log.warning("Problem loading config file %s :\n%s" % (config_file, e))
|
||||||
|
|
||||||
|
|
||||||
@route('/')
|
@route('/')
|
||||||
def root():
|
def root():
|
||||||
return template('map_template', item="prova bind")
|
return template('map_template', item="prova bind")
|
||||||
|
|
||||||
@route('/<item>')
|
@route('/<item>')
|
||||||
def myName(item):
|
def myName(item):
|
||||||
return template('map_template', item=item)
|
return template('map_template', item=item)
|
||||||
|
|
||||||
|
load_config()
|
||||||
|
|
||||||
run(host='localhost', port=9093)
|
if __name__=='__main__':
|
||||||
|
#DEVEL SERVER
|
||||||
|
from bottle import debug
|
||||||
|
debug(True)
|
||||||
|
run(host='localhost', port=9093,reloader=True)
|
||||||
|
else:
|
||||||
|
#WSGI
|
||||||
|
os.chdir(os.path.dirname(__file__))
|
||||||
|
application = default_app()
|
||||||
|
|
Loading…
Reference in a new issue