简体   繁体   English

如何使用 mqtt mosquitto 登录日志

[英]how to log to journal with mqtt mosquitto

Mosquitto has an extensive logging mechanism. Mosquitto 具有广泛的日志记录机制。 But it seems it only can log against syslog.但它似乎只能记录系统日志。

Is there a way to get logs captured in the systemd's jounal without running it as a service?有没有办法在不将其作为服务运行的情况下在 systemd 的日志中捕获日志?

Note: mosquito runs inside a docker container注意:蚊子在 docker 容器内运行

mosquitto.conf logging section is: mosquitto.conf 日志记录部分是:

    # =================================================================
    # Logging
    # =================================================================
    
    # Places to log to. Use multiple log_dest lines for multiple
    # logging destinations.
    # Possible destinations are: stdout stderr syslog topic file dlt
    #
    # stdout and stderr log to the console on the named output.
    #
    # syslog uses the userspace syslog facility which usually ends up
    # in /var/log/messages or similar.
    #
    # topic logs to the broker topic '$SYS/broker/log/<severity>',
    # where severity is one of D, E, W, N, I, M which are debug, error,
    # warning, notice, information and message. Message type severity is used by
    # the subscribe/unsubscribe log_types and publishes log messages to
    # $SYS/broker/log/M/susbcribe or $SYS/broker/log/M/unsubscribe.
    #
    # The file destination requires an additional parameter which is the file to be
    # logged to, e.g. "log_dest file /var/log/mosquitto.log". The file will be
    # closed and reopened when the broker receives a HUP signal. Only a single file
    # destination may be configured.
    #
    # The dlt destination is for the automotive `Diagnostic Log and Trace` tool.
    # This requires that Mosquitto has been compiled with DLT support.
    #
    # Note that if the broker is running as a Windows service it will default to
    # "log_dest none" and neither stdout nor stderr logging is available.
    # Use "log_dest none" if you wish to disable logging.
    log_dest syslog
    log_dest file /var/log/mosquitto/mosquitto.log
    
    # Types of messages to log. Use multiple log_type lines for logging
    # multiple types of messages.
    # Possible types are: debug, error, warning, notice, information,
    # none, subscribe, unsubscribe, websockets, all.
    # Note that debug type messages are for decoding the incoming/outgoing
    # network packets. They are not logged in "topics".
    #log_type error
    #log_type warning
    #log_type notice
    log_type all
    
    
    # If set to true, client connection and disconnection messages will be included
    # in the log.
    #connection_messages true
    
    # If using syslog logging (not on Windows), messages will be logged to the
    # "daemon" facility by default. Use the log_facility option to choose which of
    # local0 to local7 to log to instead. The option value should be an integer
    # value, e.g. "log_facility 5" to use local5.
    log_facility 5
    
    # If set to true, add a timestamp value to each log message.
    #log_timestamp true
    
    # Set the format of the log timestamp. If left unset, this is the number of
    # seconds since the Unix epoch.
    # This is a free text string which will be passed to the strftime function. To
    # get an ISO 8601 datetime, for example:
    # log_timestamp_format %Y-%m-%dT%H:%M:%S
    #log_timestamp_format
    
    # Change the websockets logging level. This is a global option, it is not
    # possible to set per listener. This is an integer that is interpreted by
    # libwebsockets as a bit mask for its lws_log_levels enum. See the
    # libwebsockets documentation for more details. "log_type websockets" must also
    # be enabled.
    #websockets_log_level 0

Because of log_dest syslog is specified, logging to syslog should be enabled, shouldn't it?因为指定了log_dest syslog ,所以应该启用记录到 syslog,不是吗?

There are logs of mosquitto in /var/log/syslog : /var/log/syslog中有 mosquitto 的日志:

    Nov 17 23:08:29 raspberrypi mosquitto[40]: 1668726509: Opening ipv6 listen socket on port 1883.
    Nov 17 23:08:29 raspberrypi mosquitto[40]: 1668726509: Opening ipv4 listen socket on port 1883.
    Nov 17 23:08:29 raspberrypi mosquitto[40]: 1668726509: Opening websockets listen socket on port 9001.
    Nov 17 23:08:29 raspberrypi mosquitto[40]: 1668726509: mosquitto version 2.0.15 running
    ...
    Nov 30 12:12:18 raspberrypi mosquitto[39]: 1669810338: Sending PUBLISH to shell (d0, q0, r0, m0, '$SYS/broker/load/bytes/sent/1min', ... (4 bytes))
    Nov 30 12:12:29 raspberrypi mosquitto[39]: 1669810349: Sending PUBLISH to shell (d0, q0, r0, m0, '$SYS/broker/load/bytes/sent/1min', ... (4 bytes))
    Nov 30 12:12:40 raspberrypi mosquitto[39]: 1669810360: Sending PUBLISH to shell (d0, q0, r0, m0, '$SYS/broker/load/bytes/sent/1min', ... (4 bytes))

But they do not end up in the journal.但它们最终不会出现在期刊中。 I suspect it is because no systemd init is running.我怀疑这是因为没有 systemd init 在运行。 Can this be worked around?这可以解决吗?

Just configure mosquitto to log to syslog and it will end up in the journal.只需将 mosquitto 配置为记录到系统日志,它就会出现在日志中。

Settings log_dest syslog should just work.设置log_dest syslog应该可以正常工作。

Edit for clarity.为清楚起见进行编辑。

This works on my Fedora 36 machine where journald appears to be consuming syslogd messages as can be seen by running journalctl -f -t mosquitto which output the usual mosquitto startup log info.这适用于我的 Fedora 36 机器,其中 journald 似乎正在使用 syslogd 消息,这可以通过运行journalctl -f -t mosquitto看到,其中 output 是通常的 mosquitto 启动日志信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 /mosquitto/data MQTT mosquitto 中存储消息? - How to store messages in /mosquitto/data MQTT mosquitto? 无法与 docker 内部的 mosquitto MQTT broker 连接 - Can not connect with mosquitto MQTT brocker inside docker Eclipse Mosquitto Docker:无法打开日志文件 /opt/mosquitto/log/mosquitto.log 进行写入 - Eclipse Mosquitto Docker: Unable to open log file /opt/mosquitto/log/mosquitto.log for writing 本地 MQTT mosquitto 实例连接 ECONNREFUSED 127.0.0.1:1883 - Local MQTT mosquitto instance getting connect ECONNREFUSED 127.0.0.1:1883 将 dockerized Spring boot 应用程序连接到 MQTT Mosquitto 代理 - Connecting dockerized Spring boot app to MQTT Mosquitto broker docker 中的 mqtt 服务器 - 一种运行<mosquitto_passwd -U>来自 DockerCompose.yaml - mqtt server in docker - a way to run the <mosquitto_passwd -U> from DockerCompose.yaml 无法使用 Node.js mqtt 库连接到 Eclipse Mosquitto 代理 - Cannot connect to Eclipse Mosquitto broker using Node.js mqtt library Paho C++ MQTT 客户端无法连接到 Ubuntu 上的 Mosquitto Docker 图片(Python 客户端工作) - Paho C++ MQTT Client unable to connect to Mosquitto on Ubuntu Docker Image (Python Client Works) 如何将 mosquitto docker 日志挂载到本地 PC - How to mount mosquitto docker logs to local pc 如何在 windows 中的 docker 上测试 mqtt? - How to test mqtt on docker in windows?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM