pyagc.utils.get_logger
- get_logger(filename: str, log_level: int = 1, name: Optional[str] = None, mode: str = 'a') Logger[source]
Create and configure a logger with both file and console handlers.
Sets up a logger that writes to both a file and the console (stdout) with consistent formatting. The logger can be configured with different verbosity levels and can append to or overwrite existing log files.
- Parameters:
filename (str) – Path to the log file. Parent directories will NOT be created automatically.
log_level (int, optional) –
Logging verbosity level:
0: DEBUG (most verbose)1: INFO (default)2: WARNING (least verbose)
(default:
1)name (str, optional) – Name for the logger. If
None, uses the root logger. Use different names to maintain separate loggers. (default:None)mode (str, optional) –
File opening mode:
'a': Append to existing file (default)'w': Overwrite existing file
(default:
'a')
- Returns:
- Configured logger instance with both file and console
handlers attached.
- Return type:
Note
The log format is:
'%(asctime)s - %(filename)s - %(levelname)s - %(message)s'Existing handlers are removed before adding new ones to avoid duplicates
Both file and console handlers use the same formatting
The logger is returned but also accessible via
logging.getLogger(name)