SecureCRT导出操作日志 + Notepad自定义语言格式高亮日志文件
起因及效果展示
最近使用CRT,有些命令会输出很多内容,这时如果你想要得知输出内容是从哪里开始的,很容易被大量的同种颜色的文字搞的晕头转向。如果输入的命令是不同的颜色,这会大大得帮助我们。
所谓的命令行有不同颜色的高亮效果,如下图的效果。但是这种效果CRT软件是做不到的。因为CRT软件可以设置高亮的部分不包含命令行。
为了获得这种效果,我设置CRT导出为扩展名为.crtlog的日志文件,然后为Notepad++自定义了一种语言格式,每当用NotePad++打开.crtlog文件时,就自动采用这种格式来高亮文本。具体的效果如下:
上图红色辅助线框起来的是一次连接的日志内容,可以使用了折叠的效果将其折叠起来。这样我们就能记录下所有的日志信息,并且不用担心日志文件难以阅读。
CRT导出日志的设置
点击 选项>>全局选项>>默认会话>>编辑默认设置>>日志文件。具体设置内容如下
其中”半夜时启用新日志“勾选后表示这一天之内的所有日志只会记录到同一个文件下。”追加到文件“选择后代表今天产生新的日志只会追加输出到同一个文件下。
“自定义日志数据“设置的”连接时”和”断开时”的内容是为了方便代码的折叠所配置的。这里就不具体解释了。
输出内容可以引用一些变量,这些变量的具体解释如下:
%H |
Hostname,主机名,其实也就是每个连接的IP地址,比如192.168.1.1 |
%S |
session name,会话名,如下图,即便签上显示的名称 |
%Y |
four-digit year,四位数字代表的年份。 |
%M |
two-digit month,两位数字代表的月份,如果是2月就是02。 |
%D |
two-digit day of the month,两位数字代表的天。 |
%h |
two-digit hour,两位数字代表的小时。 |
%m |
two-digit minute,两位数字代表的分。 |
%s |
two-digit seconds,两位数字代表的秒。 |
%t |
three-digit milliseconds,三位数字代表的毫秒。 |
保存的文件名称结果如下
NotePad++为日志文件自定义的语言格式
具体的xml代码参考末尾,这里先说一下如何配置。首先新建一个名为crtlog.xml的文本文件,用notepad打开后,将文末的代码粘贴进去,保存并关闭该文件。
然后在NotePad的界面依次选择 语言>>自定义语言格式,在弹出的界面中点击导入,选择crtlog.xml文件。如果能在该界面中的”自定义语言”下拉框中看到crtlog就表示导入成功了。
重启NotePad++,你会在”语言”下拉菜单的导数第二行多了一个crtlog,每当你打开扩展名为crtlog的文件时就会自动应用。(如果第一次打开crtlog文件没有应用该语言格式,可以手动点击一下,之后应该就会自动应用。)
crtlog.xml文件的具体内容
<NotepadPlus> <UserLang name="crtlog" ext="crtlog" udlVersion="2.1"> <Settings> <Global caseIgnored="yes" allowFoldOfComments="yes" foldCompact="no" forcePureLC="1" decimalSeparator="0" /> <Prefix Keywords1="yes" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="no" Keywords8="no" /> </Settings> <KeywordLists> <Keywords name="Comments">00[ 01 02 03{---Connected----} 04{---Disconnect---}</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">{---Connected----}</Keywords> <Keywords name="Keywords2"></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">00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23</Keywords> </KeywordLists> <Styles> <WordsStyle name="DEFAULT" fgColor="000000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="0" nesting="0" /> <WordsStyle name="COMMENTS" fgColor="000000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="0" nesting="512" /> <WordsStyle name="LINE COMMENTS" fgColor="FF8000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="1" nesting="0" /> <WordsStyle name="NUMBERS" fgColor="000000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS1" fgColor="FF0000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="5" nesting="0" /> <WordsStyle name="KEYWORDS2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS3" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="OPERATORS" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="FOLDER IN CODE1" fgColor="FF8040" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="0" nesting="0" /> <WordsStyle name="FOLDER IN CODE2" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS1" fgColor="FF0000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="1" nesting="0" /> <WordsStyle name="DELIMITERS2" fgColor="FF8000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="1" nesting="0" /> <WordsStyle name="DELIMITERS3" fgColor="FF0000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="1" nesting="0" /> <WordsStyle name="DELIMITERS4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> </Styles> </UserLang> </NotepadPlus>