aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPjotr Prins2016-06-23 09:54:16 +0000
committerPjotr Prins2016-06-23 09:54:16 +0000
commit0a6c114a20d2b02476949511773ad32e591d7d80 (patch)
tree28d523c85ef2a05a1389edd14bfd5404cc00baca
parentf4200d002cce2edddddac67c55a75c2f1883ea2f (diff)
downloadgenenetwork2-0a6c114a20d2b02476949511773ad32e591d7d80.tar.gz
Logger: improved logging
-rw-r--r--wqflask/utility/logger.py10
-rw-r--r--wqflask/utility/tools.py1
-rw-r--r--wqflask/wqflask/database.py18
3 files changed, 16 insertions, 13 deletions
diff --git a/wqflask/utility/logger.py b/wqflask/utility/logger.py
index a2ae1f1a..ff53977e 100644
--- a/wqflask/utility/logger.py
+++ b/wqflask/utility/logger.py
@@ -30,10 +30,10 @@ import logging
import string
from inspect import isfunction
from pprint import pformat as pf
+from inspect import stack
from utility.tools import LOG_LEVEL, LOG_SQL, LOG_FORMAT
-
class GNLogger:
"""A logger class with some additional functionality, such as
multiple parameter logging, SQL logging, timing, colors, and lazy
@@ -89,9 +89,9 @@ class GNLogger:
def collect(self,fun,*args):
"""Collect arguments and use fun to output"""
- out = ""
+ out = "."+stack()[2][3]
for a in args:
- if len(out)>0:
+ if len(out)>1:
out += ": "
if isinstance(a, str):
out = out + a
@@ -101,9 +101,9 @@ class GNLogger:
def collectf(self,fun,*args):
"""Collect arguments and use fun to output one by one"""
- out = ""
+ out = "."+stack()[2][3]
for a in args:
- if len(out)>0:
+ if len(out)>1:
out += ": "
if isfunction(a):
out += a()
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index 21c9c1b7..93b1fa51 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -169,6 +169,7 @@ def show_settings():
# Cached values
WEBSERVER_MODE = get_setting('WEBSERVER_MODE')
GN_SERVER_URL = get_setting('GN_SERVER_URL')
+SQL_URI = get_setting('SQL_URI')
LOG_LEVEL = get_setting('LOG_LEVEL')
LOG_LEVEL_DEBUG = get_setting_int('LOG_LEVEL_DEBUG')
LOG_SQL = get_setting_bool('LOG_SQL')
diff --git a/wqflask/wqflask/database.py b/wqflask/wqflask/database.py
index d7a1c8a8..4df872ad 100644
--- a/wqflask/wqflask/database.py
+++ b/wqflask/wqflask/database.py
@@ -1,10 +1,15 @@
+# Module to initialize sqlalchemy with flask
+
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
-from wqflask import app
+from utility.tools import SQL_URI
+
+import utility.logger
+logger = utility.logger.getLogger(__name__ )
-#engine = create_engine('sqlite:////tmp/test.db', convert_unicode=True)
-engine = create_engine(app.config['SQL_URI'], convert_unicode=True)
+
+engine = create_engine(SQL_URI, convert_unicode=True)
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
@@ -12,17 +17,14 @@ db_session = scoped_session(sessionmaker(autocommit=False,
Base = declarative_base()
Base.query = db_session.query_property()
-import utility.logger
-logger = utility.logger.getLogger(__name__ )
-
def init_db():
# import all modules here that might define models so that
# they will be registered properly on the metadata. Otherwise
# you will have to import them first before calling init_db()
#import yourapplication.models
import wqflask.model
- logger.debug("database.py: Creating all model metadata..")
+ logger.debug("Creating all model metadata")
Base.metadata.create_all(bind=engine)
- logger.info("database.py: Done creating all model metadata...")
+ logger.info("Done creating all model metadata")
init_db()