An extremely simple logging handler for relaying log events to ntfy
Project description
ntfy-handler
This repo contains an extremely simple logging handler that relays log events to ntfy.
Installation
pip install ntfy-handler
Usage
import logging
from ntfy_handler import NtfyHandler
logger = logging.getLogger()
logging.basicConfig()
nh = NtfyHandler(topic_name="my_topic")
logger.addHandler(nh)
logger.info("Info!")
Advanced Options
In addition to topic_name, the following parameters can be passed to a NtfyHandler during construction:
| Parameter Name | Type | Description | Default Value |
|---|---|---|---|
server_url |
str |
The base URL of the ntfy server to utilize. | "https://ntfy.sh" |
log_level_priority_map |
Optional[Dict[int, int]] |
A dict of {log_level: ntfy_priority} items, where log_level is defined as a log_level // 10 * 10, and ntfy_priority is the priority to use when sending the ntfy message. |
See below |
ntfy_headers |
Optional[Dict[str, Union[str, bytes]]] |
A dict of headers to be used when sending a ntfy message. | None |
access_token |
Optional[str] |
An access token to use when sending a message, retrieved from the /account page of a ntfy server. | None |
username |
Optional[str] |
A username to use when sending a message | None |
password |
Optional[str] |
A password to use when sending a message | None |
ntfy_headers
If advanced functionality is desired, custom headers can be passed to each request made by the NtfyHandler with this parameter. See this page for an up-to-date list of the headers that ntfy uses.
The Authorization header may be set here. If it is, access_token, username, and password will not override the manually set value.
The X-Title and X-Priority headers will be overridden for each log record, so setting them here would be ineffectual.
log_level_priority_map
By default, log levels are mapped to their corresponding priorities in ntfy (defined here). However, a custom mapping from log level -> ntfy priority can be defined with the log_level_priority_map parameter when constructing a NtfyHandler.
The default map is as follows:
{
logging.DEBUG: 1,
logging.INFO: 2,
logging.WARNING: 3,
logging.ERROR: 4,
logging.FATAL: 5,
}
Levels for log records are truncated to the nearest 10, to normalize them into the above options. With the default configuration, a log record with a level outside of range(9, 60) will be sent with ntfy's default priority (3).
To customize this option, provide a dict with keys set to log levels truncated to the nearest 10 and values set to the ntfy priorities to be used for those levels.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ntfy_handler-1.0.3.tar.gz.
File metadata
- Download URL: ntfy_handler-1.0.3.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b5925c07d4052652529d266f4ec199c265e8b60dd4f41e505a252760428b0c3
|
|
| MD5 |
d9cd0c529a5d76475834e08e0ba8fa0e
|
|
| BLAKE2b-256 |
01b01992735e9d576a125a59832fbf50366c692058f3eaae6a940758b68ed84b
|
File details
Details for the file ntfy_handler-1.0.3-py3-none-any.whl.
File metadata
- Download URL: ntfy_handler-1.0.3-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b5c730855545284c98b0adc0d096a3edf5b7a8a5427a34f5ae62ebd39ffb892
|
|
| MD5 |
e76c7467c894d0aa81d14c03320a9650
|
|
| BLAKE2b-256 |
8403d192e0e40c86f77eb37faea7575fa901de78ea0504a2617e686e73ca77f2
|