datadog logger

This commit is contained in:
wassname
2019-01-18 10:18:57 +08:00
parent 75c5006a1c
commit 383d8d214c
+13 -1
View File
@@ -23,15 +23,27 @@ file_handler.setFormatter(formatter)
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setLevel(logging.INFO)
import datadog
from datadog_logger import DatadogLogHandler
json_formatter = logging.Formatter('{ "loggerName":"%(name)s", "asciTime":"%(asctime)s", "fileName":"%(filename)s", "logRecordCreationTime":"%(created)f", "functionName":"%(funcName)s", "levelNo":"%(levelno)s", "lineNo":"%(lineno)d", "time":"%(msecs)d", "levelName":"%(levelname)s", "message":"%(message)s"}')
datadog.initialize(api_key="4bc53c4318964cd97489b3c1c5401c50", app_key="c07cf0fb03e363228c67f695cc957422a2763d65")
datadog_handler = DatadogLogHandler(level=logging.INFO)
# The handlers have to be at a root level since they are the final output
logging.basicConfig(
level=logging.DEBUG,
format='[{%(filename)s:%(lineno)d} %(levelname)s - %(message)s',
handlers=[
file_handler,
stream_handler
stream_handler,
]
)
logger = logging.getLogger('bitlit')
logger.addHandler(datadog_handler)
logger.info('Logging to STDOUT and {}'.format(filename))