diff --git a/README.md b/README.md index 8d6dfa7..01f0f11 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/examples.py b/examples/client.py similarity index 100% rename from examples.py rename to examples/client.py diff --git a/examples/logger.py b/examples/logger.py new file mode 100644 index 0000000..5bf1edf --- /dev/null +++ b/examples/logger.py @@ -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() diff --git a/src/axiom_py/logging.py b/src/axiom_py/logging.py index ea76b7f..0ff62cc 100644 --- a/src/axiom_py/logging.py +++ b/src/axiom_py/logging.py @@ -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