Logs

Logs provide a reliable source of information for troubleshooting and system performance optimization. You can find the record about the access, operating, or network issues from EMQX logs.

EMQX log has 8 levels, with warning as the default level, from low to high these 8 levels are:

  1. debug < info < notice < warning < error < critical < alert < emergency

You can configure EMQX logs with Dashboard or configuration files. To configure with EMQX Dashboard, you can click Management -> Log on the left navigation menu to configure.

TIP

Most configuration items listed here also can be configured with Dashboard, and their Dashboard UI fields are also introduced on this page. Once you configured these items with the Dashboard, your settings will override the same configuration items in emqx.conf.

This section introduces how to configure logs with configuration items. For example, if you want to export the logs of warning levels as both a file and output with a console, you can work with the following configuration items.

  1. log {
  2. file_handlers.default {
  3. level = warning
  4. file = "log/emqx.log"
  5. count = 10
  6. max_size = 50MB
  7. formatter = text
  8. }
  9. console_handler {
  10. level = warning
  11. formatter = text
  12. }
  13. }

Output Logs as a File

To output logs as a file, you can work with the command below:

Code example:

  1. log {
  2. file_handlers.default {
  3. level = warning
  4. file = "log/emqx.log"
  5. count = 10
  6. max_size = 50MB
  7. formatter = text
  8. }

Where,

Configuration ItemDashboard UIDescriptionDefault ValueOptional Values
file_handlers.defaultFile HandlerThis sets whether to enable using the file-based log handler for logging purposes, once enabled, it will write the log messages to a specified file on the disk (configured by file).enabledenable, disable
levelLog LevelThis sets the log level of the current log handler, that is, the minimum log level you want to record.warningdebug, info, notice, warning, error, critical, alert, emergency
fileLog File NameThis sets the name of the log file,
By default, EMQX writes the log file to the emqx.log file in the log directory of the EMQX installation directory.
emqx.log
countMax Log Files NumberThis sets the max number of log files that can be saved.101 ~ 2,048
max_sizeRotation SizeThis sets the maximum size of a single log file before it is rotated. The old log file will be renamed and moved to an archive directory once it reached the specified value unless it is set to infinity, indicating the log file will not be rotated.50MB1 ~ infinity
formattedLog FormatterThis sets the log format.texttext for free text
json for structured logging

Output log with Console

You can also use the command below to configure the logs with the console:

  1. log {
  2. console_handler {
  3. level = warning
  4. formatter = text
  5. }
  6. }

Where,

Configuration ItemDashboard UIDescriptionDefault ValueOptional Values
file_handlers.defaultEnable Log HandlerThis sets whether to enable outputting logs with the console.enabledenable, disable
levelLog LevelThis sets the log level of the current log handler, that is, the minimum log level you want to record.warningdebug, info, notice, warning, error, critical, alert, emergency
formattedLog FormatterThis sets the log formattexttext for free text
json for structured logging

TIP

To configure listeners via Dashboard, click Configuration -> Log on the left navigation menu of the Dashboard. Once you configured these items with the Dashboard, your settings will override the same configuration items in emqx.conf.

EMQX has offered more configuration items to better serve customized needs, you can continue to read Configuration Manual.