diff --git a/loris/webapp.py b/loris/webapp.py index 264057d1..6ce0cdbe 100755 --- a/loris/webapp.py +++ b/loris/webapp.py @@ -40,20 +40,32 @@ getcontext().prec = 25 # Decimal precision. This should be plenty. - -def get_debug_config(debug_jp2_transformer): +def get_default_config(): # change a few things, read the config and set up logging project_dp = path.dirname(path.dirname(path.realpath(__file__))) data_directory = path.join(project_dp, 'loris', 'data') config_file_path = path.join(data_directory, 'loris.conf') config = read_config(config_file_path) + config['data_directory'] = data_directory - config['logging']['log_to'] = 'console' - config['logging']['log_level'] = 'DEBUG' + if "logging" not in config: + config['logging'] = get_default_logging() + + return config + +def get_default_logging(): + return { + 'format': '%(asctime)s (%(name)s) [%(levelname)s]: %(message)s', + 'log_to': 'console', + 'log_level': 'DEBUG', + } + +def get_debug_config(debug_jp2_transformer): + config = get_default_config() # override some stuff to look at relative or tmp directories. - config['loris.Loris']['www_dp'] = path.join(data_directory, 'www') + config['loris.Loris']['www_dp'] = path.join(config['data_directory'], 'www') config['loris.Loris']['tmp_dp'] = '/tmp/loris/tmp' config['loris.Loris']['enable_caching'] = True config['img.ImageCache']['cache_dp'] = '/tmp/loris/cache/img' @@ -96,7 +108,13 @@ def create_app(debug=False, debug_jp2_transformer='kdu', config_file_path=''): def read_config(config_file_path): - config = ConfigObj(config_file_path, unrepr=True, interpolation='template') + if len(config_file_path) > 0: + config = ConfigObj(config_file_path, unrepr=True, interpolation='template') + else: + config = get_default_config() + tmp_logger = configure_logging(config['logging']) + tmp_logger.info("No config file path defined. Using default config") + # add the OS environment variables as the DEFAULT section to support # interpolating their values into other keys # make a copy of the os.environ dictionary so that the config object can't @@ -781,7 +799,7 @@ def _make_image(self, image_request, image_info): sys.path.append(path.join(project_dp)) # to find any local resolvers - app = create_app(debug=True) # or 'opj' + app = create_app(debug=False) # or 'opj' run_simple('localhost', 5004, app, use_debugger=True, use_reloader=True) # To debug ssl: