1、在mosquitto.conf文件中插入:
#把日志信息输入到指定文件 log_dest file /MosquittoTest/DisSunLog_1.log #在控制台输出信息,运行win服务无效 log_dest stdout #不记录 #log_type none #########下面的debug、error、warning.....等等可以组合使用。 #记录网络通信包,通信包大小(含心跳包),但不显示内容 log_type debug #错误信息(没见过) log_type error #警告信息(没见过) log_type warning #设备的订阅信息、发布信息及下线信息(端口、设备名、用户、不包发布内容) log_type notice #服务启动关闭信息、版本号、端口号、配置文件信息 log_type information #所有设备订阅主题提醒 log_type subscribe #这个没有试出来干啥用的(没见过) #log_type unsubscribe #websockets链接信息(没见过) #log_type websockets #websockets_log_level 0
3、然后重启服务,我们发一条信息来看看记录了什么。
4、按Ctrl+C 停止主服务,如果不停止服务,日志文件会被独占锁住无法打开。找到这个日志
5、日志解析
##########:以下是information信息 1552112775: mosquitto version 1.5.8 starting 1552112775: Config loaded from mosquitto.conf. 1552112775: Opening ipv6 listen socket on port 1883. 1552112775: Opening ipv4 listen socket on port 1883. ##########:以下是subscribe信息(伪造) 1552113940: mosqsub|11332-DisSunPad 0 'dissun/topic' 20-DisSunPad (c1, k60, u'dissun'). ##########:以下是notice信息,订阅客户端上线11332 1552112782: New connection from ::1 on port 1883. 1552112782: New client connected from ::1 as mosqsub|11332-DisSunPad (c1, k60, u'dissun'). ##########:以下是debug信息,订阅客户端上线11332 1552112782: No will message specified. 1552112782: Sending CONNACK to mosqsub|11332-DisSunPad (0, 0) 1552112782: Received SUBSCRIBE from mosqsub|11332-DisSunPad 1552112782: 'dissun/topic' (QoS 0) 1552112782: mosqsub|11332-DisSunPad 0 'dissun/topic' 1552112782: Sending SUBACK to mosqsub|11332-DisSunPad ##########:以下是notice信息,发布客户端上线12284 1552112832: New connection from ::1 on port 1883. 1552112832: New client connected from ::1 as mosqpub|12284-DisSunPad (c1, k60, u'dissun'). ##########:以下是debug信息,发布客户端上线12284,并发布12字节的信息,然后离线。 1552112832: No will message specified. 1552112832: Sending CONNACK to mosqpub|12284-DisSunPad (0, 0) 1552112832: Received PUBLISH from mosqpub|12284-DisSunPad (d0, q0, r0, m0, ''dissun/topic'', ... (12 bytes)) 1552112832: Sending PUBLISH to mosqsub|11332-DisSunPad (d0, q0, r0, m0, ''dissun/topic'', ... (12 bytes)) 1552112832: Received DISCONNECT from mosqpub|12284-DisSunPad ##########:以下是notice信息,发布客户端离线12284 1552112832: Client mosqpub|12284-DisSunPad disconnected. ##########:以下是debug信息,订阅客户端保持跟mosquitto的联系。PINGREQ请求心跳包,PINGRESP回应心跳包 1552112842: Received PINGREQ from mosqsub|11332-DisSunPad 1552112842: Sending PINGRESP to mosqsub|11332-DisSunPad 1552112902: Received PINGREQ from mosqsub|11332-DisSunPad 1552112902: Sending PINGRESP to mosqsub|11332-DisSunPad 1552112962: Received PINGREQ from mosqsub|11332-DisSunPad ##########:以下是information信息 主服务中断 1552113191: mosquitto version 1.5.8 terminating