A Python library for translate log from log files
Project description
作用
把日志文件拖动到窗口即可解析日志
使用
安装
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
库地址
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
LogTranslate-1.3.5.tar.gz
(29.9 kB
view details)
Built Distribution
File details
Details for the file LogTranslate-1.3.5.tar.gz
.
File metadata
- Download URL: LogTranslate-1.3.5.tar.gz
- Upload date:
- Size: 29.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 339a389c7cd466b1635a491e51fae2c4d3e467ef147f93d8938593f180fc6224 |
|
MD5 | f45dc5ae36af2541965b493d4b8e9fd3 |
|
BLAKE2b-256 | 130e577f9aa3c6c201300d0d43c6b48488de5b2fe49e7afdbf72f8762c1cb16b |
File details
Details for the file LogTranslate-1.3.5-py3-none-any.whl
.
File metadata
- Download URL: LogTranslate-1.3.5-py3-none-any.whl
- Upload date:
- Size: 33.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4475040c9531ab1ad6817353f91d9c2984aff7f46d74fd8b42e05b5fa3a67c7b |
|
MD5 | 66f69a38ee82baa656d0c3d903d940a3 |
|
BLAKE2b-256 | 8e9e1ee3ed8e2722804321425c3a568a0db6515c425d5d131cff5d07628afded |