Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.1.1
current_version = 2.2.0
commit = False
tag = False

Expand Down
5 changes: 5 additions & 0 deletions .github/actionlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Configuration related to self-hosted runner.
self-hosted-runner:
# Labels of self-hosted runner in array of strings.
labels:
- arc-runner-set
28 changes: 18 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
versiontag:
runs-on: ubuntu-latest
runs-on: arc-runner-set
if: github.ref != 'refs/heads/main'
steps:
- uses: actions/checkout@v5
Expand All @@ -19,7 +19,7 @@ jobs:
diff /tmp/main_version.txt /tmp/version.txt && exit 1 || exit 0

lint:
runs-on: ubuntu-24.04
runs-on: arc-runner-set
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v5
Expand All @@ -34,10 +34,10 @@ jobs:
run: poetry run docker/pre_commit_init.sh

test:
runs-on: ubuntu-latest
runs-on: arc-runner-set
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@v5
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -53,10 +53,18 @@ jobs:
run: |
poetry run py.test -v

devel_shell:
runs-on: ubuntu-latest
docker_builds:
runs-on: arc-runner-set
steps:
- uses: pvarki/ci@main
with:
dockerfile-target: devel_shell
image-tag: rasenmaeher_api:devel_shell
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: actions/checkout@v5
with:
submodules: recursive
- name: Build test target
run: docker build --target test -t libpvarki:test .
- name: Build production target
run: docker build --target production -t libpvarki:production .
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
tag_release:
runs-on: ubuntu-latest
runs-on: arc-runner-set
permissions:
contents: write
steps:
Expand All @@ -30,7 +30,7 @@ jobs:
tag_exists_error: false

publish:
runs-on: ubuntu-latest
runs-on: arc-runner-set
steps:
- uses: actions/checkout@v5
- name: Set up Python 3.11
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile_alpine
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Tox testsuite for multiple python version #
#############################################
FROM advian/tox-base:alpine-3.19 as tox
ARG PYTHON_VERSIONS="3.11 3.10 3.9"
ARG PYTHON_VERSIONS="3.11 3.10 3.13 3.14"
ARG POETRY_VERSION="2.2.1"
RUN export RESOLVED_VERSIONS=`pyenv_resolve $PYTHON_VERSIONS` \
&& echo RESOLVED_VERSIONS=$RESOLVED_VERSIONS \
Expand Down
1,370 changes: 523 additions & 847 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "libpvarki"
version = "2.1.1"
version = "2.2.0"
description = "Common helpers like standard logging init"
authors = ["Eero af Heurlin <eero.afheurlin@iki.fi>"]
homepage = "https://github.com/pvarki/python-libpvarki/"
Expand Down Expand Up @@ -56,7 +56,7 @@ omit = ["tests/*"]
branch = true

[tool.poetry.dependencies]
python = ">3.9.1,<4.0"
python = ">3.10,<4.0"
ecs-logging = "^2.0"
fastapi = ">0.89,<1.0" # caret behaviour on 0.x is to lock to 0.x.*
pydantic= ">=2.0,<3.0"
Expand Down
2 changes: 1 addition & 1 deletion src/libpvarki/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Common helpers like standard logging init"""

__version__ = "2.1.1" # NOTE Use `bump2version --config-file patch` to bump versions correctly
__version__ = "2.2.0" # NOTE Use `bump2version --config-file patch` to bump versions correctly
44 changes: 44 additions & 0 deletions src/libpvarki/logging/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Logging helpers"""

from typing import Dict, Any, cast
import logging
import logging.config
import copy
import os
import json


from .common import DEFAULT_LOGGING_CONFIG, UTCISOFormatter, DEFAULT_LOG_FORMAT, AddExtrasFilter
from .levels import add_logging_level


def add_trace_and_audit() -> None:
"""Adds TRACE (less important than DEBUG) and AUDIT (more important than critical) levels"""
add_logging_level("TRACE", logging.DEBUG - 5)
add_logging_level("AUDIT", logging.CRITICAL + 5)


def init_logging(level: int = logging.INFO) -> None:
"""Initialize logging, call this if you don't know any better logging arrangements"""
labels_json = os.environ.get("LOG_GLOBAL_LABELS_JSON")
console_formatter = os.environ.get("LOG_CONSOLE_FORMATTER", "ecs")
config = cast(Dict[str, Any], copy.deepcopy(DEFAULT_LOGGING_CONFIG))
# If we have the labels env set, apply filter that sets these labels to all log records
if labels_json:
config["filters"] = {
"global_labels": {
"()": AddExtrasFilter,
"extras": json.loads(labels_json),
},
}
for key in config["handlers"]:
if "filters" not in config["handlers"][key]:
config["handlers"][key]["filters"] = []
config["handlers"][key]["filters"].append("global_labels")
# Set root loglevel to desired
config["root"]["level"] = level
config["handlers"]["console"]["formatter"] = console_formatter
logging.config.dictConfig(config)


__all__ = ["DEFAULT_LOG_FORMAT", "UTCISOFormatter", "DEFAULT_LOGGING_CONFIG", "init_logging", "add_trace_and_audit"]
29 changes: 1 addition & 28 deletions src/libpvarki/logging.py → src/libpvarki/logging/common.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
"""Things common for all handlers"""

from typing import Optional, Mapping, Any, Dict, cast
import os
import json
import logging
from typing import Optional, Mapping, Any
import logging.config
import time
import datetime
import copy


import ecs_logging
Expand Down Expand Up @@ -77,26 +73,3 @@ def filter(self, record: logging.LogRecord) -> bool:
for key in self.add_extras:
setattr(record, key, self.add_extras[key])
return super().filter(record)


def init_logging(level: int = logging.INFO) -> None:
"""Initialize logging, call this if you don't know any better logging arrangements"""
labels_json = os.environ.get("LOG_GLOBAL_LABELS_JSON")
console_formatter = os.environ.get("LOG_CONSOLE_FORMATTER", "ecs")
config = cast(Dict[str, Any], copy.deepcopy(DEFAULT_LOGGING_CONFIG))
# If we have the labels env set, apply filter that sets these labels to all log records
if labels_json:
config["filters"] = {
"global_labels": {
"()": AddExtrasFilter,
"extras": json.loads(labels_json),
},
}
for key in config["handlers"]:
if "filters" not in config["handlers"][key]:
config["handlers"][key]["filters"] = []
config["handlers"][key]["filters"].append("global_labels")
# Set root loglevel to desired
config["root"]["level"] = level
config["handlers"]["console"]["formatter"] = console_formatter
logging.config.dictConfig(config)
Loading
Loading