如何给logcat文件加高亮

使用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>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,324评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,356评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,328评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,147评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,160评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,115评论 1 296
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,025评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,867评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,307评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,528评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,688评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,409评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,001评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,657评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,811评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,685评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,573评论 2 353

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,651评论 18 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,803评论 6 342
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,070评论 25 707
  • 三毛流浪记 欣然 “三毛”,之前只是看过动画片版的、影视真人...
    yiyi_1650阅读 1,167评论 1 3
  • 在上个月份的一次使用vue的项目开发的过程中发现了一个很诡异的现象,就是我在 中写样式时发现样式突然间不起作用...
    缘自世界阅读 1,009评论 0 2