ml_grid.util.logger_setup

Classes

TeeWriter

Writes to both original stream and a file, preserving all stream behaviors.

Functions

setup_logger(→ logging.Logger)

Sets up a logger that writes to a file and the console.

Module Contents

class ml_grid.util.logger_setup.TeeWriter(original_stream, log_file_path)[source]

Writes to both original stream and a file, preserving all stream behaviors.

original_stream[source]
log_file_path[source]
log_file[source]
encoding[source]
errors[source]
mode[source]
write(message: str) int[source]

Write to both streams, return bytes written.

flush() None[source]

Flush both streams.

close() None[source]

Close only the log file, not the original stream.

isatty() bool[source]

Check if original stream is a TTY.

fileno()[source]

Return file descriptor of original stream if available.

ml_grid.util.logger_setup.setup_logger(experiment_dir: str, param_space_index: int, verbose: int = 1, redirect_stdout: bool = True) logging.Logger[source]

Sets up a logger that writes to a file and the console.

This function creates a timestamped main experiment folder and a sub-folder for the specific run (e.g., ‘run_0’). It configures a logger to save all messages to ‘run.log’ inside the sub-folder and also redirects stdout/stderr to this logger.

Parameters:
  • experiment_dir (str) – The path to the parent directory for this group of experimental runs.

  • param_space_index (int) – The index of the parameter space run.

  • verbose (int) – The verbosity level. Higher numbers mean more logs to the console.

  • redirect_stdout (bool) – If True, redirects stdout and stderr to the logger. Defaults to True.

Returns:

The configured logger instance.

Return type:

logging.Logger