Logging in JSON format

Monday, 28 November 2022 · 2 messages
HV
Huib Verweij28 Nov 2022 12:47 #
Hi, from https://docs.basex.org/wiki/Logging I understand all logging in BaseX uses a fixed text format. For our Kibana/Elastic Search logging solution in OpenShift it is recommended to use JSON as the logging format. Is it possible to make BaseX generate logs in JSON format? If not, does anyone have any experience importing the BaseX logs into Kibana/Elastic Search? Hartelijke groet, Huib Verweij.
CG
Christian Grün28 Nov 2022 13:22 #
Hi Huib,
Quoted text · Huib Verweij · 1 line
> Is it possible to make BaseX generate logs in JSON format?
You can convert BaseX logs to JSON as follows (just an example):
let $day := '2022-11-28'
let $entries := admin:logs($day, true())
let $result := array {
  for $entry in $entries
  return map:merge((
    $entry/@* ! map:entry(name(), data()),
    map:entry('message', data($entry))
  ))
}
return json:serialize($result)
…yields something like…
[
  {
    "message": "bla",
    "user": "admin",
    "time": "13:18:01.982",
    "address": "SERVER",
    "type": "INFO"
  }
]
There is currently no way to choose different log output formats, as too many BaseX features rely on our standard format. Hope this helps, Christian

⚡Generated with XQuery