Skip to content

Commit

Permalink
add more logging, use logger consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeddy committed Jul 15, 2019
1 parent 6084742 commit ba85e67
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
11 changes: 10 additions & 1 deletion synprov/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import logging
import connexion

from healthcheck import HealthCheck

from synprov.config import connex_app
from synprov.config import neo4j_connection


logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


def neo4j_available():
try:
logger.info("Checking connection at {}"
.format(neo4j_connection.database.uri))
neo4j_connection.run('MATCH () RETURN 1 LIMIT 1')
return True, "neo4j ok"
except AttributeError:
return False, "neo4j connection not found"


def create_app():
app = config.connex_app
app = connex_app
app.add_api('openapi.yaml', arguments={'title': 'Provenance Service'})
# wrap the flask app and give a heathcheck url
health = HealthCheck(app, "/healthcheck")
Expand Down
13 changes: 7 additions & 6 deletions synprov/__main__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#!/usr/bin/env python3

import connexion
import logging

from synprov import create_app
from synprov.config import neo4j_connection as graph
from synprov.graph.client import GraphClient
from synprov.mock.main import create_mock_graph


logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


def init_db(num_activities=30):
graph.run(
'''
MATCH (n)
DETACH DELETE n
'''
)
graph.delete_all()
logger.info("Populating mock graph")
create_mock_graph(GraphClient(graph), num_activities)


Expand Down
8 changes: 6 additions & 2 deletions synprov/config.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
#!/usr/bin/env python3

import logging
import os
import connexion

from py2neo import Graph

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


connex_app = connexion.App(__name__, specification_dir='./openapi/')

env_host = os.environ.get('NEO4J_HOST')
neo4j_host = env_host if env_host is not None else 'localhost'
neo4j_host = env_host if env_host is not None else '0.0.0.0'
print(neo4j_host)

neo_user = os.environ['NEO4J_USERNAME']
neo_pass = os.environ['NEO4J_PASSWORD']

logger.info("Connecting to neo4j database")
neo4j_connection = Graph(
scheme='bolt',
host=neo4j_host,
Expand Down
15 changes: 8 additions & 7 deletions synprov/mock/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
from synprov.graph.client import GraphClient


logging.basicConfig(format='%(asctime)s | %(levelname)s : %(message)s',
level=logging.INFO,
stream=sys.stdout)
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


matcher = NodeMatcher(graph)

# ------------------------------
Expand All @@ -38,21 +39,21 @@ def add_activities(kt):
return x


def create_mock_graph(graph_db, NUMACTIVITIES):
def create_mock_graph(graph_client, NUMACTIVITIES):
# SCRIPT

# step 1 - Create activities:
logging.info("Generating table of Activities...")
logger.info("Generating table of Activities...")
activity_array = add_activities(NUMACTIVITIES)

# step 2 - Create corresponding nodes and relationships
# for each activity:
ref_num = 0
agt_num = 0
for i in activity_array:
logging.info("Building Activity '{}' of class '{}'"
logger.info("Building Activity '{}' of class '{}'"
.format(i.name, i._class))
act = ActivityMocker(graph_db, i, ref_num, agt_num)
act = ActivityMocker(graph_client, i, ref_num, agt_num)
(rn, an) = act.save()
ref_num += rn
agt_num += an
Expand Down

0 comments on commit ba85e67

Please sign in to comment.