ahvn.utils.basic.log_utils module¶
- ahvn.utils.basic.log_utils.get_logger(name, level=None, fmt=None, datefmt=None, style='%', *, validate=True, colors=None)[源代码]¶
Get a logger with a custom colored formatter.
- ahvn.utils.basic.log_utils.set_log_level(level, loggers=None)[源代码]¶
Set the log level globally for ahvn and optionally other loggers.
- 参数:
- 返回类型:
示例
>>> set_log_level("WARNING") # Suppress INFO/DEBUG messages >>> set_log_level(logging.DEBUG, ["ahvn", "myapp"]) # Enable debug for specific loggers
- ahvn.utils.basic.log_utils.redirect_logs(filepath, loggers=None, level=None, fmt=None)[源代码]¶
Redirect ahvn logging output to a file.
- 参数:
- 返回类型:
示例
>>> redirect_logs("/tmp/ahvn.log") >>> redirect_logs("/tmp/debug.log", level="DEBUG", loggers=["ahvn", "myapp"])
- ahvn.utils.basic.log_utils.restore_logs(loggers=None)[源代码]¶
Restore original log handlers for specified loggers.
- 参数:
loggers (Optional[List[str]]) -- List of logger names to restore. If None, restores all loggers that were modified.
- 返回类型:
示例
>>> restore_logs() # Restore all modified loggers >>> restore_logs(["ahvn"]) # Restore specific logger
- class ahvn.utils.basic.log_utils.SuppressOutput(suppress_stdout=True, suppress_stderr=True)[源代码]¶
基类:
objectContext manager to suppress stdout/stderr at the OS file descriptor level.
This is more aggressive than redirecting sys.stdout/sys.stderr and can capture output from C libraries and subprocesses as well.
Use restore() and suppress() methods for temporary restoration during the suppression context (e.g., for updating progress displays).
示例
>>> with SuppressOutput(): ... # All output suppressed here ... noisy_library_call()
>>> with SuppressOutput(suppress_stderr=False): ... # Only stdout suppressed, stderr still visible ... pass
>>> with SuppressOutput() as suppressor: ... noisy_setup() ... suppressor.restore() # Temporarily show output ... print("Progress update") ... suppressor.suppress() # Continue suppressing ... more_noisy_code()