Logger
CapturingStream
Bases: io.StringIO
Stream to capture stdout/stderr line by line and put them in a queue.
Source code in src/guigaga/logger.py
__init__(queue, *args, **kwargs)
Initializes a new instance of the CapturingStream class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
queue |
mpQueue
|
The queue to put the captured lines in. |
required |
*args |
Variable length argument list. |
()
|
|
**kwargs |
Arbitrary keyword arguments. |
{}
|
Side Effects
Initializes the _queue attribute with the provided queue and the _current_line attribute to an empty string.
Source code in src/guigaga/logger.py
flush()
Flushes the stream and captures the current line.
Side Effects
If there is a current line, puts it in the queue and resets the current line to an empty string. Then flushes the stream.
Source code in src/guigaga/logger.py
write(s)
Writes a string to the stream and captures it line by line.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s |
str
|
The string to write. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The number of characters written. |
Side Effects
Writes the string to the stream and captures it line by line, putting each line in the queue.
Notes
Normalizes newlines by replacing " " with "\n".
Source code in src/guigaga/logger.py
Logger
A class for logging messages with different levels.
Attributes:
Name | Type | Description |
---|---|---|
process |
The process that the logger is logging for. |
|
exit_code |
The exit code of the process. |
Source code in src/guigaga/logger.py
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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
__init__()
Initializes a new instance of the Logger class.
Side Effects
Initializes the process and exit_code attributes to None.
intercept_stdin_stdout(fn, ctx, *, catch_errors)
Wrap a function to intercept and yield stdout and stderr using threading.
Source code in src/guigaga/logger.py
log(message, level='INFO')
Logs a message with a specified level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
str
|
The message to log. |
required |
level |
str
|
The level of the log. Defaults to "INFO". |
'INFO'
|
Returns:
Name | Type | Description |
---|---|---|
dict |
A dictionary containing the message and level. |
Examples:
Source code in src/guigaga/logger.py
wrap_for_process(fn, ctx)
Wrap the function to capture stdout, stderr, and errors in real-time.