This class definition is responsible for capturing & logging stdout & stderr messages from subprocess Methods: -------- * __init__(stream_type) - This method is use to initlize the ProcessLogger class object * log(msg) - Log message in the orderly manner. *
| 140 | |
| 141 | |
| 142 | class ProcessLogger(Thread): |
| 143 | """ |
| 144 | This class definition is responsible for capturing & logging |
| 145 | stdout & stderr messages from subprocess |
| 146 | |
| 147 | Methods: |
| 148 | -------- |
| 149 | * __init__(stream_type) |
| 150 | - This method is use to initlize the ProcessLogger class object |
| 151 | |
| 152 | * log(msg) |
| 153 | - Log message in the orderly manner. |
| 154 | |
| 155 | * run() |
| 156 | - Reads the stdout/stderr for messages and sent them to logger |
| 157 | """ |
| 158 | |
| 159 | def __init__(self, stream_type): |
| 160 | """ |
| 161 | This method is use to initialize the ProcessLogger class object |
| 162 | |
| 163 | Args: |
| 164 | stream_type: Type of STD (std) |
| 165 | |
| 166 | Returns: |
| 167 | None |
| 168 | """ |
| 169 | import codecs |
| 170 | |
| 171 | Thread.__init__(self) |
| 172 | self.process = None |
| 173 | self.stream = None |
| 174 | self.logger = open(os.path.join(_out_dir, stream_type), 'wb', |
| 175 | buffering=0) |
| 176 | |
| 177 | def attach_process_stream(self, process, stream): |
| 178 | """ |
| 179 | This function will attach a process and its stream with this thread. |
| 180 | |
| 181 | Args: |
| 182 | process: Process |
| 183 | stream: Stream attached with the process |
| 184 | |
| 185 | Returns: |
| 186 | None |
| 187 | """ |
| 188 | self.process = process |
| 189 | self.stream = stream |
| 190 | |
| 191 | def log(self, msg): |
| 192 | """ |
| 193 | This function will update log file |
| 194 | |
| 195 | Args: |
| 196 | msg: message (bytes from subprocess) |
| 197 | |
| 198 | Returns: |
| 199 | None |