Commit a41c528e authored by Matthieu Dorier's avatar Matthieu Dorier

better logging

parent fc63233a
......@@ -11,12 +11,9 @@ import flamestore as fs
from pymargo import MargoInstance
import flamestore.log as log
fmt = log.FlameStoreFormatter()
hdlr = logging.StreamHandler(sys.stdout)
hdlr.setFormatter(fmt)
logging.root.addHandler(hdlr)
logging.root.setLevel(logging.DEBUG)
logger = logging.getLogger('flamestore')
log.init_logging(logging.INFO)
logger = log.get_logger()
try:
from mpi4py import MPI
......@@ -59,6 +56,8 @@ workspace_config = {
}
def create(args):
if(args.debug):
logging.root.setLevel(logging.DEBUG)
path = args.path
if(path[-1] == '/'):
path = path[:-1]
......@@ -129,6 +128,8 @@ def run_master_worker(workspace_path, config, comm=None):
mid.wait_for_finalize()
def run(args):
if(args.debug):
logging.root.setLevel(logging.DEBUG)
name = args.name
path = args.path
fullpath = path+'/'+name
......@@ -171,6 +172,7 @@ create_parser.add_argument('--path', '-p', type=str, help='Path to the workspace
create_parser.add_argument('--name', '-n', type=str, help='Name of the workspace', required=True)
create_parser.add_argument('--override', '-o', action='store_true', help='Override existing workspace', default=False)
create_parser.add_argument('--yes', '-y', action='store_true', default=False, help='Does not ask for confirmation before overriding')
create_parser.add_argument('--debug', '-d', action='store_true', default=False, help='Enable debug entries in logs')
create_parser.set_defaults(func=create)
# Command to run the FlameStore master or worker
......@@ -180,6 +182,7 @@ run_parser.add_argument('--worker', '-w', action='store_true', help='Run a Flame
run_parser.add_argument('--path', '-p', type=str, help='Path to the workspace', default='.')
run_parser.add_argument('--name', '-n', type=str, help='Name of the workspace', default='.')
run_parser.add_argument('--config', '-c', type=str, help='Alternative json configuration file', default='')
run_parser.add_argument('--debug', '-d', action='store_true', default=False, help='Enable debug entries in logs')
run_parser.set_defaults(func=run)
# Call the parser
......
......@@ -3,6 +3,8 @@ import sys
import numpy as np
import json
import warnings
import logging
import log
with warnings.catch_warnings():
warnings.filterwarnings("ignore",category=FutureWarning)
from keras.models import model_from_json
......@@ -13,6 +15,8 @@ from pybake.client import *
class MochiBackend():
def __init__(self, path='.', mid=None):
log.init_logging(logging.DEBUG)
self._logger = log.get_logger()
self._path = path
with open(path+'/.flamestore') as f:
info = json.loads(f.read())
......@@ -50,7 +54,7 @@ class MochiBackend():
metadata = json.loads(model.to_json())
target_info = self.__model_declare(name, metadata)
if('error' in target_info):
print("Server returned error: "+str(target_info['error']))
self._logger.error("Server returned error: "+str(target_info['error']))
return False
bake_target = list(target_info.keys())[0]
bake_addr_str = str(target_info[bake_target]['address'])
......@@ -60,12 +64,12 @@ class MochiBackend():
layer_md = self.__store_layer_data(bake_addr_str, bake_provider_id, bake_target, l)
if(type(layer_md) == bool and (not layer_md)):
# TODO: remove previously written regions and un-declare the model
print("Error: could not store model layer "+str(i))
self._logger.error("Error: could not store model layer "+str(i))
return False
metadata['config'][i]['data'] = layer_md
resp = self.__model_commit(name, metadata)
if('error' in resp):
print("Server returned error: "+str(resp['error']))
self._logger.error("Server returned error: "+str(resp['error']))
return False
else:
return True
......@@ -73,7 +77,7 @@ class MochiBackend():
def load_model(self, name):
resp = self.__model_locate(name)
if('error' in resp):
print("Server returned error: "+str(resp['error']))
self._logger.error("Server returned error: "+str(resp['error']))
return None
metadata = resp
model = model_from_json(json.dumps(metadata))
......@@ -102,8 +106,7 @@ class MochiBackend():
for i,w in enumerate(weights):
region = bake_ph.create_write_persist_numpy(bake_target, w)
if(region is None):
print("ERROR: region is None")
# TODO display an error message
self._logger.error("Could not create and write Bake region for layer")
return False
location = { 'type' : 'bake',
'address' : bake_addr_str,
......@@ -154,7 +157,7 @@ class MochiBackend():
target_info = self.__input_declare(name, md)
if('error' in target_info):
print("Server returned error: "+str(target_info['error']))
self._logger.error("Server returned error: "+str(target_info['error']))
return False
bake_target_str = list(target_info.keys())[0]
bake_addr_str = str(target_info[bake_target_str]['address'])
......@@ -165,7 +168,7 @@ class MochiBackend():
bake_target = BakeTargetID.from_str(str(bake_target_str))
region = bake_ph.create_write_persist_numpy(bake_target, array)
if(region is None):
print("Bake could not create region for input "+name)
self._logger.error("Bake could not create region for input "+name)
# TODO undo declare
return False
# Update location metadata
......@@ -178,7 +181,7 @@ class MochiBackend():
# Commit metadata
resp = self.__input_commit(name, md)
if('error' in resp):
print("Server returned error: "+str(resp['error']))
self._logger.error("Server returned error: "+str(resp['error']))
return False
else:
return True
......@@ -186,7 +189,7 @@ class MochiBackend():
def load_input(self, name, metadata_only=False):
resp = self.__input_locate(name)
if('error' in resp):
print("Server returned error: "+str(resp['error']))
self._logger.error("Server returned error: "+str(resp['error']))
return None
md = resp
metadata = md['metadata']
......
import logging
import log
import random
class DefaultController():
def __init__(self, config):
self._targets = []
self._logger = logging.getLogger('flamestore')
self._logger = log.get_logger()
self._logger.info("Initialized DefaultController")
def add_target(self, target_info):
......
import sys
from mochi.storage import StorageManager
from storage import StorageManager
from pymargo import MargoInstance
import importlib
import json
from finalizer import InstanceFinalizer
import log
class FlameStoreMaster():
def __init__(self, mid=None, path='.', config=None):
self._logger = log.get_logger()
if(config is None):
config = path+'/config.json'
......@@ -30,7 +32,7 @@ class FlameStoreMaster():
controller_module = importlib.import_module(controller_module_name)
controller_class = getattr(controller_module, controller_class_name)
except:
sys.stderr.write("[ERROR] Could not find controler class "+config['manager']['controller']+'\n')
self._logger.critical("Could not find controler class "+config['manager']['controller']+'\n')
sys.exit(-1)
controller = controller_class(config['manager']['controller']['config'])
......@@ -40,7 +42,7 @@ class FlameStoreMaster():
self._mid.on_finalize(InstanceFinalizer(self))
def _cleanup(self):
print("[INFO] Cleaning up master")
self._logger.info("Cleaning up Master")
del self._mid
def get_margo_instance(self):
......
......@@ -4,11 +4,14 @@ from pymargo import Provider
import os.path
import random
import json
import logging
import log
class StorageManager(Provider):
def __init__(self, mid, provider_id, path, controller):
super(StorageManager, self).__init__(mid, provider_id)
log.init_logging(logging.DEBUG)
self._logger = logging.getLogger('flamestore')
self.register("flame_add_storage_worker", "_add_storage_worker")
self.register("flame_model_declare", "_model_declare")
......
import logging
from flamestore.mochi.storage import StorageWorker
from storage import StorageWorker
from pymargo import MargoInstance
import pybake
import pybake.server
......
from keras.models import model_from_json
#from pfs import FileSystemBackend
#from hdf5 import HDF5Backend
from mochi.client import MochiBackend
from client import MochiBackend
import json
class WorkspaceHandle():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment