作用
把日志文件拖动到窗口即可解析日志
使用
安装
pip install LogTranslate
项目根目录 创建 config.py 里面定义字段 translator数组
translators = [SysLogTranslator(tag_translators=[BluetoothTranslator(), CrashPatternTranslator()])]
SysLogTranslator是将文件中每行字符串解析出 tag,time,pid,msg SysLogTranslator的参数 tag_translators 是数组 用来解析 各种tag对应的内容 解析tag的基类有
-
TagPatternTranslator 通过正则匹配tag然后解析
class CrashPatternTranslator(TagPatternTranslator): def __init__(self): super().__init__({ r"AndroidRuntime|FATAL.*|System.err.*": activity_task_translator }) def activity_task_translator(tag, msg): # 这里两个参数 # todo 这里需要过滤包名 return Log(translated=" ------ %s > %s----- " % (tag, msg), level=Level.e)
-
TagStrTranslator 通过字符串匹配tag然后解析
class BluetoothTranslator(TagStrTranslator): def __init__(self): super().__init__({ "BluetoothAdapter": bluetooth_adapter, }) def bluetooth_adapter(msg):# 这里一个参数 # todo 这里需要过滤包名 return Log(translated=" ------ %s > %s----- " % (tag, msg), level=Level.e)
-
SecStrTagTranslator 解析二级tag
class SecTagDemoTranslator(SecStrTagTranslator): def __init__(self): super().__init__("DFJ", lambda string: re.search(r"(?P<tag>.*?) *:(?P<msg>.*)", string), [ SysLogTranslator({ "sec_tag": self.new_tag }) ]) def new_tag(self, tag, msg):# 这里两个参数 return Log(translated=msg)
打包成 exe
1 ,项目根目录创建 ui.py
if __name__ == "__main__":
app = QApplication(sys.argv)
window = PyQt6Window()
window.show()
sys.exit(app.exec())
2, 执行打包命令
pyinstaller -n [name] --hidden-import config -F -w [-i tools.ico] ui.py
库地址
https://pypi.org/project/LogTranslate/0.1/
读取文件-->每行文件--> 判断关键tag[每个translate先判断自己的tag满足,然后再正则解析str到通用log,解析后下一个解析的不用解析str-log]
每个translate 都要配置通用的多个tag用于判断是否需要解析然后正则,解析出通用log格式之后, tag的正则可以创建translae对象的时候创建好re.compile("")
Metadata
Release files for LogTranslate 1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| logtranslate-1.7.tar.gz | 33.3 kB | Without provenance | Details for logtranslate-1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| logtranslate-1.7-py3-none-any.whl | Python 3 | none | any | Details for logtranslate-1.7-py3-none-any.whl |
Total release size: 69.9 kB
Release files / logtranslate-1.7.tar.gz
| Download URL | logtranslate-1.7.tar.gz |
|---|---|
| Size | 33.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b226c73f93b01d4b6e5b298a023c3acbb96dd5c1a9dbd6dfa669089016484dae
|
|
BLAKE2b-256 checksum How to use checksums |
ec56af9f537524355bfe2cd8fea9cc1b5f39c920685cd3a33ee0bfd38bbd5149
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / logtranslate-1.7-py3-none-any.whl
| Download URL | logtranslate-1.7-py3-none-any.whl |
|---|---|
| Size | 36.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
081b3c582652027108d7da6eef0cad3eb8855d39c7c1042dd5435ec5a3ad7f9c
|
|
BLAKE2b-256 checksum How to use checksums |
72898054dcc68f63a35f9c1eeeee6a48956756c3ea5624424e83dd7fcc880f1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for LogTranslate 1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.