Is there any way to make the logfile more readable?

I find the default log format barely readable:


This gets even worse if you use rsyslog because backslashes are added (not sure by whom).

I understand that the format is JSON.

  1. Is there a way to store the log with JSON already formated or in a format that is readable without further formatting?
  2. Do you know any logging tools on Linux that can automatically format JSON logs?
  3. Is there any way to disable the addition of backslashes when using syslog?
1 Like

occ log:tail and occ log:watch

2 Likes

Thanks, this is a big improvement but has two disadvantages:

  1. Running occ is relatively cumbersome because I have to su to www-data and then run that script.
  2. I can’t use the same tools (vim, multitail) as for all other services.

Not tested:

cat nextcloud.log | jq

Is something I use from time to time.

2 Likes

I found a new tool lnav. This is the best solution for me so far.

# apt install lnav

$ lnav nextcloud.log

Here are some important keyboard shortcuts

? see help
g go to top of file
G go to bottom of file
P turn on pretty print, which will show JSON in a structured way

1 Like

tail -f nextcloud.log | jq | grep -i message

This is handy, thanks! I made a custom format for the default server log:

{
  "nextcloud_log": {
    "title": "Nextcloud log",
    "description": "Nextcloud JSON server log",
    "url": "https://docs.nextcloud.com/server/stable/admin_manual/configuration_server/logging_configuration.html?highlight=logging#log-field-breakdown",
    "json": true,
    "file-pattern": "nextcloud.log$",
    "opid-field": "reqId",
    "level-field": "level",
    "body-field": "message",
    "hide-extra": true,
    "level" : {
      "debug" : "0",
      "info": "1",
      "warning" : "2",
      "error" : "3",
      "fatal" : "4"
    },
    "timestamp-field": "time",
    "convert-to-local-time": true,
    "multiline": false,
    "value": {
      "exception": {
        "kind": "json"
      },
      "app": {
        "kind": "string",
        "identifier": true
      }
    },
    "line-format": [
      {
        "field": "__timestamp__",
        "timestamp-format": "%b %e %H:%M:%S"
      },
      " ",
      {
        "field": "__level__",
        "text-transform": "uppercase"
      },
      " ",
      {
        "field": "app"
      },
      " ",
      {
        "field": "message"
      }
    ]
  }
}

If you save that to a local file named nextcloud.json you can install it with lnav -i nextcloud.json.