add verbose logging level
This commit is contained in:
parent
d8469f58e3
commit
4c8d144e32
3 changed files with 40 additions and 7 deletions
|
@ -263,7 +263,7 @@ class PyTeXBuilder:
|
|||
new_config: List[Tuple[RelativePath, FormattingConfig]] = \
|
||||
source_file.format(self._tmp_dir / source_file.file_hash)
|
||||
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:
|
||||
# TODO: handle this new config file
|
||||
# TODO: handle git stuff / meta info stuff
|
||||
|
@ -298,16 +298,16 @@ class PyTeXBuilder:
|
|||
def _build(self) -> bool:
|
||||
logger.info("Starting build")
|
||||
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
|
||||
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
|
||||
if len(self._files_to_build) == 0:
|
||||
logger.info(f"Everything up to date, nothing to build!")
|
||||
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
|
||||
logger.info(f"Starting build")
|
||||
logger.verbose(f"Starting build")
|
||||
try:
|
||||
self._build_files() # 53 ms
|
||||
except PyTeXError as e:
|
||||
|
|
30
PyTeX/logger/add_logging_level.py
Normal file
30
PyTeX/logger/add_logging_level.py
Normal 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)
|
|
@ -1,12 +1,15 @@
|
|||
import logging
|
||||
from .add_logging_level import add_logging_level
|
||||
|
||||
add_logging_level('VERBOSE', 15)
|
||||
|
||||
formatter = logging.Formatter("[{name}] [{levelname}] {message}", style="{")
|
||||
|
||||
console_logger = logging.StreamHandler()
|
||||
console_logger.setLevel(logging.INFO)
|
||||
console_logger.setLevel(logging.VERBOSE)
|
||||
console_logger.setFormatter(formatter)
|
||||
|
||||
logger: logging.Logger = logging.getLogger('PyTeX')
|
||||
|
||||
logger.setLevel(logging.INFO)
|
||||
logger.setLevel(logging.VERBOSE)
|
||||
logger.addHandler(console_logger)
|
||||
|
|
Loading…
Reference in a new issue