Inject process context fields used by log formatter.
| 111 | |
| 112 | |
| 113 | class ProcessContextFilter(logging.Filter): |
| 114 | """Inject process context fields used by log formatter.""" |
| 115 | |
| 116 | def __init__(self, name: str = 'lmdeploy'): |
| 117 | super().__init__(name) |
| 118 | |
| 119 | def filter(self, record: LogRecord) -> bool: |
| 120 | # `ppid` is not a builtin LogRecord attribute, inject it so logs from |
| 121 | # parent api_server and child executor processes can be correlated. |
| 122 | record.ppid = os.getppid() |
| 123 | return True |
| 124 | |
| 125 | |
| 126 | _FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(filename)s:%(lineno)d' \ |