Skip to content
Open
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: 2 additions & 0 deletions config/config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ tutorial: false
# docs in https://pypsa-eur.readthedocs.io/en/latest/configuration.html#logging
logging:
level: INFO
console_level: WARNING
file_level:
format: "%(levelname)s:%(name)s:%(message)s"

# docs in https://pypsa-eur.readthedocs.io/en/latest/configuration.html#remote
Expand Down
66 changes: 64 additions & 2 deletions config/schema.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2848,7 +2848,7 @@
"properties": {
"level": {
"default": "INFO",
"description": "Restrict console outputs to all infos, warning or errors only",
"description": "Root log level. Messages below this level are discarded before reaching any handler.",
"enum": [
"DEBUG",
"INFO",
Expand All @@ -2858,6 +2858,37 @@
],
"type": "string"
},
"console_level": {
"default": "WARNING",
"description": "Minimum level emitted to the console (stderr). Defaults to ``WARNING`` so parallel rule output stays readable; the full log is kept in the rule's log file.",
"enum": [
"DEBUG",
"INFO",
"WARNING",
"ERROR",
"CRITICAL"
],
"type": "string"
},
"file_level": {
"anyOf": [
{
"enum": [
"DEBUG",
"INFO",
"WARNING",
"ERROR",
"CRITICAL"
],
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Minimum level written to the rule log file. Defaults to ``level`` when unset."
},
"format": {
"default": "%(levelname)s:%(name)s:%(message)s",
"description": "Custom format for log messages. See `LogRecord <https://docs.python.org/3/library/logging.html#logging.LogRecord>`_ attributes.",
Expand Down Expand Up @@ -8182,7 +8213,7 @@
"properties": {
"level": {
"default": "INFO",
"description": "Restrict console outputs to all infos, warning or errors only",
"description": "Root log level. Messages below this level are discarded before reaching any handler.",
"enum": [
"DEBUG",
"INFO",
Expand All @@ -8192,6 +8223,37 @@
],
"type": "string"
},
"console_level": {
"default": "WARNING",
"description": "Minimum level emitted to the console (stderr). Defaults to ``WARNING`` so parallel rule output stays readable; the full log is kept in the rule's log file.",
"enum": [
"DEBUG",
"INFO",
"WARNING",
"ERROR",
"CRITICAL"
],
"type": "string"
},
"file_level": {
"anyOf": [
{
"enum": [
"DEBUG",
"INFO",
"WARNING",
"ERROR",
"CRITICAL"
],
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Minimum level written to the rule log file. Defaults to ``level`` when unset."
},
"format": {
"default": "%(levelname)s:%(name)s:%(message)s",
"description": "Custom format for log messages. See `LogRecord <https://docs.python.org/3/library/logging.html#logging.LogRecord>`_ attributes.",
Expand Down
2 changes: 2 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Release Notes

* perf: Optimize dask settings for computing weather-dependent profiles (https://github.com/PyPSA/pypsa-eur/pull/2137).

* Split logging levels between console and log file: the console now defaults to ``WARNING`` while the rule log file still captures ``INFO``. Configure via ``logging.console_level`` and ``logging.file_level`` (https://github.com/PyPSA/pypsa-eur/pull/2144).

PyPSA-Eur v2026.02.0 (18th February 2026)
=========================================

Expand Down
17 changes: 7 additions & 10 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ def configure_logging(snakemake, skip_handlers=False):

kwargs = snakemake.config.get("logging", dict()).copy()
kwargs.setdefault("level", "INFO")
console_level = kwargs.pop("console_level", "WARNING")
file_level = kwargs.pop("file_level", None) or kwargs["level"]

if skip_handlers is False:
fallback_path = Path(__file__).parent.joinpath(
Expand All @@ -270,16 +272,11 @@ def configure_logging(snakemake, skip_handlers=False):
logfile = snakemake.log.get(
"python", snakemake.log[0] if snakemake.log else fallback_path
)
kwargs.update(
{
"handlers": [
# Prefer the 'python' log, otherwise take the first log for each
# Snakemake rule
logging.FileHandler(logfile),
logging.StreamHandler(),
]
}
)
file_handler = logging.FileHandler(logfile)
file_handler.setLevel(file_level)
stream_handler = logging.StreamHandler()
stream_handler.setLevel(console_level)
kwargs["handlers"] = [file_handler, stream_handler]
logging.basicConfig(**kwargs)

# Setup a function to handle uncaught exceptions and include them with their stacktrace into logfiles
Expand Down
10 changes: 9 additions & 1 deletion scripts/lib/validation/config/_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ class LoggingConfig(ConfigModel):

level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = Field(
"INFO",
description="Restrict console outputs to all infos, warning or errors only",
description="Root log level. Messages below this level are discarded before reaching any handler.",
)
console_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = Field(
"WARNING",
description="Minimum level emitted to the console (stderr). Defaults to ``WARNING`` so parallel rule output stays readable; the full log is kept in the rule's log file.",
)
file_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] | None = Field(
None,
description="Minimum level written to the rule log file. Defaults to ``level`` when unset.",
)
format: str = Field(
"%(levelname)s:%(name)s:%(message)s",
Expand Down
Loading