Skip to content

Commit

Permalink
Merge pull request #123 from axiomhq/arne/logger-docs
Browse files Browse the repository at this point in the history
Add logger example
  • Loading branch information
darach authored Sep 9, 2024
2 parents 43e254b + 30d500a commit 8801b56
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,26 @@ client.ingest_events(
client.query(r"['my-dataset'] | where foo == 'bar' | limit 100")
```

for more examples, check out `examples.py`.
For more examples, see [`examples/client.py`](examples/client.py).

## Logger

You can use the `AxiomHandler` to send logs from the `logging` module to Axiom
like this:

```python
import axiom_py
from axiom_py.logging import AxiomHandler
import logging


def setup_logger():
client = axiom_py.Client()
handler = AxiomHandler(client, "my-dataset")
logging.getLogger().addHandler(handler)
```

For a full example, see [`examples/logger.py`](examples/logger.py).

## Contributing

Expand Down
File renamed without changes.
19 changes: 19 additions & 0 deletions examples/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import axiom_py
from axiom_py.logging import AxiomHandler
import logging


def main():
# Add Axiom handler to root logger
client = axiom_py.Client()
handler = AxiomHandler(client, "my-dataset")
logging.getLogger().addHandler(handler)

# Get logger and log something
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.info("Hello world")


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion src/axiom_py/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AxiomHandler(Handler):
last_run: float

def __init__(self, client: Client, dataset: str, level=NOTSET, interval=1):
Handler.__init__(self, level)
super().__init__()
# set urllib3 logging level to warning, check:
# https://github.com/axiomhq/axiom-py/issues/23
# This is a temp solution that would stop requests
Expand Down

0 comments on commit 8801b56

Please sign in to comment.