#!/usr/bin/env python
"""
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  This file is part of the Smart Developer Hub Project:
    http://www.smartdeveloperhub.org

  Center for Open Middleware
        http://www.centeropenmiddleware.com/
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  Copyright (C) 2015 Center for Open Middleware.
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
"""

import logging

import json
from sdh.curator.server import app
import os
from sdh.curator import metadata

__author__ = 'Fernando Serena'

log_level = int(os.environ.get('LOG_LEVEL', logging.INFO))
if log_level is None:
    log_level = int(app.config['LOG'])

ch = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
ch.setLevel(log_level)
logger = logging.getLogger('agora')
logger.addHandler(ch)
logger.setLevel(log_level)
logger = logging.getLogger('sdh')
logger.addHandler(ch)
logger.setLevel(log_level)
logger = logging.getLogger('sdh.curator.bootstrap')

logger.info('--- Starting SDH Curator v{} ---'.format(metadata.get('version')))

logger.info('Loading API description...')
from sdh.curator import api

logger.info('Loading messaging system and daemons...')
import sdh.curator.messaging


logger.info('Starting REST API...')

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=app.config['PORT'], debug=False, use_reloader=False)
