-
Notifications
You must be signed in to change notification settings - Fork 0
init #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
init #1
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f0a7859
init
grigoriev-semyon 9591d62
fix
grigoriev-semyon 6561458
fix
grigoriev-semyon cca3b4b
fix
grigoriev-semyon 395e05c
fix
grigoriev-semyon 2539087
fix
grigoriev-semyon dfd599d
fix
grigoriev-semyon d1ee03e
fix
grigoriev-semyon 341e1ee
fix
grigoriev-semyon 4efc092
fix
grigoriev-semyon b7dbfcc
fix
grigoriev-semyon 222c10a
fix
grigoriev-semyon 0170889
readme
grigoriev-semyon 86572d4
readme
grigoriev-semyon ec22647
review
grigoriev-semyon 2afdc0c
review
grigoriev-semyon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,25 @@ | ||
| name: Publish Python 🐍 distributions 📦 | ||
|
|
||
| on: | ||
| release: | ||
| types: [published] | ||
|
|
||
| jobs: | ||
| build-and-publish: | ||
| name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@master | ||
| - name: Set up Python 3.11 | ||
| uses: actions/setup-python@v3 | ||
| with: | ||
| python-version: "3.11" | ||
| - name: Install dependencies | ||
| run: | | ||
| python -m ensurepip | ||
| pip install build --user | ||
| python -m build --wheel --sdist --outdir dist/ | ||
| - name: Publish a Python distribution to PyPI | ||
| uses: pypa/gh-action-pypi-publish@release/v1 | ||
| with: | ||
| password: ${{ secrets.PYPI_API_TOKEN }} |
This file contains hidden or 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,12 @@ | ||
| # logging-lib | ||
| Библиотека для логирования сервисов Твой ФФ! | ||
|
|
||
| ## Как подключить | ||
| 1. В requirements.txt добавьте logging-profcomff | ||
| 2. Скопируйте из /gunicorn_logging_examples обе конфигурации | ||
| 3. Вставьте их в корень проекта | ||
| 4. Добаввьте в Dockerfile ARG CONF_FILE | ||
| 5. В Dockerfile добавьте GUNICORN_CMD_ARGS в качестве env переменной | ||
| 6. Пропишите туда "--log-config $CONF_FILE" | ||
| 7. В Actions в запуск добавьте(прод) --build-args: docker build --build-arg CONF_FILE=logging_prod.conf | ||
| 8. В Actions в запуск добавьте(тест) --build-args: docker build --build-arg CONF_FILE=logging_test.conf | ||
This file contains hidden or 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,35 @@ | ||
| [loggers] | ||
| keys=root,gunicorn.error,gunicorn.access | ||
|
|
||
| [handlers] | ||
| keys=all | ||
|
|
||
| [formatters] | ||
| keys=json | ||
|
|
||
| [logger_root] | ||
| level=INFO | ||
| handlers=all | ||
|
|
||
| [logger_gunicorn.error] | ||
| level=INFO | ||
| handlers=all | ||
| propagate=0 | ||
| qualname=gunicorn.error | ||
| formatter=json | ||
|
|
||
| [logger_gunicorn.access] | ||
| level=INFO | ||
| handlers=all | ||
| propagate=0 | ||
| qualname=gunicorn.access | ||
| formatter=json | ||
|
|
||
| [handler_all] | ||
| class=StreamHandler | ||
| formatter=json | ||
| level=INFO | ||
| args=(sys.stdout,) | ||
|
|
||
| [formatter_json] | ||
| class=logger.formatter.JSONLogFormatter |
This file contains hidden or 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,35 @@ | ||
| [loggers] | ||
| keys=root,gunicorn.error,gunicorn.access | ||
|
|
||
| [handlers] | ||
| keys=all | ||
|
|
||
| [formatters] | ||
| keys=json | ||
|
|
||
| [logger_root] | ||
| level=DEBUG | ||
| handlers=all | ||
|
|
||
| [logger_gunicorn.error] | ||
| level=DEBUG | ||
| handlers=all | ||
| propagate=0 | ||
| qualname=gunicorn.error | ||
| formatter=json | ||
|
|
||
| [logger_gunicorn.access] | ||
| level=DEBUG | ||
| handlers=all | ||
| propagate=0 | ||
| qualname=gunicorn.access | ||
| formatter=json | ||
|
|
||
| [handler_all] | ||
| class=StreamHandler | ||
| formatter=json | ||
| level=DEBUG | ||
| args=(sys.stdout,) | ||
|
|
||
| [formatter_json] | ||
| class=logger.formatter.JSONLogFormatter |
Empty file.
This file contains hidden or 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,67 @@ | ||
| import datetime | ||
| import json | ||
| import logging | ||
| import traceback | ||
|
|
||
|
|
||
| class JSONLogFormatter(logging.Formatter): | ||
| """ | ||
| Кастомизированный класс-форматер для логов в формате json | ||
| """ | ||
|
|
||
| def format(self, record: logging.LogRecord, *args, **kwargs) -> str: | ||
| """ | ||
| Преобразование объект журнала в json | ||
|
|
||
| :param record: объект журнала | ||
| :return: строка журнала в JSON формате | ||
| """ | ||
| log_object: dict = self._format_log_object(record) | ||
| return json.dumps(log_object, ensure_ascii=False) | ||
|
|
||
| @staticmethod | ||
| def _format_log_object(record: logging.LogRecord) -> dict: | ||
| """ | ||
| Перевод записи объекта журнала | ||
| в json формат с необходимым перечнем полей | ||
|
|
||
| :param record: объект журнала | ||
| :return: Словарь с объектами журнала | ||
| """ | ||
| now = ( | ||
| datetime.datetime.fromtimestamp(record.created) | ||
| .astimezone() | ||
| .replace(microsecond=0) | ||
| .isoformat() | ||
| ) | ||
| message = record.getMessage() | ||
| duration_ms = record.duration if hasattr(record, "duration") else record.msecs | ||
| # Инициализация тела журнала | ||
| json_log_fields = dict() | ||
| json_log_fields["thread"] = record.process | ||
| json_log_fields["timestamp"] = now | ||
| json_log_fields["level"] = record.levelno | ||
| json_log_fields["level_name"] = record.levelname | ||
| json_log_fields["message"] = message | ||
| json_log_fields["source"] = record.name | ||
| json_log_fields["duration_ms"] = duration_ms | ||
| json_log_fields["func"] = record.funcName | ||
| json_log_fields["file"] = record.filename | ||
| empty_record = logging.LogRecord( | ||
| str(), int(), str(), int(), object(), exc_info=None, args=(object,) | ||
| ) | ||
| keys = set(dir(record)) - set(dir(empty_record)) | ||
| json_log_fields.update({key: getattr(record, key) for key in keys}) | ||
|
|
||
| if hasattr(record, "props"): | ||
| json_log_fields.props = record.props | ||
|
|
||
| if record.exc_info: | ||
| json_log_fields["exceptions"] = traceback.format_exception(*record.exc_info) | ||
| elif record.exc_text: | ||
| json_log_fields["exceptions"] = record.exc_text | ||
|
|
||
| if hasattr(record, "request_json_fields"): | ||
| json_log_fields.update(record.request_json_fields) | ||
|
|
||
| return json_log_fields |
This file contains hidden or 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,18 @@ | ||
| from setuptools import setup, find_packages | ||
|
|
||
| with open("README.md", "r") as readme_file: | ||
| readme = readme_file.read() | ||
|
|
||
| setup( | ||
| name="logging_profcomff", | ||
| version="2023.03.11", | ||
| author="Semyon Grigoriev", | ||
| long_description=readme, | ||
| long_description_content_type="text/markdown", | ||
| url="https://github.com/profcomff/logging-lib", | ||
| packages=find_packages(), | ||
| install_requires=["setuptools"], | ||
| classifiers=[ | ||
| "Programming Language :: Python :: 3.11", | ||
| ], | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.