log
optimus_dl.core.log
¶
setup_logging(level=logging.INFO, log_file=None, use_rich=True, use_colors=True, format_string=None, date_format='%Y-%m-%d %H:%M:%S')
¶
Set up beautiful Python logging with colors and optional file output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
int | str
|
Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
INFO
|
log_file
|
str | Path | None
|
Optional path to log file for persistent logging |
None
|
use_rich
|
bool
|
Use Rich library for enhanced console output |
True
|
use_colors
|
bool
|
Enable colored output (ignored if use_rich=True) |
True
|
format_string
|
str | None
|
Custom format string (uses default if None) |
None
|
date_format
|
str
|
Date format for timestamps |
'%Y-%m-%d %H:%M:%S'
|
Returns:
| Type | Description |
|---|---|
Logger
|
Configured logger instance |
Example
Source code in optimus_dl/core/log.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
tqdm(*args, **kwargs)
¶
A wrapper around tqdm.auto.tqdm that handles non-interactive environments. In non-TTY environments, it sets default intervals to avoid flooding logs.
Source code in optimus_dl/core/log.py
trange(*args, **kwargs)
¶
A wrapper around tqdm.auto.trange that handles non-interactive environments.
Source code in optimus_dl/core/log.py
warn_once(logger, message)
¶
Log a warning message only once, even if called multiple times.
This is useful for deprecation warnings or other messages that should only appear once per program execution, even if the code path is executed multiple times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger
|
Logger instance to log the warning to. |
required |
message
|
str
|
Warning message to log (only logged once). |
required |