Logging Module (stx.logging)
Unified logging with file/console output, custom warnings, exception hierarchy, and stream redirection.
Quick Reference
import scitex as stx
from scitex import logging
# Get a logger
logger = logging.getLogger(__name__)
logger.info("Processing data")
logger.success("Analysis complete") # Custom level (31)
logger.fail("Model diverged") # Custom level (35)
# Configure globally
logging.configure(level="DEBUG", log_file="./run.log")
logging.set_level("WARNING")
# Temporary file logging
with logging.log_to_file("analysis.log"):
logger.info("This goes to both console and file")
# Warnings
logging.warn("Large dataset", category=logging.PerformanceWarning)
logging.warn_deprecated("old_func", "new_func", version="3.0")
logging.filterwarnings("ignore", category=logging.UnitWarning)
Log Levels
Level |
Value |
Description |
|---|---|---|
|
10 |
Detailed diagnostic information |
|
20 |
General operational messages |
|
30 |
Something unexpected but not fatal |
|
31 |
Custom: operation completed successfully |
|
35 |
Custom: operation failed (non-fatal) |
|
40 |
Serious problem |
|
50 |
Program may not continue |
Warning Categories
SciTeXWarning– Base warning classUnitWarning– SI unit convention issuesStyleWarning– Formatting issuesSciTeXDeprecationWarning– Deprecated featuresPerformanceWarning– Performance issuesDataLossWarning– Potential data loss
Exception Hierarchy
All inherit from SciTeXError:
I/O:
IOError,FileFormatError,SaveError,LoadErrorConfig:
ConfigurationError,ConfigFileNotFoundError,ConfigKeyErrorPath:
PathError,InvalidPathError,PathNotFoundErrorData:
DataError,ShapeError,DTypeErrorPlotting:
PlottingError,FigureNotFoundError,AxisErrorStats:
StatsError,TestErrorScholar:
ScholarError,SearchError,PDFDownloadError,DOIResolutionErrorNN:
NNError,ModelErrorTemplate:
TemplateError,TemplateViolationError
Stream Redirection
from scitex.logging import tee
import sys
# Redirect stdout/stderr to log files
sys.stdout, sys.stderr = tee(sys, sdir="./output")
The @stx.session decorator handles this automatically.
API Reference
See scitex.logging API Reference for the auto-generated Python API.