Logging - tmuxp.log

Log utilities for tmuxp.

class tmuxp.log.TmuxpLoggerAdapter

Bases: LoggerAdapter

LoggerAdapter 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')
function[source]

Configure tmuxp’s logging for CLI use.

Can checks for any existing loggers to prevent loading handlers twice.

Parameters:
  • logger (Logger) – logger instance for tmuxp

  • level (str)

Return type:

None

tmuxp.log.set_style(message, stylized, style_before='', style_after='', prefix='', suffix='')
function[source]

Stylize terminal logging output.

Parameters:
Return type:

str

class tmuxp.log.LogFormatter

Bases: Formatter

Format logs for tmuxp.

tmuxp.log.debug_log_template(self, record, stylized=False, **kwargs)
function[source]

Return the prefix for the log message. Template for Formatter.

Parameters:
Returns:

Log template.

Return type:

str

class tmuxp.log.DebugLogFormatter

Bases: LogFormatter

Provides greater technical details than standard log Formatter.

tmuxp.log.setup_log_file(log_file, level='INFO')
function[source]

Attach a file handler to the tmuxp logger.

Parameters:
  • log_file (str) – Path to the log file.

  • level (str) – Log level name (e.g. “DEBUG”, “INFO”). Selects formatter and sets handler filtering level.

Return type:

None

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)
function[source]

Print user-facing CLI output.

Parameters:
  • message (str | None) – Message to print. If None, does nothing.

  • file (t.TextIO | None) – Output stream. Defaults to sys.stdout.

Return type:

None

Examples

>>> tmuxp_echo("Session loaded")
Session loaded
>>> tmuxp_echo("Warning message")
Warning message