12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- # -*- coding: utf-8 -*-
- # @Time : 2023/7/31 15:27
- # @Author : XuJiakai
- # @File : sls_log
- # @Software: PyCharm
- import logging.config, os
- import platform
- __version__ = '0.1.0'
- def __is_test_env():
- return os.environ.get('SPIDER_TEST', False) or platform.system() == "Windows"
- def __get_endpoint():
- if __is_test_env():
- return "cn-shanghai.log.aliyuncs.com"
- else:
- return "cn-shanghai-intranet.log.aliyuncs.com"
- conf = {'version': 1,
- 'disable_existing_loggers': False,
- 'formatters': {'rawformatter': {'class': 'logging.Formatter',
- 'format': '%(message)s'}
- },
- 'handlers': {'sls_handler': {'()':
- 'aliyun.log.QueuedLogHandler',
- 'level': 'INFO',
- 'formatter': 'rawformatter',
- # custom args:
- 'end_point': os.environ.get('ALIYUN_LOG_ENDPOINT', __get_endpoint()),
- 'access_key_id': os.environ.get('ALIYUN_LOG_ACCESSID', 'LTAI4GKTLebfci8tYSM1NFCN'),
- 'access_key': os.environ.get('ALIYUN_LOG_ACCESSKEY', 'v59Sy885c9GfXZ4me9caIxYHh9CPVc'),
- 'project': os.environ.get('ALIYUN_LOG_PROJECT', 'data-clean'),
- 'log_store': os.environ.get('ALIYUN_LOG_STORE', "clean"),
- 'extract_json': True,
- 'extract_json_prefix': 'dc_',
- }
- },
- 'loggers': {'sls': {'handlers': ['sls_handler', ],
- 'level': 'INFO',
- 'propagate': False}
- }
- }
- logging.config.dictConfig(conf)
- def get_logger():
- return logging.getLogger("sls")
|