logging-slacker


Namelogging-slacker JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/s3m3dov/logging_slacker
SummaryPosts log events to Slack via API
upload_time2023-08-18 13:31:04
maintainer
docs_urlNone
authorHikmat Samadov
requires_python
license
keywords slack logging
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # logging_slacker

[![image](https://img.shields.io/pypi/v/log-to-slack.svg?style=flat-square)](https://pypi.python.org/pypi/log-to-slack)
[![image](https://img.shields.io/pypi/wheel/log-to-slack.svg?style=flat-square)](https://pypi.python.org/pypi/log-to-slack)
[![image](https://img.shields.io/pypi/format/log-to-slack.svg?style=flat-square)](https://pypi.python.org/pypi/log-to-slack)
[![image](https://img.shields.io/pypi/pyversions/log-to-slack.svg?style=flat-square)](https://pypi.python.org/pypi/log-to-slack)
[![image](https://img.shields.io/pypi/status/log-to-slack.svg?style=flat-square)](https://pypi.python.org/pypi/log-to-slack)

Python log handler that posts to a Slack channel. Posts to the Slack API
using [Python Slack SDK](https://github.com/slackapi/python-slack-sdk).

Related Repos: 
  - Mathias Ose: [slacker_log_handler](https://github.com/mathiasose/slacker_log_handler)
  - [log-to-slack](https://github.com/pandianmn/log_to_slack)
  - [python-slack-logger](https://github.com/junhwi/python-slack-logger/)

## Installation

``` bash
pip install logging_slacker
```

## Arguments
- slack_token (str): The Slack API token if not using `webhook_url`
  Generate a key at <https://api.slack.com/>
- channel (str): The Slack channel to post to if not using `webhook_url`
- webhook_url (str): The Slack webhook URL if using `webhook_url`
- is_webhook (bool): Whether to use webhook_url or not (Defaults to `True`)
- is_debug (bool): Doesn't send Slack messages if True (Defaults to `False`)
- stack_trace (bool): Whether to include the stacktrace in the Slack message (Defaults to `True`)
- username (str): The username to use for the Slack message (Not usable if using `webhook_url`)
- icon_url (str): The icon URL to use for the Slack message (Not usable if using `webhook_url`)
- icon_emoji (str): The icon emoji to use for the Slack message (Not usable if using `webhook_url`)
- msg_len (int): The maximum length of the Slack message (Defaults to `1300`)
- traceback_len (int): The maximum length of the stack_trace (Defaults to `700`)
- fail_silent (bool): Whether to fail silently if the Slack API returns an error (Defaults to `False`)
  Defaults to `False`. If your API key is invalid or for some other reason
  the API call returns an error, this option will silently ignore the API
  error. If you enable this setting, **make sure you have another log
  handler** that will also handle the same log events, or they may be lost
  entirely.

## Example Python logging handler

This is how you use log_to_slack as a regular Python
logging handler. This example will send a error message to a slack
channel.

``` python
import logging
import os

from log_to_slack import SlackLogHandler
from log_to_slack.formatters import NoStacktraceFormatter, DefaultFormatter

WEBHOOK_URL = os.getenv("WEBHOOK_URL")

logger = logging.getLogger("debug_application")
logger.setLevel(logging.DEBUG)

default_formatter = DefaultFormatter("%(levelprefix)s %(asctime)s (%(name)s) %(message)s")
no_stacktrace_formatter = NoStacktraceFormatter("%(levelprefix)s %(asctime)s (%(name)s) %(message)s")

default_handler = logging.StreamHandler()
default_handler.setFormatter(default_formatter)
logger.addHandler(default_handler)

slack_handler = SlackLogHandler(webhook_url=WEBHOOK_URL, stack_trace=True)
slack_handler.setFormatter(no_stacktrace_formatter)
slack_handler.setLevel(logging.ERROR)
logger.addHandler(slack_handler)

# Main code
logger.debug("Test DEBUG")
logger.info("Test INFO")
logger.warning("Test WARNING")
logger.error("Test ERROR")
logger.fatal("Test FATAL")
logger.critical("Test CRITICAL")

try:
    raise Exception("Test exception")
except Exception as e:
    logger.exception(e)

```

## Slack message formatting

This example use a subclass that will send a formatted message to a
Slack channel. [Learn More](https://api.slack.com/reference/surfaces/formatting)

``` python
class CustomLogHandler(SlackLogHandler):
    def build_msg(self, record):
        message = "> New message :\n" + record.getMessage()
        return message
```

## License

Apache 2.0

See also: <https://api.slack.com/terms-of-service>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/s3m3dov/logging_slacker",
    "name": "logging-slacker",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "slack,logging",
    "author": "Hikmat Samadov",
    "author_email": "hikmat@cublya.com",
    "download_url": "https://files.pythonhosted.org/packages/df/17/76a5b01ece8b8cacddd6bb3deb2011585a384775fc3466650c9b31485f0d/logging_slacker-0.1.0.tar.gz",
    "platform": null,
    "description": "# logging_slacker\n\n[![image](https://img.shields.io/pypi/v/log-to-slack.svg?style=flat-square)](https://pypi.python.org/pypi/log-to-slack)\n[![image](https://img.shields.io/pypi/wheel/log-to-slack.svg?style=flat-square)](https://pypi.python.org/pypi/log-to-slack)\n[![image](https://img.shields.io/pypi/format/log-to-slack.svg?style=flat-square)](https://pypi.python.org/pypi/log-to-slack)\n[![image](https://img.shields.io/pypi/pyversions/log-to-slack.svg?style=flat-square)](https://pypi.python.org/pypi/log-to-slack)\n[![image](https://img.shields.io/pypi/status/log-to-slack.svg?style=flat-square)](https://pypi.python.org/pypi/log-to-slack)\n\nPython log handler that posts to a Slack channel. Posts to the Slack API\nusing [Python Slack SDK](https://github.com/slackapi/python-slack-sdk).\n\nRelated Repos: \n  - Mathias Ose: [slacker_log_handler](https://github.com/mathiasose/slacker_log_handler)\n  - [log-to-slack](https://github.com/pandianmn/log_to_slack)\n  - [python-slack-logger](https://github.com/junhwi/python-slack-logger/)\n\n## Installation\n\n``` bash\npip install logging_slacker\n```\n\n## Arguments\n- slack_token (str): The Slack API token if not using `webhook_url`\n  Generate a key at <https://api.slack.com/>\n- channel (str): The Slack channel to post to if not using `webhook_url`\n- webhook_url (str): The Slack webhook URL if using `webhook_url`\n- is_webhook (bool): Whether to use webhook_url or not (Defaults to `True`)\n- is_debug (bool): Doesn't send Slack messages if True (Defaults to `False`)\n- stack_trace (bool): Whether to include the stacktrace in the Slack message (Defaults to `True`)\n- username (str): The username to use for the Slack message (Not usable if using `webhook_url`)\n- icon_url (str): The icon URL to use for the Slack message (Not usable if using `webhook_url`)\n- icon_emoji (str): The icon emoji to use for the Slack message (Not usable if using `webhook_url`)\n- msg_len (int): The maximum length of the Slack message (Defaults to `1300`)\n- traceback_len (int): The maximum length of the stack_trace (Defaults to `700`)\n- fail_silent (bool): Whether to fail silently if the Slack API returns an error (Defaults to `False`)\n  Defaults to `False`. If your API key is invalid or for some other reason\n  the API call returns an error, this option will silently ignore the API\n  error. If you enable this setting, **make sure you have another log\n  handler** that will also handle the same log events, or they may be lost\n  entirely.\n\n## Example Python logging handler\n\nThis is how you use log_to_slack as a regular Python\nlogging handler. This example will send a error message to a slack\nchannel.\n\n``` python\nimport logging\nimport os\n\nfrom log_to_slack import SlackLogHandler\nfrom log_to_slack.formatters import NoStacktraceFormatter, DefaultFormatter\n\nWEBHOOK_URL = os.getenv(\"WEBHOOK_URL\")\n\nlogger = logging.getLogger(\"debug_application\")\nlogger.setLevel(logging.DEBUG)\n\ndefault_formatter = DefaultFormatter(\"%(levelprefix)s %(asctime)s (%(name)s) %(message)s\")\nno_stacktrace_formatter = NoStacktraceFormatter(\"%(levelprefix)s %(asctime)s (%(name)s) %(message)s\")\n\ndefault_handler = logging.StreamHandler()\ndefault_handler.setFormatter(default_formatter)\nlogger.addHandler(default_handler)\n\nslack_handler = SlackLogHandler(webhook_url=WEBHOOK_URL, stack_trace=True)\nslack_handler.setFormatter(no_stacktrace_formatter)\nslack_handler.setLevel(logging.ERROR)\nlogger.addHandler(slack_handler)\n\n# Main code\nlogger.debug(\"Test DEBUG\")\nlogger.info(\"Test INFO\")\nlogger.warning(\"Test WARNING\")\nlogger.error(\"Test ERROR\")\nlogger.fatal(\"Test FATAL\")\nlogger.critical(\"Test CRITICAL\")\n\ntry:\n    raise Exception(\"Test exception\")\nexcept Exception as e:\n    logger.exception(e)\n\n```\n\n## Slack message formatting\n\nThis example use a subclass that will send a formatted message to a\nSlack channel. [Learn More](https://api.slack.com/reference/surfaces/formatting)\n\n``` python\nclass CustomLogHandler(SlackLogHandler):\n    def build_msg(self, record):\n        message = \"> New message :\\n\" + record.getMessage()\n        return message\n```\n\n## License\n\nApache 2.0\n\nSee also: <https://api.slack.com/terms-of-service>\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Posts log events to Slack via API",
    "version": "0.1.0",
    "project_urls": {
        "Download": "https://github.com/s3m3dov/logging_slacker/archive/0.1.0.tar.gz",
        "Homepage": "https://github.com/s3m3dov/logging_slacker"
    },
    "split_keywords": [
        "slack",
        "logging"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "44916b71e0a0c9e42d7f62df846dce5d005af963c98a087e37991a8917dcf7ce",
                "md5": "bd112fd736531fa5ab57a4161a5639f0",
                "sha256": "d94c5fa93f89e29b519f2aad2a5fc6def712fbc6fa7be3077e07e2d55a94f296"
            },
            "downloads": -1,
            "filename": "logging_slacker-0.1.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bd112fd736531fa5ab57a4161a5639f0",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 9653,
            "upload_time": "2023-08-18T13:31:02",
            "upload_time_iso_8601": "2023-08-18T13:31:02.686863Z",
            "url": "https://files.pythonhosted.org/packages/44/91/6b71e0a0c9e42d7f62df846dce5d005af963c98a087e37991a8917dcf7ce/logging_slacker-0.1.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "df1776a5b01ece8b8cacddd6bb3deb2011585a384775fc3466650c9b31485f0d",
                "md5": "bae1e0fc4418ff860e2d6077895fbd4c",
                "sha256": "7dd562edb39e1d41bcb832eb5fa1391f9ece15845fad8e057c6a7e046d50bf4b"
            },
            "downloads": -1,
            "filename": "logging_slacker-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "bae1e0fc4418ff860e2d6077895fbd4c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9636,
            "upload_time": "2023-08-18T13:31:04",
            "upload_time_iso_8601": "2023-08-18T13:31:04.639139Z",
            "url": "https://files.pythonhosted.org/packages/df/17/76a5b01ece8b8cacddd6bb3deb2011585a384775fc3466650c9b31485f0d/logging_slacker-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-18 13:31:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "s3m3dov",
    "github_project": "logging_slacker",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "logging-slacker"
}
        
Elapsed time: 0.10496s