Logging - tmuxp.log¶
Log utilities for tmuxp.
-
class tmuxp.log.TmuxpLoggerAdapter¶
Bases:
LoggerAdapterLoggerAdapter that merges extra dictionary on Python < 3.13.
Follows the portable pattern to avoid repeating the same extra on every call while preserving the ability to add per-call extra kwargs.
Examples
>>> adapter = TmuxpLoggerAdapter( ... logging.getLogger("test"), ... {"tmux_session": "my-session"}, ... ) >>> msg, kwargs = adapter.process("hello %s", {"extra": {"tmux_window": "editor"}}) >>> msg 'hello %s' >>> kwargs["extra"]["tmux_session"] 'my-session' >>> kwargs["extra"]["tmux_window"] 'editor'
-
tmuxp.log.setup_logger(logger=None, level='INFO')¶
Configure tmuxp’s logging for CLI use.
Can checks for any existing loggers to prevent loading handlers twice.
-
tmuxp.log.set_style(message, stylized, style_before='', style_after='', prefix='', suffix='')¶
Stylize terminal logging output.
-
tmuxp.log.debug_log_template(self, record, stylized=False, **kwargs)¶
Return the prefix for the log message. Template for Formatter.
- Parameters:
record (
logging.LogRecord) – Object passed fromlogging.Formatter.format().kwargs (Any)
- Returns:
Log template.
- Return type:
-
class tmuxp.log.DebugLogFormatter¶
Bases:
LogFormatterProvides greater technical details than standard log Formatter.
-
tmuxp.log.setup_log_file(log_file, level='INFO')¶
Attach a file handler to the tmuxp logger.
Examples
>>> import tempfile, os, logging >>> f = tempfile.NamedTemporaryFile(suffix=".log", delete=False) >>> f.close() >>> setup_log_file(f.name, level="INFO") >>> tmuxp_logger = logging.getLogger("tmuxp") >>> tmuxp_logger.handlers = [ ... h for h in tmuxp_logger.handlers if not isinstance(h, logging.FileHandler) ... ] >>> os.unlink(f.name)
-
tmuxp.log.tmuxp_echo(message=None, file=None)¶
Print user-facing CLI output.
Examples
>>> tmuxp_echo("Session loaded") Session loaded
>>> tmuxp_echo("Warning message") Warning message