1 # ================================================================================
2 # Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
3 # ================================================================================
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 # ============LICENSE_END=========================================================
17 """run as server: python -m otihandler"""
23 from otihandler.config import Config
24 from otihandler.onap.audit import Audit
25 from otihandler.web_server import DTIWeb
26 from otihandler.dbclient import DaoBase
29 class LogWriter(object):
30 """redirect the standard out + err to the logger"""
32 def __init__(self, logger_func):
33 self.logger_func = logger_func
35 def write(self, log_line):
36 """actual writer to be used in place of stdout or stderr"""
38 log_line = log_line.rstrip()
40 self.logger_func(log_line)
43 """no real flushing of the buffer"""
48 def run_event_handler():
49 """main run function for event_handler"""
51 Config.load_from_file()
54 logger = logging.getLogger("event_handler")
55 sys.stdout = LogWriter(logger.info)
56 sys.stderr = LogWriter(logger.error)
58 logger.info("========== run_event_handler ==========")
59 app_version = os.getenv("APP_VER")
60 logger.info("app_version %s", app_version)
61 Audit.init(Config.get_system_name(), app_version, Config.LOGGER_CONFIG_FILE_PATH)
63 logger.info("starting event_handler with config:")
64 logger.info(Audit.log_json_dumps(Config.config))
66 audit = Audit(req_message="start event_handler")
68 audit = Audit(req_message="DB init start")
69 DaoBase.init_db(os.environ.get("DB_CONN_URL"))
71 DTIWeb.run_forever(audit)
73 if __name__ == "__main__":