scitex_core.logging

scitex_core.logging.getLogger(name=None)[source]

Return a logger with the specified name, creating it if necessary.

If no name is specified, return the root logger.

scitex_core.logging.configure(level='info', log_file=None, enable_file=True, enable_console=True, capture_prints=True, max_file_size=10485760, backup_count=5)[source]

Configure logging for SciTeX with both console and file output.

Parameters:
  • level (Union[str, int]) – Log level (string or logging constant)

  • log_file (Optional[str]) – Path to log file (default: ~/.scitex/logs/scitex-YYYY-MM-DD.log)

  • enable_file (bool) – Whether to enable file logging

  • enable_console (bool) – Whether to enable console logging

  • capture_prints (bool) – Whether to capture print() statements to logs

  • max_file_size (int) – Maximum size of log file before rotation (default: 10MB)

  • backup_count (int) – Number of backup files to keep (default: 5)

scitex_core.logging.get_log_path()[source]

Get the current log file path.

class scitex_core.logging.Tee(stream, log_path_or_stream, verbose=True)[source]

Bases: object

__init__(stream, log_path_or_stream, verbose=True)[source]
write(data)[source]
Return type:

None

flush()[source]
Return type:

None

isatty()[source]
Return type:

bool

fileno()[source]
Return type:

int

property buffer
close()[source]

Explicitly close the log file (only if we opened it).

scitex_core.logging.tee(sys_or_path=None, sdir=None, verbose=True)[source]

Tee stdout/stderr to files.

Two calling styles are supported:

  1. tee(sys_module, sdir=None) — the legacy call that returns (stdout_tee, stderr_tee) wrapping sys.stdout / sys.stderr.

  2. tee(path) — context-manager form that redirects sys.stdout to a Tee writing to both the original stdout and path.

Example

>>> with tee("/tmp/out.log"):
...     print("hello")  # printed + logged to /tmp/out.log
scitex_core.logging.log_to_file(file_path, level=10, mode='w', formatter=None)[source]

Context manager to temporarily log all output to a specific file.

Usage:

from scitex import logging logger = logging.getLogger(__name__)

with logging.log_to_file(“/path/to/log.txt”):

logger.info(“This goes to both console and /path/to/log.txt”) logger.success(“This too!”)

Parameters:
  • file_path (Union[str, Path]) – Path to log file

  • level (int) – Logging level for this handler (default: DEBUG)

  • mode (str) – File mode (‘w’ for overwrite, ‘a’ for append)

  • formatter (Optional[Formatter]) – Custom formatter (default: SciTeXFileFormatter)

Yields:

The file handler (can be ignored)