自定义时间格式化器,指定时区为东八区
| 41 | |
| 42 | # 自定义时间格式化器,指定时区为东八区 |
| 43 | class CSTFormatter(logging.Formatter): |
| 44 | """ |
| 45 | 自定义时间格式化器,指定时区为东八区 |
| 46 | """ |
| 47 | |
| 48 | def converter(self, timestamp): |
| 49 | """ |
| 50 | 自定义时间转换函数,加上时区信息 |
| 51 | Args: |
| 52 | timestamp (int): 时间戳。 |
| 53 | Returns: |
| 54 | tuple: 格式化后的时间元组。 |
| 55 | """ |
| 56 | dt = datetime.utcfromtimestamp(timestamp) |
| 57 | dt = pytz.utc.localize(dt).astimezone(tz) |
| 58 | return dt.timetuple() |
| 59 | |
| 60 | formatter = CSTFormatter(self.LOG_FORMAT) |
| 61 | log_name = None |