add verbose logging level

This commit is contained in:
Maximilian Keßler 2022-02-18 11:18:28 +01:00
parent d8469f58e3
commit 4c8d144e32
3 changed files with 40 additions and 7 deletions

View file

@ -263,7 +263,7 @@ class PyTeXBuilder:
new_config: List[Tuple[RelativePath, FormattingConfig]] = \ new_config: List[Tuple[RelativePath, FormattingConfig]] = \
source_file.format(self._tmp_dir / source_file.file_hash) source_file.format(self._tmp_dir / source_file.file_hash)
for filename in source_file.output_files: for filename in source_file.output_files:
logger.info(f"[Built] {filename}") logger.verbose(f"[Built] {filename}")
for output_file in source_file.output_files: for output_file in source_file.output_files:
# TODO: handle this new config file # TODO: handle this new config file
# TODO: handle git stuff / meta info stuff # TODO: handle git stuff / meta info stuff
@ -298,16 +298,16 @@ class PyTeXBuilder:
def _build(self) -> bool: def _build(self) -> bool:
logger.info("Starting build") logger.info("Starting build")
self._load_pytex_files() # 8ms self._load_pytex_files() # 8ms
logger.info(f"Found {len(self._pytex_files)} source files") logger.verbose(f"Found {len(self._pytex_files)} source files")
self._init_output_files() # 1ms self._init_output_files() # 1ms
logger.info(f"Found {len(self._output_files)} potential output files to build.") logger.verbose(f"Found {len(self._output_files)} potential output files to build.")
self._compute_files_to_build() # 1ms self._compute_files_to_build() # 1ms
if len(self._files_to_build) == 0: if len(self._files_to_build) == 0:
logger.info(f"Everything up to date, nothing to build!") logger.info(f"Everything up to date, nothing to build!")
return True return True
logger.info(f"Needing to build {len(self._files_to_build)} many source files.") logger.verbose(f"Needing to build {len(self._files_to_build)} many source files.")
self._check_output_directory_integrity() # 1ms self._check_output_directory_integrity() # 1ms
logger.info(f"Starting build") logger.verbose(f"Starting build")
try: try:
self._build_files() # 53 ms self._build_files() # 53 ms
except PyTeXError as e: except PyTeXError as e:

View file

@ -0,0 +1,30 @@
# This file is adapted from the haggis library, available at
# https://github.com/madphysicist/haggis
#
# The haggis library is licensed under the
# GNU Affero General Public License v3.0 (AGPLv3)
#
# The code has been adapted since only a small code piece is needed
# to avoid introducing an additional install-dependency when
# using PyTeX
#
# You should have received a copy of the AGPLv3 license along with the
# PyTeX distribution. If not, refer to
# https://www.gnu.org/licenses/agpl-3.0.en.html
#
import logging
def add_logging_level(level_name: str, level_num: int):
def log_for_level(self, message, *args, **kwargs):
if self.isEnabledFor(level_num):
self._log(level_num, message, args, **kwargs)
def log_to_root(message, *args, **kwargs):
logging.log(level_num, message, *args, **kwargs)
logging.addLevelName(level_num, level_name.upper())
setattr(logging, level_name.upper(), level_num)
setattr(logging.getLoggerClass(), level_name.lower(), log_for_level)
setattr(logging, level_name.lower(), log_to_root)

View file

@ -1,12 +1,15 @@
import logging import logging
from .add_logging_level import add_logging_level
add_logging_level('VERBOSE', 15)
formatter = logging.Formatter("[{name}] [{levelname}] {message}", style="{") formatter = logging.Formatter("[{name}] [{levelname}] {message}", style="{")
console_logger = logging.StreamHandler() console_logger = logging.StreamHandler()
console_logger.setLevel(logging.INFO) console_logger.setLevel(logging.VERBOSE)
console_logger.setFormatter(formatter) console_logger.setFormatter(formatter)
logger: logging.Logger = logging.getLogger('PyTeX') logger: logging.Logger = logging.getLogger('PyTeX')
logger.setLevel(logging.INFO) logger.setLevel(logging.VERBOSE)
logger.addHandler(console_logger) logger.addHandler(console_logger)