Coverage for oc_validator / __init__.py: 100%
11 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-30 15:46 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-30 15:46 +0000
1# ISC License
2#
3# Copyright (c) 2023-2026, Elia Rizzetto, Silvio Peroni
4#
5# Permission to use, copy, modify, and/or distribute this software for any
6# purpose with or without fee is hereby granted, provided that the above
7# copyright notice and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
11# FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15# PERFORMANCE OF THIS SOFTWARE.
17import logging
18from typing import Optional
20logger = logging.getLogger('oc_validator')
23def configure_logging(verbose: bool = False, log_file: Optional[str] = None) -> None:
24 """
25 Configure logging for the oc_validator package.
27 :param verbose: If True, set level to INFO; otherwise WARNING.
28 :type verbose: bool
29 :param log_file: If provided, log to this file path instead of the terminal.
30 :type log_file: Optional[str]
31 :rtype: None
32 """
33 level = logging.INFO if verbose else logging.WARNING
34 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
35 handler = logging.FileHandler(log_file) if log_file else logging.StreamHandler()
36 handler.setFormatter(formatter)
37 logger.handlers.clear()
38 logger.addHandler(handler)
39 logger.setLevel(level)