Skip to main content

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

库地址

https://pypi.org/project/LogTranslate/0.1/

读取文件-->每行文件-->判断关键tag[每个translate先判断自己的tag满足,然后再正则解析str到通用log,解析后下一个解析的不用解析str-log]

每个translate 都要配置通用的多个tag用于判断是否需要解析然后正则,解析出通用log格式之后, tag的正则可以创建translae对象的时候创建好re.compile("")

Project details


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.4.2.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

LogTranslate-1.4.2-py3-none-any.whl (36.0 kB view details)

Uploaded Python 3

File details

Details for the file LogTranslate-1.4.2.tar.gz.

File metadata

  • Download URL: LogTranslate-1.4.2.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.4

File hashes

Hashes for LogTranslate-1.4.2.tar.gz
Algorithm Hash digest
SHA256 3a1dc729144041fdb0645755d8af90fdf288cbd753d610d2fb09e33f9069f795
MD5 822dde2474c3778caf4e12bee54371c9
BLAKE2b-256 a30d3c81b239ac344474ff41045ba801a30ad6d530520ae5bcef6cfd817c0a4b

See more details on using hashes here.

File details

Details for the file LogTranslate-1.4.2-py3-none-any.whl.

File metadata

  • Download URL: LogTranslate-1.4.2-py3-none-any.whl
  • Upload date:
  • Size: 36.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.4

File hashes

Hashes for LogTranslate-1.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c60d0ca84ba309fc5aa48f9cabed04b993b3c2d26f565d44874cc17cb76c6526
MD5 aefc12d892ce968c715bb21adcef49dc
BLAKE2b-256 82e98cb913029ab49c2899f0013254cd7559eaaee0d39c1f983c7a6529651d4e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page