Create logger for diagnostic
()
| 195 | |
| 196 | |
| 197 | def create_logger(): |
| 198 | """ |
| 199 | Create logger for diagnostic |
| 200 | """ |
| 201 | # create logger |
| 202 | loggr = logging.getLogger("nodeenv") |
| 203 | loggr.setLevel(logging.INFO) |
| 204 | |
| 205 | # monkey patch |
| 206 | def emit(self, record): |
| 207 | msg = self.format(record) |
| 208 | fs = "%s" if getattr(record, "continued", False) else "%s\n" |
| 209 | self.stream.write(fs % to_utf8(msg)) |
| 210 | self.flush() |
| 211 | logging.StreamHandler.emit = emit |
| 212 | |
| 213 | # create console handler and set level to debug |
| 214 | ch = logging.StreamHandler() |
| 215 | ch.setLevel(logging.DEBUG) |
| 216 | |
| 217 | # create formatter |
| 218 | formatter = logging.Formatter(fmt="%(message)s") |
| 219 | |
| 220 | # add formatter to ch |
| 221 | ch.setFormatter(formatter) |
| 222 | |
| 223 | # add ch to logger |
| 224 | loggr.addHandler(ch) |
| 225 | return loggr |
| 226 | |
| 227 | |
| 228 | logger = create_logger() |