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

2 Likes

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. Even better, commit it to source control, then pass the repo link to lnav -i.

Update 2023-04-11: here’s a better one. It handles all Nextcloud server logs, and tracks “operation id” so you can use o and O to navigate between log lines caused by the same request.

1 Like

Good news for lnav users: Nextcloud server-side log support should be shipped in the next release.

https://github.com/tstack/lnav/pull/1197

2 Likes

If anyone is interested I have an AWK script:

#	OwnCloudLogAnal [controls] file
#
#	Controls:
#		start=<number>	The record number to start processing from.
#		stop=<number>	The record number to stop processing at.
#		mode=count	Only count the records.
#		label=<label string> See below
#
#	If a label string is given (for instance label="message") then each
#	line with the label "message" is accumulated and at the end each of the
#	distinct messages is printed along with their frequencies.

It’s nearly 200 lines long (I like comments) so probably inappropriate for the thread. If anyone is interested ping me a PM and I’ll give you a copy.