Logging - vcspull.log¶
Log utilities for formatting CLI output in vcspull.
This module containers special formatters for processing the additional context
information from libvcs.base.RepoLoggingAdapter.
Colorized formatters for generic logging inside the application is also provided.
-
vcspull.log.get_cli_logger_names(include_self=True)¶
Return logger names under
vcspull.cli.
-
vcspull.log._libvcs_stream_level(verbosity)¶
Return the libvcs StreamHandler level for a given
-vcount.Reporter expectation: at the default verbosity, libvcs’s chatty
log.info("Updating to '%s'.")andlog.debug("git_tag: ...")crumb lines should NOT print on the terminal – only WARNING+ does.-vlifts that to INFO;-vvto DEBUG. The debug log file (setup_file_logger) is always DEBUG regardless of this knob.
-
vcspull.log.setup_logger(log=None, level='INFO', verbosity=0)¶
Configure the vcspull logging hierarchy once and reuse it everywhere.
The
levelargument governs the vcspull logger and its CLI submodules; existing callers and--log-levelusers see no change.The
verbosityargument (-vcount from the sync subcommand) drives the libvcs StreamHandler level via_libvcs_stream_level(). Setting it as a per-handler filter – not a logger-level filter – is deliberate:setup_file_loggerlater raises both loggers to DEBUG so the debug file captures the full trace, and without per-handler levels on the StreamHandlers that bump would also open the terminal floodgate. Seetests/test_log.py::test_setup_file_logger_does_not_open_stream_floodgatefor the regression guard.
-
class vcspull.log.DebugLogFormatter¶
Bases:
LogFormatterProvides greater technical details than standard log Formatter.
-
class vcspull.log.RepoLogFormatter¶
Bases:
LogFormatterLog message for VCS repository.
-
class vcspull.log.SimpleLogFormatter¶
Bases:
FormatterSimple formatter that outputs only the message, like print().
-
vcspull.log._DEBUG_FILE_FORMAT = '%(asctime)s.%(msecs)03d [%(levelname)s] %(name)s %(module)s:%(lineno)d -- %(message)s'¶
Format string for the debug log file. Verbose enough to trace a hang: level, timestamp (to millisecond), logger, module:line, and the message.
-
vcspull.log.default_debug_log_path()¶
Return the path where vcspull writes its per-invocation debug log.
Mirrors the
npm/pnpmconvention of dropping a timestamped log file in the system temp directory on every run. The file is always created but its path is only surfaced to the user when something went wrong (failure or timeout), so clean runs stay quiet.Logs land under a
vcspull/subdirectory of the system tempdir (e.g./tmp/vcspull/debug-<ts>-<pid>.log) so the dir name in/tmp/is self-describing instead of relying on avcspull-file prefix that gets lost in a busy tempdir. Under pytest (PYTEST_CURRENT_TESTis set) the subdirectory isvcspull-test/instead – an automatic safety net so tests that incidentally invoke this helper without redirectingTMPDIRcan’t pollute the production log dir.Examples
>>> path = default_debug_log_path() >>> path.name.startswith("debug-") True >>> path.suffix '.log' >>> path.parent.name in {"vcspull", "vcspull-test"} True >>> path.parent.parent == pathlib.Path(tempfile.gettempdir()) True
- Return type:
-
vcspull.log.setup_file_logger(path, *, level=10)¶
Attach a file handler to the
vcspullandlibvcsloggers.Unlike
setup_logger(), this handler is not tied to stdout – it captures the full debug trace so a post-mortem (npm/pnpm/yarn style) has enough context to diagnose a timeout even when the CLI output was aggressively summarised.- Parameters:
path (pathlib.Path) – Destination file. Parent directories are created as needed. An existing file is appended to so a single session that sets up logging multiple times does not clobber earlier context.
level (int) – Threshold for the file handler. Defaults to
logging.DEBUGbecause the file is consulted only when diagnosing a failure.
- Return type:
-
vcspull.log.teardown_file_logger(handler)¶
Flush and detach
handlerfrom the vcspull/libvcs loggers.- Parameters:
handler (FileHandler)
- Return type: