https://github.com/bufferapp/stacklogging
Python logging integration with Google Cloud Stackdriver API.
https://github.com/bufferapp/stacklogging
Last synced: 9 months ago
JSON representation
Python logging integration with Google Cloud Stackdriver API.
- Host: GitHub
- URL: https://github.com/bufferapp/stacklogging
- Owner: bufferapp
- License: mit
- Created: 2018-09-18T09:15:15.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2020-10-01T07:04:08.000Z (over 5 years ago)
- Last Synced: 2025-03-29T10:23:45.935Z (10 months ago)
- Language: Python
- Homepage:
- Size: 16.6 KB
- Stars: 12
- Watchers: 6
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Stacklogging
[](LICENSE)
[](https://badge.fury.io/py/stacklogging)
This small library generates log entries that are understood by Stackdriver Logging. You won't need to authenticate in GCE. The logs emmited will be in [JSON schema understood by Stackdriver API](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry) and [Stackdriver Logging](https://cloud.google.com/error-reporting/docs/formatting-error-messages).
## Installation
You can use `pip` to install `stacklogging`:
```bash
pip install stacklogging
```
## Usage
```python
import stacklogging
logger = stacklogging.getLogger()
def sum(a, b):
logger.info(f"Adding {a} and {b}")
return a + b
r = sum(2, 4)
```
This will output a JSON like this one:
```json
{
"message": "Adding 2 and 4",
"timestamp": {
"seconds": 1548239928,
"nanos": 380779027
},
"thread": 140619343472128,
"severity": "INFO"
}
```
It is also possible to log extra fields at runtime using the `extra` parameter.
```python
logger.info("message", extra={"from": "Alice", "to": "Bob"})
```
Stacklogging will add the extra keys to the final JSON:
```json
{
"message": "Email sent",
"timestamp": {
"seconds": 1548260191,
"nanos": 256482124
},
"thread": 140166127678976,
"severity": "INFO",
"from": "Alice",
"to": "Bob"
}
```
## License
MIT © Buffer