如何给logcat文件加高亮

作者: felix_forever | 来源:发表于2017-08-27 23:24 被阅读60次

    使用android studio的时候,看logcat各种级别各种级别的时候有各种各样的颜色,像我就有点依赖这些颜色,对红色和黄色的error(warning)就比较敏感,但是logcat也有缺陷,就是没有搜索,虽然过滤也不错,但是如果我要看某个log前后的呢,其次就是,我机子插着的时候,还在不停的刷,如果之前的被刷掉了呢?我在意的是到某个地方的log,如果往后太多,影响到我现在的分析呢?这种情况一般就需要保存到本地,但是本地的话,就没了高亮,所以今天介绍的是用sublime来给自己的log定义高亮。
    首先,要下载packageDev,ctrl+shift+p调出控制面板(没装控制面板的,自行搜索sublime 安装package control),安装完packageDev后,tools->packages->package developement->new syntax definition,会有默认的模板

    # [PackageDev] target_format: plist, ext: tmLanguage
    ---
    name: Syntax Name
    scopeName: source.syntax_name
    fileTypes: []
    uuid: 832949e4-ea62-488c-9ae2-7194594ce134
    
    patterns:
    - 
    ...
    

    先附上我的吧,自己根据需要再进行修改

    ···# [PackageDev] target_format: plist, ext: tmLanguage
    ---
    name: log
    scopeName: source.log
    fileTypes: [log]
    uuid: 7b7dfa50-0e20-4f46-94b8-79f81bee1153
    
    patterns:
    - comment: Error
      name: felix.error
      match: '[0-9]{1,2}-[0-9 :.]+ [0-9-]+/(\?|\S)+ ([Ee]/)[\s\S]+'
    
    - comment: Warning
      name: felix.warn
      match: '[0-9]{1,2}-[0-9 :.]+ [0-9-]+/(\?|\S)+ ([Ww]/)[\s\S]+'
      
    - comment: DEBUG
      name: felix.debug
      match: '[0-9]{1,2}-[0-9 :.]+ [0-9-]+/(\?|\S)+ ([Dd]/)[\s\S]+'
      
    - comment: Info
      name: felix.info
      match: '[0-9]{1,2}-[0-9 :.]+ [0-9-]+/(\?|\S)+ ([Ii]/)[\s\S]+'
      
    - comment: Assert
      name: felix.assert
      match: '[0-9]{1,2}-[0-9 :.]+ [0-9-]+/(\?|\S)+ ([Aa]/)[\s\S]+'
      
    - comment: Verbose
      name: felix.verbose
      match: '[0-9]{1,2}-[0-9 :.]+ [0-9-]+/(\?|\S)+ ([Vv]/)[\s\S]+'
    
    - comment: Link
      name: keyword
      match: '\([a-zA-Z]+.java:[0-9]+\)'
    
    ...
    

    简单介绍一下patterns吧,
    comment,自己的名字,自己写个自己知道的即可
    name:这个比较重要,颜色的名字,是个scopeName,主题上有定义的,我上面写的是我自己添加到主题颜色里面的,后面再说。
    match:正则表达式,匹配自己需要的文本,对于logcat我只能想到E/等标识了,有更好的欢迎补充(其他格式的自己定义)(备注下:好像同一个表达式无法匹配回车换行,试了好多次都没成功,所以,那种抛出异常的有多行,例如at啥的,后面的就匹配不到了,以及部分信息会回车再写信息的,也匹配不了,如果可以的话,也欢迎补充)
    我自己就匹配了error,warn,debug,info,verbose,assert,以及抛出异常显示的代码行数的匹配了下,有其他需要的,可以自己继续匹配

    编辑完后,直接保存(建议新建个文件夹保存),会保存成YAML-tmlanguage格式,系统识别的是tmlanguage格式,所以,ctrl+shift+B(tools->build with)选择convert to ... 控制台会显示转换信息,你到你保存的文件的目录下看,会多了一个和你同名,但是后缀名是tmlanguage(少了YAML),这个时候,新的语言就定义成功了,这时候,打开你的log文件,如果没识别出来,右下角,文件类型,选择你刚写的那个fileType(我的是.log),就可以了。

    你刚才的name可能并不知道系统定义了哪些scopeName,所以,接下来就是如果自定义了。
    首先preferences->Settings-Users,大概看到这个

    {
        "color_scheme": "Packages/User/SublimeLinter/Monokai (SL).tmTheme",
        "font_size": 18
    }
    

    color_scheme是你的主题,找到你sublime text的安装目录,根据你的路径找到tmTheme,打开可以看到系统定义的所有的scopeName,根据自己选择找到合适的颜色即可。自定义的话,根据他的格式,应该很好看懂,依葫芦画瓢,懒的话,我也附上我修改过后的完整的,不会的就直接覆盖上去即可。

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
        <dict>
            <key>name</key>
            <string>Monokai</string>
            <key>settings</key>
            <array>
                <dict>
                    <key>settings</key>
                    <dict>
                        <key>background</key>
                        <string>#272822</string>
                        <key>caret</key>
                        <string>#F8F8F0</string>
                        <key>foreground</key>
                        <string>#F8F8F2</string>
                        <key>invisibles</key>
                        <string>#3B3A32</string>
                        <key>lineHighlight</key>
                        <string>#3E3D32</string>
                        <key>selection</key>
                        <string>#49483E</string>
                        <key>findHighlight</key>
                        <string>#FFE792</string>
                        <key>findHighlightForeground</key>
                        <string>#000000</string>
                        <key>selectionBorder</key>
                        <string>#222218</string>
                        <key>activeGuide</key>
                        <string>#9D550FB0</string>
    
                        <key>bracketsForeground</key>
                        <string>#F8F8F2A5</string>
                        <key>bracketsOptions</key>
                        <string>underline</string>
    
                        <key>bracketContentsForeground</key>
                        <string>#F8F8F2A5</string>
                        <key>bracketContentsOptions</key>
                        <string>underline</string>
    
                        <key>tagsOptions</key>
                        <string>stippled_underline</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Comment</string>
                    <key>scope</key>
                    <string>comment</string>
                    <key>settings</key>
                    <dict>
                        <key>foreground</key>
                        <string>#75715E</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>String</string>
                    <key>scope</key>
                    <string>string</string>
                    <key>settings</key>
                    <dict>
                        <key>foreground</key>
                        <string>#E6DB74</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Number</string>
                    <key>scope</key>
                    <string>constant.numeric</string>
                    <key>settings</key>
                    <dict>
                        <key>foreground</key>
                        <string>#AE81FF</string>
                    </dict>
                </dict>
    
                <dict>
                    <key>name</key>
                    <string>Built-in constant</string>
                    <key>scope</key>
                    <string>constant.language</string>
                    <key>settings</key>
                    <dict>
                        <key>foreground</key>
                        <string>#AE81FF</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>User-defined constant</string>
                    <key>scope</key>
                    <string>constant.character, constant.other</string>
                    <key>settings</key>
                    <dict>
                        <key>foreground</key>
                        <string>#AE81FF</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Variable</string>
                    <key>scope</key>
                    <string>variable</string>
                    <key>settings</key>
                    <dict>
                        <key>fontStyle</key>
                        <string />
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Keyword</string>
                    <key>scope</key>
                    <string>keyword</string>
                    <key>settings</key>
                    <dict>
                        <key>foreground</key>
                        <string>#F92672</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Storage</string>
                    <key>scope</key>
                    <string>storage</string>
                    <key>settings</key>
                    <dict>
                        <key>fontStyle</key>
                        <string />
                        <key>foreground</key>
                        <string>#F92672</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Storage type</string>
                    <key>scope</key>
                    <string>storage.type</string>
                    <key>settings</key>
                    <dict>
                        <key>fontStyle</key>
                        <string>italic</string>
                        <key>foreground</key>
                        <string>#66D9EF</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Class name</string>
                    <key>scope</key>
                    <string>entity.name.class</string>
                    <key>settings</key>
                    <dict>
                        <key>fontStyle</key>
                        <string>underline</string>
                        <key>foreground</key>
                        <string>#A6E22E</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Inherited class</string>
                    <key>scope</key>
                    <string>entity.other.inherited-class</string>
                    <key>settings</key>
                    <dict>
                        <key>fontStyle</key>
                        <string>italic underline</string>
                        <key>foreground</key>
                        <string>#A6E22E</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Function name</string>
                    <key>scope</key>
                    <string>entity.name.function</string>
                    <key>settings</key>
                    <dict>
                        <key>fontStyle</key>
                        <string />
                        <key>foreground</key>
                        <string>#A6E22E</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Function argument</string>
                    <key>scope</key>
                    <string>variable.parameter</string>
                    <key>settings</key>
                    <dict>
                        <key>fontStyle</key>
                        <string>italic</string>
                        <key>foreground</key>
                        <string>#FD971F</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Tag name</string>
                    <key>scope</key>
                    <string>entity.name.tag</string>
                    <key>settings</key>
                    <dict>
                        <key>fontStyle</key>
                        <string />
                        <key>foreground</key>
                        <string>#F92672</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Tag attribute</string>
                    <key>scope</key>
                    <string>entity.other.attribute-name</string>
                    <key>settings</key>
                    <dict>
                        <key>fontStyle</key>
                        <string />
                        <key>foreground</key>
                        <string>#A6E22E</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Library function</string>
                    <key>scope</key>
                    <string>support.function</string>
                    <key>settings</key>
                    <dict>
                        <key>fontStyle</key>
                        <string />
                        <key>foreground</key>
                        <string>#66D9EF</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Library constant</string>
                    <key>scope</key>
                    <string>support.constant</string>
                    <key>settings</key>
                    <dict>
                        <key>fontStyle</key>
                        <string />
                        <key>foreground</key>
                        <string>#66D9EF</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Library class/type</string>
                    <key>scope</key>
                    <string>support.type, support.class</string>
                    <key>settings</key>
                    <dict>
                        <key>fontStyle</key>
                        <string>italic</string>
                        <key>foreground</key>
                        <string>#66D9EF</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Library variable</string>
                    <key>scope</key>
                    <string>support.other.variable</string>
                    <key>settings</key>
                    <dict>
                        <key>fontStyle</key>
                        <string />
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Invalid</string>
                    <key>scope</key>
                    <string>invalid</string>
                    <key>settings</key>
                    <dict>
                        <key>background</key>
                        <string>#F92672</string>
                        <key>fontStyle</key>
                        <string />
                        <key>foreground</key>
                        <string>#F8F8F0</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>Invalid deprecated</string>
                    <key>scope</key>
                    <string>invalid.deprecated</string>
                    <key>settings</key>
                    <dict>
                        <key>background</key>
                        <string>#AE81FF</string>
                        <key>foreground</key>
                        <string>#F8F8F0</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>JSON String</string>
                    <key>scope</key>
                    <string>meta.structure.dictionary.json string.quoted.double.json</string>
                    <key>settings</key>
                    <dict>
                        <key>foreground</key>
                        <string>#CFCFC2</string>
                    </dict>
                </dict>
    
                <dict>
                    <key>name</key>
                    <string>diff.header</string>
                    <key>scope</key>
                    <string>meta.diff, meta.diff.header</string>
                    <key>settings</key>
                    <dict>
                        <key>foreground</key>
                        <string>#75715E</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>diff.deleted</string>
                    <key>scope</key>
                    <string>markup.deleted</string>
                    <key>settings</key>
                    <dict>
                        <key>foreground</key>
                        <string>#F92672</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>diff.inserted</string>
                    <key>scope</key>
                    <string>markup.inserted</string>
                    <key>settings</key>
                    <dict>
                        <key>foreground</key>
                        <string>#A6E22E</string>
                    </dict>
                </dict>
                <dict>
                    <key>name</key>
                    <string>diff.changed</string>
                    <key>scope</key>
                    <string>markup.changed</string>
                    <key>settings</key>
                    <dict>
                        <key>foreground</key>
                        <string>#E6DB74</string>
                    </dict>
                </dict>
    
                <dict>
                    <key>scope</key>
                    <string>constant.numeric.line-number.find-in-files - match</string>
                    <key>settings</key>
                    <dict>
                        <key>foreground</key>
                        <string>#AE81FFA0</string>
                    </dict>
                </dict>
                <dict>
                    <key>scope</key>
                    <string>entity.name.filename</string>
                    <key>settings</key>
                    <dict>
                        <key>foreground</key>
                        <string>#E6DB74</string>
                    </dict>
                </dict>
    
                <dict>
                    <key>scope</key>
                    <string>message.error</string>
                    <key>settings</key>
                    <dict>
                        <key>foreground</key>
                        <string>#F83333</string>
                    </dict>
                </dict>
    
                <dict>
                    <key>name</key>
                    <string>SublimeLinter Error</string>
                    <key>scope</key>
                    <string>sublimelinter.mark.error</string>
                    <key>settings</key>
                    <dict>
                        <key>foreground</key>
                        <string>#D02000</string>
                    </dict>
                </dict><dict>
                <key>name</key>
                <string>SublimeLinter Gutter Mark</string>
                <key>scope</key>
                <string>sublimelinter.gutter-mark</string>
                <key>settings</key>
                <dict>
                    <key>foreground</key>
                    <string>#FFFFFF</string>
                </dict>
            </dict>
            <dict>
                <key>name</key>
                <string>SublimeLinter Warning</string>
                <key>scope</key>
                <string>sublimelinter.mark.warning</string>
                <key>settings</key>
                <dict>
                    <key>foreground</key>
                    <string>#DDB700</string>
                </dict>
            </dict>
    
    
    
            <dict>
                <key>name</key>
                <string>felix verbose</string>
                <key>scope</key>
                <string>felix.verbose</string>
                <key>settings</key>
                <dict>
                    <key>foreground</key>
                    <string>#BBBBBB</string>
                </dict>
            </dict>
            <dict>
                <key>name</key>
                <string>felix debug</string>
                <key>scope</key>
                <string>felix.debug</string>
                <key>settings</key>
                <dict>
                    <key>foreground</key>
                    <string>#0070BB</string>
                </dict>
            </dict>
            <dict>
                <key>name</key>
                <string>felix info</string>
                <key>scope</key>
                <string>felix.info</string>
                <key>settings</key>
                <dict>
                    <key>foreground</key>
                    <string>#48BB31</string>
                </dict>
            </dict>
            <dict>
                <key>name</key>
                <string>felix warn</string>
                <key>scope</key>
                <string>felix.warn</string>
                <key>settings</key>
                <dict>
                    <key>foreground</key>
                    <string>#BBBB23</string>
                </dict>
            </dict>
            <dict>
                <key>name</key>
                <string>felix error</string>
                <key>scope</key>
                <string>felix.error</string>
                <key>settings</key>
                <dict>
                    <key>foreground</key>
                    <string>#FF0006</string>
                </dict>
            </dict>
            <dict>
                <key>name</key>
                <string>felix assert</string>
                <key>scope</key>
                <string>felix.assert</string>
                <key>settings</key>
                <dict>
                    <key>foreground</key>
                    <string>#8F0005</string>
                </dict>
            </dict>
    
    
        </array>
        <key>uuid</key>
        <string>D8D5E82E-3D5B-46B5-B38E-8C841C21347D</string>
    </dict>
    </plist>
    

    相关文章

      网友评论

        本文标题:如何给logcat文件加高亮

        本文链接:https://www.haomeiwen.com/subject/opoidxtx.html