Coverage for src/python/ensembl/vep/config/sections/common/logging.py: 100%
21 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-18 14:41 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-18 14:41 +0000
1# See the NOTICE file distributed with this work for additional information
2# regarding copyright ownership.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Logging options, read by every runner."""
16from __future__ import annotations
18from pathlib import Path
19from typing import ClassVar
21from attrs import define, field
23from ensembl.vep.config.option_spec import option
24from ensembl.vep.config.sections.base import ConfigSection
26__all__ = ["LoggingConfig"]
28LOG_LEVELS = ("debug", "info", "warning", "error", "critical")
31@define(frozen=True, kw_only=True, auto_attribs=True)
32class LoggingConfig(ConfigSection):
33 """How much the run says, and where it says it.
35 Attributes:
36 log_level (str): Root level for the ``ensembl.vep`` logger hierarchy.
37 log_file (Path | None): File to append log records to, or None for stream output only.
38 Perl VEP calls this ``--warning_file``, which is accepted as a synonym.
39 verbose (bool): Shorthand for ``log_level="debug"``. Also what turns derivation tracing on,
40 since ensembl.vep.trace keys off the strategy logger being at DEBUG.
41 quiet (bool): Shorthand for ``log_level="error"``.
42 """
44 section_name: ClassVar[str] = "logging"
46 log_level: str = field(
47 default="info", metadata=option("logging level", synonyms=("level",), choices=LOG_LEVELS)
48 )
49 log_file: Path | None = field(
50 default=None,
51 metadata=option("write log records to this file", synonyms=("warning_file",)),
52 )
53 verbose: bool = field(default=False, metadata=option("log at debug level", short="v"))
54 quiet: bool = field(default=False, metadata=option("log errors only", short="q"))
56 def effective_level(self) -> str:
57 """Returns the level to apply once ``verbose``/``quiet`` are taken into account.
59 Returns:
60 str: One of ``LOG_LEVELS``. ``quiet`` wins over ``verbose`` when both are set, so the
61 quieter of two conflicting requests is honoured.
62 """
63 if self.quiet:
64 return "error"
65 if self.verbose:
66 return "debug"
67 return self.log_level