Provide an option to disable format for some messages. Taken from https://stackoverflow.com/questions/34954373/disable-format-for-some-messages Examples: .. code:: python >>> import logging >>> import sys >>> handler = logging.StreamHandler(sys.std
| 229 | |
| 230 | |
| 231 | class ConditionalFormatter(logging.Formatter): |
| 232 | """Provide an option to disable format for some messages. |
| 233 | Taken from https://stackoverflow.com/questions/34954373/disable-format-for-some-messages |
| 234 | Examples: |
| 235 | .. code:: python |
| 236 | |
| 237 | >>> import logging |
| 238 | >>> import sys |
| 239 | >>> handler = logging.StreamHandler(sys.stdout) |
| 240 | >>> formatter = ConditionalFormatter('%(asctime)s %(levelname)s - %(message)s') |
| 241 | >>> handler.setFormatter(formatter) |
| 242 | >>> logger = logging.getLogger("graphscope") |
| 243 | >>> logger.setLevel("INFO") |
| 244 | >>> logger.addHandler(handler) |
| 245 | >>> logger.info("with formatting") |
| 246 | 2020-12-21 13:44:52,537 INFO - with formatting |
| 247 | >>> logger.info("without formatting", extra={'simple': True}) |
| 248 | without formatting |
| 249 | """ |
| 250 | |
| 251 | def format(self, record): |
| 252 | if hasattr(record, "simple") and record.simple: |
| 253 | return record.getMessage() |
| 254 | return logging.Formatter.format(self, record) |
| 255 | |
| 256 | |
| 257 | class GSLogger(object): |