"""Application Logger. ====================== Creates application logger instance. If config.LOGGER_DSN value is not set, the logs will be sent to stdout. """ import logging import uuid from owslogger import logger import sentry_sdk from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration from disable_inactive_users import config # exception logger sentry_sdk.init(config.SENTRY_DSN, integrations=[AwsLambdaIntegration()]) # application logger app_logger = logger.setup( config.LOGGER_DSN, config.ENVIRONMENT, 'ows1', (logging.DEBUG if config.ENVIRONMENT == config.PROD_ENVIRONMENT else logging.INFO), config.APPLICATION_NAME, config.APPLICATION_VERSION) def get_current_logger(correlation_id=None): """Get logger with a correlation_id attached. Args: correlation_id: correlation_id that will be sent along with log record Returns: logger.OwsLoggingAdapter: instance of OwsLoggingAdapter with correlation_id attached. """ return logger.OwsLoggingAdapter(app_logger, { 'correlation_id': correlation_id or uuid.uuid4() })