https://github.com/ivaltryek/datadog-custom-logger
A custom Python logger for DataDog logging
https://github.com/ivaltryek/datadog-custom-logger
datadog datadog-logs python-logger
Last synced: 3 months ago
JSON representation
A custom Python logger for DataDog logging
- Host: GitHub
- URL: https://github.com/ivaltryek/datadog-custom-logger
- Owner: ivaltryek
- License: mit
- Created: 2021-08-02T10:54:29.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-08-13T15:55:28.000Z (almost 4 years ago)
- Last Synced: 2025-03-20T06:42:59.277Z (3 months ago)
- Topics: datadog, datadog-logs, python-logger
- Language: Python
- Homepage:
- Size: 21.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Datadog Custom Logger
[](https://pypi.org/project/datadog-custom-logger/)
[](https://open.vscode.dev/meet86/datadog-custom-logger)## Usage
>⚠️ 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
## Example
```python
import os
os.environ["DD_API_KEY"] = "" #Your Datadog API Key
os.environ["DD_SITE"] = "datadoghq.com"
```### Steps
- Install pip package
```shell
pip install datadog-custom-logger==1.1.1
```
- Import package
```python
from datadog_custom_logger import DatadogCustomLogHandler
```
- Initialize the handler
```python
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.## Hierarchy:
- debug (logging.DEBUG)
- info (logging.INFO)
- warning (logging.WARNING)
- error (logging.ERROR)
- Attach the handler
```python
logging.basicConfig()
logger = logging.getLogger()
logger.addHandler(datadog_custom_handler)
logging.getLogger().setLevel(logging.INFO)
```
- Now simply log the logs
```python
# 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")
```## Complete example:
[](https://github.com/meet86/datadog-logger-example)