## 作用
把日志文件拖动到窗口即可解析日志
## 使用
安装
```commandline
pip install LogTranslate
```
项目根目录 创建 config.py
里面定义字段 translator数组
```commandline
translators = [SysLogTranslator(tag_translators=[BluetoothTranslator(), CrashPatternTranslator()])]
```
SysLogTranslator是将文件中每行字符串解析出 tag,time,pid,msg
SysLogTranslator的参数 tag_translators 是数组 用来解析 各种tag对应的内容
解析tag的基类有
- TagPatternTranslator 通过正则匹配tag然后解析
```python
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然后解析
```python
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
```python
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
```python
if __name__ == "__main__":
app = QApplication(sys.argv)
window = PyQt6Window()
window.show()
sys.exit(app.exec())
```
#### 2, 执行打包命令
```commandline
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("")
Raw data
{
"_id": null,
"home_page": "https://github.com/5hmlA/PyTools",
"name": "LogTranslate",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "tools log translate",
"author": "5hmlA",
"author_email": "gene.jzy@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/59/16/46e951df6d05387be250d1934580de3181894db8a64416d6a388f82208c0/logtranslate-1.5.tar.gz",
"platform": null,
"description": "## \u4f5c\u7528\n\n\u628a\u65e5\u5fd7\u6587\u4ef6\u62d6\u52a8\u5230\u7a97\u53e3\u5373\u53ef\u89e3\u6790\u65e5\u5fd7\n\n## \u4f7f\u7528\n\n\u5b89\u88c5\n\n```commandline\npip install LogTranslate\n```\n\n\u9879\u76ee\u6839\u76ee\u5f55 \u521b\u5efa config.py\n\u91cc\u9762\u5b9a\u4e49\u5b57\u6bb5 translator\u6570\u7ec4\n\n```commandline\ntranslators = [SysLogTranslator(tag_translators=[BluetoothTranslator(), CrashPatternTranslator()])]\n```\n\nSysLogTranslator\u662f\u5c06\u6587\u4ef6\u4e2d\u6bcf\u884c\u5b57\u7b26\u4e32\u89e3\u6790\u51fa tag,time,pid,msg\nSysLogTranslator\u7684\u53c2\u6570 tag_translators \u662f\u6570\u7ec4 \u7528\u6765\u89e3\u6790 \u5404\u79cdtag\u5bf9\u5e94\u7684\u5185\u5bb9\n\u89e3\u6790tag\u7684\u57fa\u7c7b\u6709\n\n- TagPatternTranslator \u901a\u8fc7\u6b63\u5219\u5339\u914dtag\u7136\u540e\u89e3\u6790\n ```python\n class CrashPatternTranslator(TagPatternTranslator):\n def __init__(self):\n super().__init__({\n r\"AndroidRuntime|FATAL.*|System.err.*\": activity_task_translator\n })\n \n def activity_task_translator(tag, msg): # \u8fd9\u91cc\u4e24\u4e2a\u53c2\u6570\n # todo \u8fd9\u91cc\u9700\u8981\u8fc7\u6ee4\u5305\u540d\n return Log(translated=\" ------ %s > %s----- \" % (tag, msg), level=Level.e)\n\n ```\n\n- TagStrTranslator \u901a\u8fc7\u5b57\u7b26\u4e32\u5339\u914dtag\u7136\u540e\u89e3\u6790\n ```python\n class BluetoothTranslator(TagStrTranslator):\n def __init__(self):\n super().__init__({\n \"BluetoothAdapter\": bluetooth_adapter,\n })\n \n def bluetooth_adapter(msg):# \u8fd9\u91cc\u4e00\u4e2a\u53c2\u6570\n # todo \u8fd9\u91cc\u9700\u8981\u8fc7\u6ee4\u5305\u540d\n return Log(translated=\" ------ %s > %s----- \" % (tag, msg), level=Level.e)\n\n ```\n- SecStrTagTranslator \u89e3\u6790\u4e8c\u7ea7tag\n ```python\n class SecTagDemoTranslator(SecStrTagTranslator):\n def __init__(self):\n super().__init__(\"DFJ\",\n lambda string: re.search(r\"(?P<tag>.*?) *:(?P<msg>.*)\", string),\n [\n SysLogTranslator({\n \"sec_tag\": self.new_tag\n })\n ])\n\n def new_tag(self, tag, msg):# \u8fd9\u91cc\u4e24\u4e2a\u53c2\u6570\n return Log(translated=msg)\n ```\n\n## \u6253\u5305\u6210 exe\n\n#### 1 \uff0c\u9879\u76ee\u6839\u76ee\u5f55\u521b\u5efa ui.py\n\n```python\n\nif __name__ == \"__main__\":\n app = QApplication(sys.argv)\n window = PyQt6Window()\n window.show()\n sys.exit(app.exec())\n```\n\n#### 2\uff0c \u6267\u884c\u6253\u5305\u547d\u4ee4\n\n```commandline\n\npyinstaller -n [name] --hidden-import config -F -w [-i tools.ico] ui.py\n\n```\n\n### \u5e93\u5730\u5740\n\nhttps://pypi.org/project/LogTranslate/0.1/\n\n\u8bfb\u53d6\u6587\u4ef6-->\u6bcf\u884c\u6587\u4ef6-->\n\u5224\u65ad\u5173\u952etag[\u6bcf\u4e2atranslate\u5148\u5224\u65ad\u81ea\u5df1\u7684tag\u6ee1\u8db3\uff0c\u7136\u540e\u518d\u6b63\u5219\u89e3\u6790str\u5230\u901a\u7528log\uff0c\u89e3\u6790\u540e\u4e0b\u4e00\u4e2a\u89e3\u6790\u7684\u4e0d\u7528\u89e3\u6790str-log]\n\n\u6bcf\u4e2atranslate \u90fd\u8981\u914d\u7f6e\u901a\u7528\u7684\u591a\u4e2atag\u7528\u4e8e\u5224\u65ad\u662f\u5426\u9700\u8981\u89e3\u6790\u7136\u540e\u6b63\u5219\uff0c\u89e3\u6790\u51fa\u901a\u7528log\u683c\u5f0f\u4e4b\u540e\uff0c\ntag\u7684\u6b63\u5219\u53ef\u4ee5\u521b\u5efatranslae\u5bf9\u8c61\u7684\u65f6\u5019\u521b\u5efa\u597dre.compile(\"\")\n",
"bugtrack_url": null,
"license": "MIT Licence",
"summary": "A Python library for translate log from log files",
"version": "1.5",
"project_urls": {
"Homepage": "https://github.com/5hmlA/PyTools"
},
"split_keywords": [
"tools",
"log",
"translate"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "930a10a64869358af2fdb61f5237882743b0a91c8fb7afde68f004346188af47",
"md5": "6dd9df49a28359841a65cf4675551516",
"sha256": "f4e6c284977a511d181cab3c9f9670cb8d1596912bf3848f20e6083275f0bb6d"
},
"downloads": -1,
"filename": "LogTranslate-1.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6dd9df49a28359841a65cf4675551516",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 36322,
"upload_time": "2024-12-14T17:14:46",
"upload_time_iso_8601": "2024-12-14T17:14:46.867360Z",
"url": "https://files.pythonhosted.org/packages/93/0a/10a64869358af2fdb61f5237882743b0a91c8fb7afde68f004346188af47/LogTranslate-1.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "591646e951df6d05387be250d1934580de3181894db8a64416d6a388f82208c0",
"md5": "2ce6a8c7945bd5324f2cb0599680c16a",
"sha256": "e0959b9800eb0ac6d6ad4cd82b24453d5b18e3a813cdbd32a583f8b93d3dea58"
},
"downloads": -1,
"filename": "logtranslate-1.5.tar.gz",
"has_sig": false,
"md5_digest": "2ce6a8c7945bd5324f2cb0599680c16a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 33045,
"upload_time": "2024-12-14T17:14:48",
"upload_time_iso_8601": "2024-12-14T17:14:48.158397Z",
"url": "https://files.pythonhosted.org/packages/59/16/46e951df6d05387be250d1934580de3181894db8a64416d6a388f82208c0/logtranslate-1.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-14 17:14:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "5hmlA",
"github_project": "PyTools",
"github_not_found": true,
"lcname": "logtranslate"
}