{"id":27930,"library":"logdna","title":"LogDNA Python Logger","description":"A Python package for sending logs to LogDNA (now Mezmo). This library provides both a standard logging handler and a custom LogDNA logger class. Current version: 1.18.12. Release cadence is irregular, primarily bugfixes.","status":"active","version":"1.18.12","language":"python","source_language":"en","source_url":"https://github.com/logdna/python","tags":["logging","log-management","logdna","mezmo","handler"],"install":[{"cmd":"pip install logdna","lang":"bash","label":"Install via pip"}],"dependencies":[{"reason":"Used for HTTP communication with LogDNA ingestion endpoint","package":"requests","optional":false},{"reason":"Provides SSL certificate bundle for secure connections","package":"certifi","optional":false}],"imports":[{"note":"LogDNAHandler is not a submodule; the correct import is from the top-level package.","wrong":"from logdna.handler import LogDNAHandler","symbol":"LogDNAHandler","correct":"from logdna import LogDNAHandler"},{"note":"LogDNALogger is exported directly from logdna package.","wrong":"from logdna.logger import LogDNALogger","symbol":"LogDNALogger","correct":"from logdna import LogDNALogger"},{"note":"StreamHandler is a standard library class, not part of logdna.","wrong":"from logdna import StreamHandler","symbol":"StreamHandler","correct":"from logging import StreamHandler"}],"quickstart":{"code":"import os\nimport logging\nfrom logdna import LogDNAHandler\n\n# Use environment variables for credentials\nkey = os.environ.get('LOGDNA_INGESTION_KEY', '')\n# If you have a custom ingestion host, set LOGDNA_URL\nurl = os.environ.get('LOGDNA_URL', 'https://logs.logdna.com/logs/ingest')\n\nlogger = logging.getLogger('logdna')\nlogger.setLevel(logging.INFO)\n\nhandler = LogDNAHandler(\n    key=key,\n    url=url,\n    index_meta=True,  # Optional: index metadata as searchable fields\n    tags=['python', 'test'],\n    app='myapp',\n    env='production',\n    level=logging.INFO,\n)\nlogger.addHandler(handler)\n\nlogger.info('Hello from LogDNA Python logger!', {\"custom\": \"metadata\"})\n\n# Ensure logs are flushed before exit\nimport atexit\natexit.register(handler.flush)","lang":"python","description":"Minimal setup for sending logs to LogDNA using LogDNAHandler. Replace LOGDNA_INGESTION_KEY with your actual key."},"warnings":[{"fix":"Upgrade to >= 1.18.10 or ensure your network config allows the 'apikey' header. The library automatically uses the new header; no code change required if using the same key parameter.","message":"In version 1.18.10, authentication was changed to use the 'apikey' HTTP header instead of the 'Authorization' header. Older versions used 'Authorization: Bearer <key>'. This breaks compatibility with setups that relied on the old header format.","severity":"breaking","affected_versions":"< 1.18.10"},{"fix":"Register an atexit handler: `atexit.register(handler.flush)` or flush manually before exit.","message":"LogDNAHandler.flush() must be called explicitly on program exit to avoid losing buffered logs. The library does not auto-flush on shutdown.","severity":"gotcha","affected_versions":"all"},{"fix":"When creating the handler, include `index_meta=True` to index metadata fields.","message":"The LogDNAHandler's 'index_meta' parameter defaults to False. If you pass metadata as a dictionary and expect it to be searchable, set index_meta=True explicitly.","severity":"gotcha","affected_versions":"all"},{"fix":"Avoid using this option in production. If you must, set it to True (default) to see errors.","message":"The 'log_error_response' option was introduced in v1.18.3 for debugging but is not officially documented. It silences errors when set to False, which may hide connectivity issues.","severity":"deprecated","affected_versions":">= 1.18.3"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Use `from logdna import LogDNAHandler` instead of `from logging import LogDNAHandler`.","cause":"Trying to import LogDNAHandler as a standard library class.","error":"AttributeError: module 'logging' has no attribute 'LogDNAHandler'"},{"fix":"Verify your LOGDNA_URL is correct and network allows outbound traffic to logs.logdna.com:443. If using a proxy, configure it via environment variables (e.g., HTTP_PROXY, HTTPS_PROXY).","cause":"Network/firewall blocking outbound HTTPS to LogDNA ingestion endpoint, or invalid URL.","error":"requests.exceptions.ConnectionError: HTTPSConnectionPool(host='logs.logdna.com', port=443): Max retries exceeded with url: /logs/ingest"},{"fix":"Set LOGDNA_INGESTION_KEY environment variable to a valid key. Check that the key is not expired.","cause":"Invalid or missing ingestion key.","error":"logdna.exceptions.LogDNAError: 401 Unauthorized"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}