[經驗分享]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文件的具體內容

 1 <NotepadPlus>
 2     <UserLang name="crtlog" ext="crtlog" udlVersion="2.1">
 3         <Settings>
 4             <Global caseIgnored="yes" allowFoldOfComments="yes" foldCompact="no" forcePureLC="1" decimalSeparator="0" />
 5             <Prefix Keywords1="yes" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="no" Keywords8="no" />
 6         </Settings>
 7         <KeywordLists>
 8             <Keywords name="Comments">00[ 01 02 03{---Connected----} 04{---Disconnect---}</Keywords>
 9             <Keywords name="Numbers, prefix1"></Keywords>
10             <Keywords name="Numbers, prefix2"></Keywords>
11             <Keywords name="Numbers, extras1"></Keywords>
12             <Keywords name="Numbers, extras2"></Keywords>
13             <Keywords name="Numbers, suffix1"></Keywords>
14             <Keywords name="Numbers, suffix2"></Keywords>
15             <Keywords name="Numbers, range"></Keywords>
16             <Keywords name="Operators1"></Keywords>
17             <Keywords name="Operators2"></Keywords>
18             <Keywords name="Folders in code1, open"></Keywords>
19             <Keywords name="Folders in code1, middle"></Keywords>
20             <Keywords name="Folders in code1, close"></Keywords>
21             <Keywords name="Folders in code2, open"></Keywords>
22             <Keywords name="Folders in code2, middle"></Keywords>
23             <Keywords name="Folders in code2, close"></Keywords>
24             <Keywords name="Folders in comment, open"></Keywords>
25             <Keywords name="Folders in comment, middle"></Keywords>
26             <Keywords name="Folders in comment, close"></Keywords>
27             <Keywords name="Keywords1">{---Connected----}</Keywords>
28             <Keywords name="Keywords2"></Keywords>
29             <Keywords name="Keywords3"></Keywords>
30             <Keywords name="Keywords4"></Keywords>
31             <Keywords name="Keywords5"></Keywords>
32             <Keywords name="Keywords6"></Keywords>
33             <Keywords name="Keywords7"></Keywords>
34             <Keywords name="Keywords8"></Keywords>
35             <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>
36         </KeywordLists>
37         <Styles>
38             <WordsStyle name="DEFAULT" fgColor="000000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="0" nesting="0" />
39             <WordsStyle name="COMMENTS" fgColor="000000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="0" nesting="512" />
40             <WordsStyle name="LINE COMMENTS" fgColor="FF8000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="1" nesting="0" />
41             <WordsStyle name="NUMBERS" fgColor="000000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="0" nesting="0" />
42             <WordsStyle name="KEYWORDS1" fgColor="FF0000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="5" nesting="0" />
43             <WordsStyle name="KEYWORDS2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
44             <WordsStyle name="KEYWORDS3" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
45             <WordsStyle name="KEYWORDS4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
46             <WordsStyle name="KEYWORDS5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
47             <WordsStyle name="KEYWORDS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
48             <WordsStyle name="KEYWORDS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
49             <WordsStyle name="KEYWORDS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
50             <WordsStyle name="OPERATORS" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
51             <WordsStyle name="FOLDER IN CODE1" fgColor="FF8040" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="0" nesting="0" />
52             <WordsStyle name="FOLDER IN CODE2" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
53             <WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="0" nesting="0" />
54             <WordsStyle name="DELIMITERS1" fgColor="FF0000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="1" nesting="0" />
55             <WordsStyle name="DELIMITERS2" fgColor="FF8000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="1" nesting="0" />
56             <WordsStyle name="DELIMITERS3" fgColor="FF0000" bgColor="FFFFFF" fontName="Lucida Console" fontStyle="1" nesting="0" />
57             <WordsStyle name="DELIMITERS4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
58             <WordsStyle name="DELIMITERS5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
59             <WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
60             <WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
61             <WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
62         </Styles>
63     </UserLang>
64 </NotepadPlus>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM