|
@@ -1,7 +1,37 @@
|
|
|
-import os
|
|
|
import logging
|
|
|
+import logging.config
|
|
|
+import os
|
|
|
import time
|
|
|
|
|
|
+from config import set_config
|
|
|
+
|
|
|
+config_ = set_config()
|
|
|
+
|
|
|
+# 配置
|
|
|
+conf = {'version': 1,
|
|
|
+ 'formatters': {'rawformatter': {'class': 'logging.Formatter',
|
|
|
+ 'format': '%(message)s'}
|
|
|
+ },
|
|
|
+ 'handlers': {'sls_handler': {'()':
|
|
|
+ 'aliyun.log.QueuedLogHandler',
|
|
|
+ 'level': 'INFO',
|
|
|
+ 'formatter': 'rawformatter',
|
|
|
+
|
|
|
+ # custom args:
|
|
|
+ 'end_point': config_.ALIYUN_LOG.get('ENDPOINT', ''),
|
|
|
+ 'access_key_id': config_.ALIYUN_LOG.get('ACCESSID', ''),
|
|
|
+ 'access_key': config_.ALIYUN_LOG.get('ACCESSKEY', ''),
|
|
|
+ 'project': config_.ALIYUN_LOG.get('PROJECT', ''),
|
|
|
+ 'log_store': "info"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ 'loggers': {'sls': {'handlers': ['sls_handler', ],
|
|
|
+ 'level': 'INFO',
|
|
|
+ 'propagate': False}
|
|
|
+ }
|
|
|
+ }
|
|
|
+logging.config.dictConfig(conf)
|
|
|
+
|
|
|
|
|
|
class Log(object):
|
|
|
# def __init__(self, pag_source, log_path=os.path.join(os.path.dirname(os.path.realpath(__file__)), "logs")):
|
|
@@ -12,7 +42,7 @@ class Log(object):
|
|
|
# 文件的命名
|
|
|
# self.logname = os.path.join(log_path, '{}_{}.log'.format(pag_source, time.strftime('%Y%m%d')))
|
|
|
self.logname = os.path.join(log_path, '{}.log'.format(time.strftime('%Y%m%d')))
|
|
|
- self.logger = logging.getLogger()
|
|
|
+ self.logger = logging.getLogger('sls')
|
|
|
self.logger.setLevel(logging.DEBUG)
|
|
|
# 日志输出格式
|
|
|
self.formatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s')
|