mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-01-11 13:16:19 +00:00
fix: EOS loguru logging of EOSdash stdout logs (#827)
Some checks failed
Bump Version / Bump Version Workflow (push) Has been cancelled
docker-build / platform-excludes (push) Has been cancelled
docker-build / build (push) Has been cancelled
docker-build / merge (push) Has been cancelled
pre-commit / pre-commit (push) Has been cancelled
Run Pytest on Pull Request / test (push) Has been cancelled
Close stale pull requests/issues / Find Stale issues and PRs (push) Has been cancelled
Some checks failed
Bump Version / Bump Version Workflow (push) Has been cancelled
docker-build / platform-excludes (push) Has been cancelled
docker-build / build (push) Has been cancelled
docker-build / merge (push) Has been cancelled
pre-commit / pre-commit (push) Has been cancelled
Run Pytest on Pull Request / test (push) Has been cancelled
Close stale pull requests/issues / Find Stale issues and PRs (push) Has been cancelled
When patching loguru logging records do not replace structured loguru fields. Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
This commit is contained in:
2
.env
2
.env
@@ -11,7 +11,7 @@ DOCKER_COMPOSE_DATA_DIR=${HOME}/.local/share/net.akkudoktor.eos
|
||||
# -----------------------------------------------------------------------------
|
||||
# Image / build
|
||||
# -----------------------------------------------------------------------------
|
||||
VERSION=0.2.0.dev70048701
|
||||
VERSION=0.2.0.dev81236039
|
||||
PYTHON_VERSION=3.13.9
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
# the root directory (no add-on folder as usual).
|
||||
|
||||
name: "Akkudoktor-EOS"
|
||||
version: "0.2.0.dev70048701"
|
||||
version: "0.2.0.dev81236039"
|
||||
slug: "eos"
|
||||
description: "Akkudoktor-EOS add-on"
|
||||
url: "https://github.com/Akkudoktor-EOS/EOS"
|
||||
|
||||
@@ -136,7 +136,7 @@
|
||||
}
|
||||
},
|
||||
"general": {
|
||||
"version": "0.2.0.dev81043823",
|
||||
"version": "0.2.0.dev81236039",
|
||||
"data_folder_path": null,
|
||||
"data_output_subpath": "output",
|
||||
"latitude": 52.52,
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
| latitude | `EOS_GENERAL__LATITUDE` | `Optional[float]` | `rw` | `52.52` | Latitude in decimal degrees between -90 and 90. North is positive (ISO 19115) (°) |
|
||||
| longitude | `EOS_GENERAL__LONGITUDE` | `Optional[float]` | `rw` | `13.405` | Longitude in decimal degrees within -180 to 180 (°) |
|
||||
| timezone | | `Optional[str]` | `ro` | `N/A` | Computed timezone based on latitude and longitude. |
|
||||
| version | `EOS_GENERAL__VERSION` | `str` | `rw` | `0.2.0.dev81043823` | Configuration file version. Used to check compatibility. |
|
||||
| version | `EOS_GENERAL__VERSION` | `str` | `rw` | `0.2.0.dev81236039` | Configuration file version. Used to check compatibility. |
|
||||
:::
|
||||
<!-- pyml enable line-length -->
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
```json
|
||||
{
|
||||
"general": {
|
||||
"version": "0.2.0.dev81043823",
|
||||
"version": "0.2.0.dev81236039",
|
||||
"data_folder_path": null,
|
||||
"data_output_subpath": "output",
|
||||
"latitude": 52.52,
|
||||
@@ -46,7 +46,7 @@
|
||||
```json
|
||||
{
|
||||
"general": {
|
||||
"version": "0.2.0.dev81043823",
|
||||
"version": "0.2.0.dev81236039",
|
||||
"data_folder_path": null,
|
||||
"data_output_subpath": "output",
|
||||
"latitude": 52.52,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Akkudoktor-EOS
|
||||
|
||||
**Version**: `v0.2.0.dev81043823`
|
||||
**Version**: `v0.2.0.dev81236039`
|
||||
|
||||
<!-- pyml disable line-length -->
|
||||
**Description**: This project provides a comprehensive solution for simulating and optimizing an energy system based on renewable energy sources. With a focus on photovoltaic (PV) systems, battery storage (batteries), load management (consumer requirements), heat pumps, electric vehicles, and consideration of electricity price data, this system enables forecasting and optimization of energy flow and costs over a specified period.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"info": {
|
||||
"title": "Akkudoktor-EOS",
|
||||
"description": "This project provides a comprehensive solution for simulating and optimizing an energy system based on renewable energy sources. With a focus on photovoltaic (PV) systems, battery storage (batteries), load management (consumer requirements), heat pumps, electric vehicles, and consideration of electricity price data, this system enables forecasting and optimization of energy flow and costs over a specified period.",
|
||||
"version": "v0.2.0.dev81043823"
|
||||
"version": "v0.2.0.dev81236039"
|
||||
},
|
||||
"paths": {
|
||||
"/v1/admin/cache/clear": {
|
||||
@@ -2525,7 +2525,7 @@
|
||||
"general": {
|
||||
"$ref": "#/components/schemas/GeneralSettings-Output",
|
||||
"default": {
|
||||
"version": "0.2.0.dev81043823",
|
||||
"version": "0.2.0.dev81236039",
|
||||
"data_output_subpath": "output",
|
||||
"latitude": 52.52,
|
||||
"longitude": 13.405,
|
||||
@@ -4272,7 +4272,7 @@
|
||||
"type": "string",
|
||||
"title": "Version",
|
||||
"description": "Configuration file version. Used to check compatibility.",
|
||||
"default": "0.2.0.dev81043823"
|
||||
"default": "0.2.0.dev81236039"
|
||||
},
|
||||
"data_folder_path": {
|
||||
"anyOf": [
|
||||
@@ -4346,7 +4346,7 @@
|
||||
"type": "string",
|
||||
"title": "Version",
|
||||
"description": "Configuration file version. Used to check compatibility.",
|
||||
"default": "0.2.0.dev81043823"
|
||||
"default": "0.2.0.dev81236039"
|
||||
},
|
||||
"data_folder_path": {
|
||||
"anyOf": [
|
||||
|
||||
@@ -455,7 +455,7 @@ class HomeAssistantAdapter(AdapterProvider):
|
||||
measurement_key = entity_id
|
||||
if measurement_key not in measurement_keys:
|
||||
measurement_keys.append(measurement_key)
|
||||
self.comfig.measurement.load_emr_keys = measurement_keys
|
||||
self.config.measurement.load_emr_keys = measurement_keys
|
||||
try:
|
||||
state = self.get_entity_state(entity_id)
|
||||
logger.debug(f"Entity {entity_id}: {state}")
|
||||
|
||||
@@ -3,6 +3,7 @@ import os
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any, MutableMapping
|
||||
|
||||
from loguru import logger
|
||||
|
||||
@@ -36,6 +37,58 @@ LOG_PATTERN = re.compile(
|
||||
)
|
||||
|
||||
|
||||
def patch_loguru_record(
|
||||
record: MutableMapping[str, Any],
|
||||
*,
|
||||
file_name: str,
|
||||
file_path: str,
|
||||
line_no: int,
|
||||
function: str,
|
||||
logger_name: str = "EOSdash",
|
||||
) -> None:
|
||||
"""Patch a Loguru log record with subprocess-origin metadata.
|
||||
|
||||
This helper mutates an existing Loguru record in-place to update selected
|
||||
metadata fields (file, line, function, and logger name) while preserving
|
||||
Loguru's internal record structure. It must be used with ``logger.patch()``
|
||||
and **must not** replace structured fields (such as ``record["file"]``)
|
||||
with plain dictionaries.
|
||||
|
||||
The function is intended for forwarding log messages originating from
|
||||
subprocess stdout/stderr streams into Loguru while retaining meaningful
|
||||
source information (e.g., file path and line number).
|
||||
|
||||
Args:
|
||||
record:
|
||||
The Loguru record dictionary provided to ``logger.patch()``.
|
||||
file_name:
|
||||
The source file name to assign (e.g. ``"main.py"``).
|
||||
file_path:
|
||||
The full source file path to assign
|
||||
(e.g. ``"/app/server/main.py"``).
|
||||
line_no:
|
||||
The source line number associated with the log entry.
|
||||
function:
|
||||
The function name associated with the log entry.
|
||||
logger_name:
|
||||
The logical logger name to assign to the record. Defaults to
|
||||
``"EOSdash"``.
|
||||
|
||||
Notes:
|
||||
- This function mutates the record in-place and returns ``None``.
|
||||
- Only attributes of existing structured objects are modified;
|
||||
no structured Loguru fields are replaced.
|
||||
- Replacing ``record["file"]`` or similar structured fields with a
|
||||
dictionary will cause Loguru sinks to fail.
|
||||
|
||||
"""
|
||||
record["file"].name = file_name
|
||||
record["file"].path = file_path
|
||||
record["line"] = line_no
|
||||
record["function"] = function
|
||||
record["name"] = logger_name
|
||||
|
||||
|
||||
async def forward_stream(stream: asyncio.StreamReader, prefix: str = "") -> None:
|
||||
"""Continuously read log lines from a subprocess and re-log them via Loguru.
|
||||
|
||||
@@ -94,16 +147,12 @@ async def forward_stream(stream: asyncio.StreamReader, prefix: str = "") -> None
|
||||
|
||||
# ---- Patch logger with realistic metadata ----
|
||||
patched = logger.patch(
|
||||
lambda r: r.update(
|
||||
{
|
||||
"file": {
|
||||
"name": file_name,
|
||||
"path": file_path,
|
||||
},
|
||||
"line": line_no,
|
||||
"function": func_name,
|
||||
"name": "EOSdash",
|
||||
}
|
||||
lambda r: patch_loguru_record(
|
||||
r,
|
||||
file_name=file_name,
|
||||
file_path=file_path,
|
||||
line_no=line_no,
|
||||
function=func_name,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -115,16 +164,13 @@ async def forward_stream(stream: asyncio.StreamReader, prefix: str = "") -> None
|
||||
file_path = f"/subprocess/{file_name}"
|
||||
|
||||
logger.patch(
|
||||
lambda r: r.update(
|
||||
{
|
||||
"file": {
|
||||
"name": file_name,
|
||||
"path": file_path,
|
||||
},
|
||||
"line": 1,
|
||||
"function": "<subprocess>",
|
||||
"name": "EOSdash",
|
||||
}
|
||||
lambda r: patch_loguru_record(
|
||||
r,
|
||||
file_name=file_name,
|
||||
file_path=file_path,
|
||||
line_no=1,
|
||||
function="<subprocess>",
|
||||
logger_name="EOSdash",
|
||||
)
|
||||
).info(f"{prefix}{raw}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user