-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Iglesys347/1-prepare-for-pypi-publish
1 prepare for pypi publish
- Loading branch information
Showing
7 changed files
with
211 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Publish package to Pypi | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
permissions: | ||
contents: read # to fetch code (actions/checkout) | ||
|
||
jobs: | ||
build_and_package: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: install python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.9 | ||
- name: Install dev tools | ||
run: | | ||
pip install -r dev_requirements.txt | ||
pip install twine wheel | ||
- name: Build package | ||
run: | | ||
python setup.py build | ||
python setup.py sdist bdist_wheel | ||
- name: Publish to Test Pypi | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
password: ${{ secrets.TEST_PYPI_API_TOKEN }} | ||
repository_url: https://test.pypi.org/legacy/ | ||
# NOT PUBLISHING TO THE REAL Pypi FOR THE MOMENT | ||
# - name: Publish to Pypi | ||
# uses: pypa/gh-action-pypi-publish@release/v1 | ||
# with: | ||
# password: ${{ secrets.PYPI_API_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,120 @@ | ||
# redis-log-handler | ||
|
||
Log handler to forward logs to Redis | ||
|
||
<center> | ||
|
||
| [Installation](#installation) | [Usage](#usage) | | ||
| :---------------------------: | :-------------: | | ||
|
||
</center> | ||
|
||
## Installation | ||
|
||
Installation with `pip`: | ||
|
||
```bash | ||
pip install redis-logs | ||
``` | ||
|
||
## Usage | ||
|
||
### Basic example | ||
|
||
Setup log forwarding to a redis stream: | ||
|
||
```python | ||
from rlh import RedisStreamLogHandler | ||
|
||
# define your logger | ||
logger = logging.getLogger('my_app') | ||
|
||
# define the Redis log handler | ||
handler = RedisStreamLogHandler() | ||
# add the handler to the logger | ||
logger.addHandler(handler) | ||
``` | ||
|
||
After that, all the logs emitted with the logger will be forwarded to a [Redis Stream](https://redis.io/docs/data-types/streams/); by default the logs are forwarded to a Redis instance running at `localhost:6379` in a stream named `logs`. | ||
|
||
### Use a different stream name | ||
|
||
```python | ||
from rlh import RedisStreamLogHandler | ||
|
||
# define your logger | ||
logger = logging.getLogger('my_app') | ||
|
||
# define the Redis log handler | ||
handler = RedisStreamLogHandler(stream_name="custom_stream_name") | ||
# add the handler to the logger | ||
logger.addHandler(handler) | ||
``` | ||
|
||
### Specify a custom Redis client | ||
|
||
To use a custom Redis client, you can either define your own client with `redis.Redis` and then pass it to the handler: | ||
|
||
```python | ||
from redis import Redis | ||
from rlh import RedisStreamLogHandler | ||
|
||
# define a custom Redis client | ||
client = Redis(host="redis", port=6380, db=1) | ||
|
||
# define your logger | ||
logger = logging.getLogger('my_app') | ||
|
||
# define the Redis log handler with custom Redis client | ||
handler = RedisStreamLogHandler(redis_client=client) | ||
# add the handler to the logger | ||
logger.addHandler(handler) | ||
``` | ||
|
||
Or dirrectly call the handler constructor with your custom Redis settings: | ||
|
||
```python | ||
from rlh import RedisStreamLogHandler | ||
|
||
# define your logger | ||
logger = logging.getLogger('my_app') | ||
|
||
# define the Redis log handler with custom Redis client | ||
handler = RedisStreamLogHandler(host="redis", port=6380, db=1) | ||
# add the handler to the logger | ||
logger.addHandler(handler) | ||
``` | ||
|
||
### Specify custom log fields to save | ||
|
||
By default the handler only saves the logs fieds `msg`, `levelname` and `created`. You can however change this default behaviour by setting your own desired fields (see the full list of fields in [logging documentation](https://docs.python.org/3/library/logging.html#logrecord-attributes)): | ||
|
||
```python | ||
from rlh import RedisStreamLogHandler | ||
|
||
# define your logger | ||
logger = logging.getLogger('my_app') | ||
|
||
# define the Redis log handler with custom fields | ||
handler = RedisStreamLogHandler(fields=["msg", "name", "module", "levelno"]) | ||
# add the handler to the logger | ||
logger.addHandler(handler) | ||
``` | ||
|
||
### Save `LogRecord` as pickle format | ||
|
||
Logs can also be saved in DB as [pickle format](https://docs.python.org/3/library/pickle.html): | ||
|
||
```python | ||
from rlh import RedisStreamLogHandler | ||
|
||
# define your logger | ||
logger = logging.getLogger('my_app') | ||
|
||
# define the Redis log handler with custom fields | ||
handler = RedisStreamLogHandler(as_pkl=True) | ||
# add the handler to the logger | ||
logger.addHandler(handler) | ||
``` | ||
|
||
This can be useful if you need to re-use the logs with another python program. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
async-timeout==4.0.2 | ||
redis==4.4.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from rlh.handlers import ( | ||
RedisLogHandler, | ||
RedisStreamLogHandler, | ||
) | ||
|
||
__all__ = [ | ||
"RedisLogHandler", | ||
"RedisStreamLogHandler", | ||
] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python | ||
from setuptools import find_packages, setup | ||
|
||
setup( | ||
name="redis-logs", | ||
description="Python log handler to forward logs to Redis database", | ||
long_description=open("README.md").read().strip(), | ||
long_description_content_type="text/markdown", | ||
keywords=["Redis", "logging"], | ||
license="MIT", | ||
version="0.0.1", | ||
packages=find_packages( | ||
include=[ | ||
"rlh", | ||
"rlh.handlers", | ||
] | ||
), | ||
url="https://github.com/Iglesys347/redis-log-handler", | ||
project_urls={ | ||
# "Documentation": "TODO:add link to readthedoc", | ||
"Changes": "https://github.com/Iglesys347/redis-log-handler/releases", | ||
"Code": "https://github.com/Iglesys347/redis-log-handler", | ||
"Issue tracker": "https://github.com/Iglesys347/redis-log-handler/issues", | ||
}, | ||
author="Iglesys347", | ||
author_email="g.imbert34@gmail.com", | ||
python_requires=">=3.9", | ||
install_requires=[ | ||
"redis", | ||
], | ||
classifiers=[ | ||
"Development Status :: 2 - Pre-Alpha", | ||
"Environment :: Console", | ||
"Intended Audience :: Developers", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3 :: Only", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
], | ||
extras_require={}, | ||
) |