This package provides logging.Handler implementations that will send message to a slack channel. Supports updated slack.WebClient API released in 2020.
Limitations
How often messages can be sent is limited by slack. See https://api.slack.com/docs/rate-limits. By default, this handler only sends accumulated messages every 60 seconds. That can be adjusted by the optional update argument to SlackHandler.
send_remaining() should be called prior to program exit to send any remaining messages.
Example
from nmrbox_slack import SlackHandler
token = 'your token here'
channel = 'your channel name'
handler = SlackHandler(token, channel)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
example_logger = logging.getLogger("Test Logger")
example_logger.propagate = False
example_logger.addHandler(handler)
example_logger.setLevel(logging.INFO)
example_logger.info("Then shalt thou use Python three, no more, no less.")
...
# at end of program
handler.send_remaining()
Variants
Two versions are currently supported.
SlackHandler connects to slack upon creation and validates the token and channel name.
LazySlackHandler does not attempt to connect to slack until the first message is sent.
SlackHandler is recommended if it is known messages are to be sent. LazySlackHandler is available to reduce overhead of processes which typically do not send messages.
Additional channels
Sending to additional channels may be done more efficiently with the SlackHandler.additional_channel_handler() method.
from nmrbox_slack.slacklogger import SlackHandler
token = 'your token here'
channel = 'your channel name'
handler = SlackHandler(token, channel)
second_handler = heandler.additional_channel_handler('second channel name')
From mapping
from_mapping(mapping:Mapping,,lazy:bool)* will return a SlackHandler or LazySlackHandler from a mapping:
{'slack:
{
'channel':<channel name>,
'token file': <file with token in it>
}
}
Release history
2.0 New API from slack 2.2.2 Add pagination
Funding acknowledgment
This work supported by National Institutes of Health (NIH) / National Institute of General Medical Sciences (NIGMS), grant 1P41GM111135.
Metadata
Release files for slack-webclient-logger 2.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| slack_webclient_logger-2.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Release files / slack_webclient_logger-2.2.2-py3-none-any.whl
| Download URL | slack_webclient_logger-2.2.2-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d2f3243d70594f637ca398e5a8b3ec9cec2aa23c7f13b8daf316e60a923a2f7b
|
|
BLAKE2b-256 checksum How to use checksums |
b864a082fce71455030e9250c8833496b32c1fb518fa0790b737a67be5bb550a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/65.6.3 requests-toolbelt/0.8.0 tqdm/4.64.1 CPython/3.8.10
|