⚠️ Make sure to setup these 2 environment variables before using this package. You can either set them up by configuring the system environment variables or using python's os.environ[] method
import os
os.environ["DD_API_KEY"] = "" #Your Datadog API Key
os.environ["DD_SITE"] = "datadoghq.com"
-
Install pip package
pip install datadog-custom-logger==1.1.1
-
Import package
from datadog_custom_logger import DatadogCustomLogHandler
-
Initialize the handler
datadog_custom_handler = DatadogCustomLogHandler(level=logging.INFO)
💡Note: if the level is set to logging.WARNING, you won't be able to see info or debug level logs.
- debug (logging.DEBUG)
- info (logging.INFO)
- warning (logging.WARNING)
- error (logging.ERROR)
-
Attach the handler
logging.basicConfig() logger = logging.getLogger() logger.addHandler(datadog_custom_handler) logging.getLogger().setLevel(logging.INFO)
-
Now simply log the logs
# This statement won't be logged because the .setLevel() is set to logging.INFO. # Please check the logging hierarchy for more. logging.debug("This is debug level code") # This will be logged as per .setLevel() logging.info("This is info level logs")