Cisco

Cisco IOS:僅在命令行上記錄調試消息

  • November 5, 2014

我想要一個安靜的命令行,例如(config)# no logging console原因。不過,我想使用# debug命令。在我看來,這# debug取決於系統日誌級別 7。所以我不能有一個安靜的 CLI 並同時閱讀調試消息​​。

有解決方法嗎?

Host(config)#logging ?
 Hostname or A.B.C.D  IP address of the logging host
 buffered             Set buffered logging parameters
 buginf               Enable buginf logging for debugging
 cns-events           Set CNS Event logging level
 console              Set console logging parameters
 count                Count every log message and timestamp last occurrence
 discriminator        Create or modify a message discriminator
 dmvpn                DMVPN Configuration
 esm                  Set ESM filter restrictions
 exception            Limit size of exception flush output
 facility             Facility parameter for syslog messages
 filter               Specify logging filter
 history              Configure syslog history table
 host                 Set syslog server IP address and parameters
 message-counter      Configure log message to include certain counter value 
 monitor              Set terminal line (monitor) logging parameters
 on                   Enable logging to all enabled destinations
 origin-id            Add origin ID to syslog messages
 persistent           Set persistent logging parameters
 queue-limit          Set logger message queue size
 rate-limit           Set messages per second limit
 reload               Set reload logging level
 server-arp           Enable sending ARP requests for syslog servers when first configured
 source-interface     Specify interface for source address in logging transactions
 trap                 Set syslog server logging level
 userinfo             Enable logging of user info on privileged mode enabling

Host(config)#logging console ?
 <0-7>          Logging severity level
 alerts         Immediate action needed           (severity=1)
 critical       Critical conditions               (severity=2)
 debugging      Debugging messages                (severity=7)
 discriminator  Establish MD-Console association
 emergencies    System is unusable                (severity=0)
 errors         Error conditions                  (severity=3)
 filtered       Enable filtered logging
 guaranteed     Guarantee console messages
 informational  Informational messages            (severity=6)
 notifications  Normal but significant conditions (severity=5)
 warnings       Warning conditions                (severity=4)
 xml            Enable logging in XML
 <cr>

使用cpt_fink解決方案的範例:

之後logging console criticallogging buffered 64000 debug之後:clear log_Host

Host#show log
Syslog logging: enabled (12 messages dropped, 0 messages rate-limited,
               0 flushes, 0 overruns, xml disabled, filtering disabled)

No Active Message Discriminator.



No Inactive Message Discriminator.


   Console logging: level critical, 20 messages logged, xml disabled,
                    filtering disabled
   Monitor logging: level debugging, 0 messages logged, xml disabled,
                    filtering disabled
   Buffer logging:  level debugging, 4 messages logged, xml disabled,
                    filtering disabled
   Logging Exception size (4096 bytes)
   Count and timestamp logging messages: disabled
   Persistent logging: disabled

No active filter modules.

ESM: 0 messages dropped

   Trap logging: level informational, 36 message lines logged

Log Buffer (64000 bytes):
Host#
Host#
Host#debug ip icmp
ICMP packet debugging is on
Host#
Host#
Host#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Host(config)#   
Host(config)#interface fastethernet0/1
Host(config-if)#
Host(config-if)#ip address 192.168.0.1 255.255.255.0
Host(config-if)#
Host(config-if)#no shut
Host(config-if)#end
Host#
Host#
Host#show log
Syslog logging: enabled (12 messages dropped, 0 messages rate-limited,
               0 flushes, 0 overruns, xml disabled, filtering disabled)

No Active Message Discriminator.



No Inactive Message Discriminator.


   Console logging: level critical, 20 messages logged, xml disabled,
                    filtering disabled
   Monitor logging: level debugging, 0 messages logged, xml disabled,
                    filtering disabled
   Buffer logging:  level debugging, 5 messages logged, xml disabled,
                    filtering disabled
   Logging Exception size (4096 bytes)
   Count and timestamp logging messages: disabled
   Persistent logging: disabled

No active filter modules.

ESM: 0 messages dropped

   Trap logging: level informational, 37 message lines logged

Log Buffer (64000 bytes):

Nov  4 18:03:05.551: %SYS-5-CONFIG_I: Configured from console by console
Host#

讓我們觸發一個 ICMP 調試消息。

Host_2#ping 192.168.0.1 repeat 1

Type escape sequence to abort.
Sending 1, 100-byte ICMP Echos to 192.168.0.1, timeout is 2 seconds:
.
Success rate is 0 percent (0/1)
Host_2#
Host_2#
Host_2#ping 192.168.0.1 repeat 1

Type escape sequence to abort.
Sending 1, 100-byte ICMP Echos to 192.168.0.1, timeout is 2 seconds:
!
Success rate is 100 percent (1/1), round-trip min/avg/max = 12/12/12 ms
Host_2#

讓我們查找系統日誌:

Host#show log
Syslog logging: enabled (12 messages dropped, 0 messages rate-limited,
               0 flushes, 0 overruns, xml disabled, filtering disabled)

No Active Message Discriminator.



No Inactive Message Discriminator.


   Console logging: level critical, 20 messages logged, xml disabled,
                    filtering disabled
   Monitor logging: level debugging, 0 messages logged, xml disabled,
                    filtering disabled
   Buffer logging:  level debugging, 6 messages logged, xml disabled,
                    filtering disabled
   Logging Exception size (4096 bytes)
   Count and timestamp logging messages: disabled
   Persistent logging: disabled

No active filter modules.

ESM: 0 messages dropped

   Trap logging: level informational, 37 message lines logged

Log Buffer (64000 bytes):

Nov  4 18:03:05.551: %SYS-5-CONFIG_I: Configured from console by console
Nov  4 18:04:47.527: ICMP: echo reply sent, src 192.168.0.1, dst 192.168.0.2
Host#

讓我們發出通常會導致煩人消息的命令:

Host#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Host(config)#
Host(config)#interface fastethernet0/0
Host(config-if)#
Host(config-if)#shut
Host(config-if)#
Host(config-if)#exit
Host(config)#
Host(config)#
Host(config)#interface fastethernet0/1
Host(config-if)#
Host(config-if)#shut
Host(config-if)#    
Host(config-if)#exit
Host(config)#
Host(config)#end
Host#

讓我們查找系統日誌:

Host#show log
Syslog logging: enabled (12 messages dropped, 0 messages rate-limited,
               0 flushes, 0 overruns, xml disabled, filtering disabled)

No Active Message Discriminator.



No Inactive Message Discriminator.


   Console logging: level critical, 20 messages logged, xml disabled,
                    filtering disabled
   Monitor logging: level debugging, 0 messages logged, xml disabled,
                    filtering disabled
   Buffer logging:  level debugging, 11 messages logged, xml disabled,
                    filtering disabled
   Logging Exception size (4096 bytes)
   Count and timestamp logging messages: disabled
   Persistent logging: disabled

No active filter modules.

ESM: 0 messages dropped

Trap logging: level informational, 42 message lines logged

Log Buffer (64000 bytes):

Nov  4 18:03:05.551: %SYS-5-CONFIG_I: Configured from console by console
Nov  4 18:04:47.527: ICMP: echo reply sent, src 192.168.0.1, dst 192.168.0.2
Nov  4 18:11:57.371: %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to administratively down
Nov  4 18:11:58.371: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to down
Nov  4 18:12:07.619: %LINK-5-CHANGED: Interface FastEthernet0/1, changed state to administratively down
Nov  4 18:12:08.619: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1,     changed state to down
Nov  4 18:12:36.111: %SYS-5-CONFIG_I: Configured from console by console
Host#
  • 我喜歡什麼:我可以在 CLI 上工作而不會中斷。
  • 我不喜歡的:我仍然收到未記錄的消息debug ip icmp

使用cpt_fink的解決方案標記為正確答案的範例:

配置:

Router_1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router_1(config)#
Router_1(config)#logging console
Router_1(config)#
Router_1(config)#logging console critical
Router_1(config)#
Router_1(config)#logging buffered 64000 debug
Router_1(config)#
Router_1(config)#do clock set 07:29:30 5 november 2014
Router_1(config)#
Router_1(config)#end
Router_1#
Router_1#debug ip icmp
ICMP packet debugging is on
Router_1#

讓我們創建至少一條消息:

Router_2#ping 192.168.0.1 repeat 2

Type escape sequence to abort.
Sending 2, 100-byte ICMP Echos to 192.168.0.1, timeout is 2 seconds:
!!
Success rate is 100 percent (2/2), round-trip min/avg/max = 4/4/4 ms
Router_2#

讓我們查找系統日誌:

Router_1#show logging | include ICMP
Nov  5 07:30:05.463: ICMP: echo reply sent, src 192.168.0.1, dst 192.168.0.2
Nov  5 07:30:05.467: ICMP: echo reply sent, src 192.168.0.1, dst 192.168.0.2
Router_1#

讓我們挑起更多消息:

Router_2#ping 192.168.0.1 repeat 11

Type escape sequence to abort.
Sending 11, 100-byte ICMP Echos to 192.168.0.1, timeout is 2 seconds:
!!!!!!!!!!!
Success rate is 100 percent (11/11), round-trip min/avg/max = 4/4/4 ms
Router_2#

讓我們查找系統日誌:

Router_1#show logging | include ICMP
Nov  5 07:30:05.463: ICMP: echo reply sent, src 192.168.0.1, dst 192.168.0.2
Nov  5 07:30:05.467: ICMP: echo reply sent, src 192.168.0.1, dst 192.168.0.2
Nov  5 07:32:24.807: ICMP: echo reply sent, src 192.168.0.1, dst 192.168.0.2
Nov  5 07:32:24.811: ICMP: echo reply sent, src 192.168.0.1, dst 192.168.0.2
Nov  5 07:32:24.815: ICMP: echo reply sent, src 192.168.0.1, dst 192.168.0.2
Nov  5 07:32:24.819: ICMP: echo reply sent, src 192.168.0.1, dst 192.168.0.2
Nov  5 07:32:24.823: ICMP: echo reply sent, src 192.168.0.1, dst 192.168.0.2
Nov  5 07:32:24.827: ICMP: echo reply sent, src 192.168.0.1, dst 192.168.0.2
Nov  5 07:32:24.831: ICMP: echo reply sent, src 192.168.0.1, dst 192.168.0.2
Nov  5 07:32:24.835: ICMP: echo reply sent, src 192.168.0.1, dst 192.168.0.2
Nov  5 07:32:24.839: ICMP: echo reply sent, src 192.168.0.1, dst 192.168.0.2
Nov  5 07:32:24.843: ICMP: echo reply sent, src 192.168.0.1, dst 192.168.0.2
Nov  5 07:32:24.847: ICMP: echo reply sent, src 192.168.0.1, dst 192.168.0.2
Router_1#

我建議您使用該命令查看歷史輸出,logging console critical而不會用消息阻塞低速物理控制台,同時仍會在控制台上接收關鍵或更高級別的消息。logging buffered 64000 debug``sho log

在使用日誌緩衝區時,正確設置系統時間(使用 NTP 或clock set ...來自 exec)和時區/夏令時clock timezone XXX -#以及clock summer-time XXX recurring使用 service timestamps log datetime local msservice timestamps debug date local ms命令在輸出消息時標記消息也很有用。

作為旁注terminal monitor(並terminal no monitor禁用它)是一種在遠端連接時立即獲得輸出的方法。您可以將 設置logging monitor [level]為包含調試或僅包含更高重要性的消息。

引用自:https://serverfault.com/questions/641919