2022-08-07 13:27:59 +01:00
|
|
|
"""Root module containing Mixonomer backend
|
2021-03-23 22:26:59 +00:00
|
|
|
|
|
|
|
Top level module with functions for creating app with loaded blueprints and initialising the logging stack
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2019-08-17 18:30:13 +01:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
logger.setLevel('DEBUG')
|
|
|
|
|
2019-09-05 12:20:21 +01:00
|
|
|
spotframework_logger = logging.getLogger('spotframework')
|
2019-10-07 12:21:26 +01:00
|
|
|
fmframework_logger = logging.getLogger('fmframework')
|
|
|
|
spotfm_logger = logging.getLogger('spotfm')
|
2019-09-05 12:20:21 +01:00
|
|
|
|
2021-02-08 16:18:16 +00:00
|
|
|
def init_log(cloud=False, console=False):
|
|
|
|
if cloud:
|
|
|
|
import google.cloud.logging
|
|
|
|
from google.cloud.logging.handlers import CloudLoggingHandler
|
|
|
|
|
|
|
|
log_format = '%(funcName)s - %(message)s'
|
|
|
|
formatter = logging.Formatter(log_format)
|
2019-08-17 18:30:13 +01:00
|
|
|
|
2021-02-08 16:18:16 +00:00
|
|
|
client = google.cloud.logging.Client()
|
|
|
|
handler = CloudLoggingHandler(client, name="music-tools")
|
2019-08-17 18:30:13 +01:00
|
|
|
|
2021-02-08 16:18:16 +00:00
|
|
|
handler.setFormatter(formatter)
|
2019-08-17 18:30:13 +01:00
|
|
|
|
2021-02-08 16:18:16 +00:00
|
|
|
logger.addHandler(handler)
|
|
|
|
spotframework_logger.addHandler(handler)
|
|
|
|
fmframework_logger.addHandler(handler)
|
|
|
|
spotfm_logger.addHandler(handler)
|
2019-08-17 18:30:13 +01:00
|
|
|
|
2021-02-08 16:18:16 +00:00
|
|
|
if console:
|
|
|
|
log_format = '%(levelname)s %(name)s:%(funcName)s - %(message)s'
|
|
|
|
formatter = logging.Formatter(log_format)
|
2019-08-17 18:30:13 +01:00
|
|
|
|
2021-02-08 16:18:16 +00:00
|
|
|
stream_handler = logging.StreamHandler()
|
|
|
|
stream_handler.setFormatter(formatter)
|
2019-08-17 18:30:13 +01:00
|
|
|
|
2021-02-08 16:18:16 +00:00
|
|
|
logger.addHandler(stream_handler)
|
|
|
|
spotframework_logger.addHandler(stream_handler)
|
|
|
|
fmframework_logger.addHandler(stream_handler)
|
|
|
|
spotfm_logger.addHandler(stream_handler)
|
2019-08-17 18:30:13 +01:00
|
|
|
|
2021-02-08 16:18:16 +00:00
|
|
|
if os.environ.get('DEPLOY_DESTINATION', None) == 'PROD':
|
|
|
|
init_log(cloud=True)
|