【notepad++】log日志文件高亮

文章介绍了如何在Notepad++中自定义Ansible输出的日志颜色,通过编辑XML配置文件来改变不同类型的错误和警告的颜色显示,以提高可读性和调试效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

自定义文件路径

  • C:\Users\zhangbin\AppData\Roaming\Notepad++\userDefineLangs
    在这里插入图片描述

先改背景: 设置==》语言格式设置

在这里插入图片描述

效果

在这里插入图片描述

XML 文件

<NotepadPlus>
    <UserLang name="Ansible" ext="" udlVersion="2.1">
        <Settings>
            <Global caseIgnored="no" allowFoldOfComments="no" foldCompact="no" forcePureLC="0" decimalSeparator="0" />
            <Prefix Keywords1="yes" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="no" Keywords8="no" />
        </Settings>
        <KeywordLists>
            <Keywords name="Comments">00failed: 00fatal: 00FAILED! 00ERROR 00Traceback 00ArithmeticError 00AssertionError 00AttributeError 00BaseException 00BlockingIOError 00BrokenPipeError 00BufferError 00ChildProcessError 00ConnectionAbortedError 00ConnectionError 00ConnectionRefusedError 00ConnectionResetError 00EOFError 00EnvironmentError 00Exception 00FileExistsError 00FileNotFoundError 00FloatingPointError 00GeneratorExit 00IOError 00ImportError 00IndentationError 00IndexError 00InterruptedError 00IsADirectoryError 00KeyError 00KeyboardInterrupt 00LookupError 00MemoryError 00ModuleNotFoundError 00NameError 00NotADirectoryError 00NotImplemented 00NotImplementedError 00OSError 00OverflowError 00PermissionError 00ProcessLookupError 00RecursionError 00ReferenceError 00RuntimeError 00StopAsyncIteration 00StopIteration 00SyntaxError 00SystemError 00SystemExit 00TabError 00TimeoutError 00TypeError 00UnboundLocalError 00UnicodeDecodeError 00UnicodeEncodeError 00UnicodeError 00UnicodeTranslateError 00ValueError 00WindowsError 00ZeroDivisionError 01 02 03Warning 04&#x000A;</Keywords>
            <Keywords name="Numbers, prefix1"></Keywords>
            <Keywords name="Numbers, prefix2"></Keywords>
            <Keywords name="Numbers, extras1"></Keywords>
            <Keywords name="Numbers, extras2"></Keywords>
            <Keywords name="Numbers, suffix1"></Keywords>
            <Keywords name="Numbers, suffix2"></Keywords>
            <Keywords name="Numbers, range"></Keywords>
            <Keywords name="Operators1"></Keywords>
            <Keywords name="Operators2"></Keywords>
            <Keywords name="Folders in code1, open"></Keywords>
            <Keywords name="Folders in code1, middle"></Keywords>
            <Keywords name="Folders in code1, close"></Keywords>
            <Keywords name="Folders in code2, open"></Keywords>
            <Keywords name="Folders in code2, middle"></Keywords>
            <Keywords name="Folders in code2, close"></Keywords>
            <Keywords name="Folders in comment, open"></Keywords>
            <Keywords name="Folders in comment, middle"></Keywords>
            <Keywords name="Folders in comment, close"></Keywords>
            <Keywords name="Keywords1">WARN</Keywords>
            <Keywords name="Keywords2">...ignoring skipped</Keywords>
            <Keywords name="Keywords3"></Keywords>
            <Keywords name="Keywords4"></Keywords>
            <Keywords name="Keywords5"></Keywords>
            <Keywords name="Keywords6"></Keywords>
            <Keywords name="Keywords7"></Keywords>
            <Keywords name="Keywords8"></Keywords>
            <Keywords name="Delimiters">00INFO 01 02&#x000A; 03DEBUG 04 05&#x000A; 06WARN 07 08&#x000A; 09FAILED 10 11&#x000A; 12 13 14 15 16 17 18 19 20 21 22 23</Keywords>
        </KeywordLists>
        <Styles>
            <WordsStyle name="DEFAULT" fgColor="000000" bgColor="FFFFFF" colorStyle="0" fontStyle="0" nesting="0" />
            <WordsStyle name="COMMENTS" fgColor="FF80FF" bgColor="FFFFFF" colorStyle="1" fontStyle="0" nesting="0" />
            <WordsStyle name="LINE COMMENTS" fgColor="FF0000" bgColor="FFFFFF" colorStyle="1" fontStyle="0" nesting="0" />
            <WordsStyle name="NUMBERS" fgColor="000000" bgColor="FFFFFF" colorStyle="0" fontStyle="0" nesting="0" />
            <WordsStyle name="KEYWORDS1" fgColor="0080FF" bgColor="FFFFFF" colorStyle="1" fontStyle="0" nesting="0" />
            <WordsStyle name="KEYWORDS2" fgColor="00FFFF" bgColor="FFFFFF" colorStyle="1" fontStyle="0" nesting="0" />
            <WordsStyle name="KEYWORDS3" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
            <WordsStyle name="KEYWORDS4" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
            <WordsStyle name="KEYWORDS5" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
            <WordsStyle name="KEYWORDS6" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
            <WordsStyle name="KEYWORDS7" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
            <WordsStyle name="KEYWORDS8" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
            <WordsStyle name="OPERATORS" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
            <WordsStyle name="FOLDER IN CODE1" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
            <WordsStyle name="FOLDER IN CODE2" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
            <WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
            <WordsStyle name="DELIMITERS1" fgColor="00C800" bgColor="FFFFFF" colorStyle="1" fontStyle="0" nesting="0" />
            <WordsStyle name="DELIMITERS2" fgColor="FF8000" bgColor="FFFFFF" colorStyle="1" fontStyle="0" nesting="0" />
            <WordsStyle name="DELIMITERS3" fgColor="000000" bgColor="FFFFFF" colorStyle="1" fontStyle="0" nesting="0" />
            <WordsStyle name="DELIMITERS4" fgColor="808080" bgColor="FFFFFF" colorStyle="1" fontStyle="0" nesting="0" />
            <WordsStyle name="DELIMITERS5" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
            <WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
            <WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
            <WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
        </Styles>
    </UserLang>
</NotepadPlus>

### 设置日志文件中的关键字高亮显示 为了在Notepad++中实现日志文件的关键字高亮显示,可以通过自定义语言来完成这一需求。具体操作方法如下: #### 定义新的用户语言 进入`语言(L)`菜单并选择`定义自己的语言(U)...`[^1]。 在此界面中,可以配置不同类型的词法元素,如关键字、注释、函数等,并为其指定颜色和其他样式属性。对于日志级别的关键词(例如DEBUG, INFO, WARN, ERROR),可以在“Keywords lists”标签页下的相应类别里输入这些术语[^2]。 #### 使用现有XML配置简化过程 考虑到手动设置可能较为繁琐,也可以利用已有的社区资源。有开发者分享了适用于特定格式的日志文件的User Defined Language XML文件[^3]。下载合适的模板后,在Notepad++中通过导入功能加载此XML文件即可快速应用预设的语法高亮规则。 ```xml <UserDefinedLang> <Name>Logfile</Name> <!-- Define your keyword groups here --> <KeywordLists> <Keywords name="Primary Keywords and Identifiers">DEBUG INFO WARN ERROR FATAL</Keywords> ... </KeywordLists> <!-- Other settings such as styles can be added below --> </UserDefinedLang> ``` 上述代码片段展示了如何在一个简单的User Defined Language定义中加入常见的日志级别作为关键字列表的一部分。实际使用的XML可能会更复杂一些,取决于具体的日志格式和个人偏好。 #### 应用与验证 一旦完成了新语言的定义或成功导入了一个现成的语言包之后,打开目标日志文件时只需从下拉菜单中切换至刚刚创建/导入的语言模式,就能看到预期的效果——即重要的信息被突出显示出来,便于阅读分析。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

等风来不如迎风去

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值