-
Notifications
You must be signed in to change notification settings - Fork 596
add error log to file #3431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Jiang-Jia-Jun
merged 8 commits into
PaddlePaddle:develop
from
xiaolei373:new_log_config
Aug 20, 2025
+1,399
−33
Merged
add error log to file #3431
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f288d98
feat(log):add_request_and_response_log
xiaolei373 f083a85
Merge branch 'PaddlePaddle:develop' into develop
xiaolei373 830785b
Merge branch 'PaddlePaddle:develop' into develop
xiaolei373 3e8d4ab
Merge branch 'PaddlePaddle:develop' into develop
xiaolei373 26611bf
Merge branch 'PaddlePaddle:develop' into develop
xiaolei373 775060f
Merge branch 'PaddlePaddle:develop' into develop
xiaolei373 b6425ba
Merge branch 'PaddlePaddle:develop' into develop
xiaolei373 9cef8b0
feat[log]:add error log to file
xiaolei373 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,7 +121,7 @@ dmypy.json | |
FETCH_HEAD | ||
|
||
#log | ||
log*/ | ||
log/ | ||
|
||
checkpoints/ | ||
checkpoints_origin/ | ||
|
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" | ||
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License" | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
""" | ||
|
||
""" | ||
自定义日志格式化器模块 | ||
该模块定义了 ColoredFormatter 类,用于在控制台输出带颜色的日志信息, | ||
便于开发者在终端中快速识别不同级别的日志。 | ||
""" | ||
|
||
import logging | ||
|
||
|
||
class ColoredFormatter(logging.Formatter): | ||
""" | ||
自定义日志格式器,用于控制台输出带颜色的日志。 | ||
支持的颜色: | ||
- WARNING: 黄色 | ||
- ERROR: 红色 | ||
- CRITICAL: 红色 | ||
- 其他等级: 默认终端颜色 | ||
""" | ||
|
||
COLOR_CODES = { | ||
logging.WARNING: 33, # 黄色 | ||
logging.ERROR: 31, # 红色 | ||
logging.CRITICAL: 31, # 红色 | ||
} | ||
|
||
def format(self, record): | ||
""" | ||
格式化日志记录,并根据日志等级添加 ANSI 颜色前缀和后缀。 | ||
Args: | ||
record (LogRecord): 日志记录对象。 | ||
Returns: | ||
str: 带有颜色的日志消息字符串。 | ||
""" | ||
color_code = self.COLOR_CODES.get(record.levelno, 0) | ||
prefix = f"\033[{color_code}m" | ||
suffix = "\033[0m" | ||
message = super().format(record) | ||
if color_code: | ||
message = f"{prefix}{message}{suffix}" | ||
return message |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
增加开源协议
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好滴