Mercurial > prosody-modules
comparison mod_log_json/README.md @ 5975:fe081789f7b5
All community modules: Unify file extention of Markdown files to .md
| author | Menel <menel@snikket.de> |
|---|---|
| date | Tue, 22 Oct 2024 10:26:01 +0200 |
| parents | mod_log_json/README.markdown@4356088ad675 |
| children |
comparison
equal
deleted
inserted
replaced
| 5974:5a65a632d5b9 | 5975:fe081789f7b5 |
|---|---|
| 1 --- | |
| 2 summary: JSON Log Sink | |
| 3 --- | |
| 4 | |
| 5 Conifiguration | |
| 6 ============== | |
| 7 | |
| 8 Here we log to `/var/log/prosody/prosody.json`: | |
| 9 | |
| 10 ``` {.lua} | |
| 11 log = { | |
| 12 -- your other log sinks | |
| 13 info = "/var/log/prosody/prosody.log" | |
| 14 -- add this: | |
| 15 { to = "json", filename = "/var/log/prosody/prosody.json" }; | |
| 16 } | |
| 17 ``` | |
| 18 | |
| 19 ## UDP | |
| 20 | |
| 21 Alternatively, it can send logs via UDP: | |
| 22 | |
| 23 ```lua | |
| 24 log = { | |
| 25 { to = "json", udp_host = "10.1.2.3", udp_port = "9999" }; | |
| 26 } | |
| 27 ``` | |
| 28 | |
| 29 Format | |
| 30 ====== | |
| 31 | |
| 32 JSON log files consist of a series of `\n`-separated JSON objects, | |
| 33 suitable for mangling with tools like | |
| 34 [`jq`](https://stedolan.github.io/jq/). | |
| 35 | |
| 36 Example (with whitespace and indentation for readability): | |
| 37 | |
| 38 ``` {.json} | |
| 39 { | |
| 40 "args" : [], | |
| 41 "datetime" : "2019-11-03T13:38:28Z", | |
| 42 "level" : "info", | |
| 43 "message" : "Client connected", | |
| 44 "source" : "c2s55f267f5b9d0" | |
| 45 } | |
| 46 { | |
| 47 "args" : [ | |
| 48 "user@example.net" | |
| 49 ], | |
| 50 "datetime" : "2019-11-03T13:38:28Z", | |
| 51 "level" : "debug", | |
| 52 "message" : "load_roster: asked for: %s", | |
| 53 "source" : "rostermanager" | |
| 54 } | |
| 55 ``` | |
| 56 | |
| 57 `datetime` | |
| 58 : [XEP-0082]-formatted timestamp. | |
| 59 | |
| 60 `source` | |
| 61 : Log source, usually a module or a connected session. | |
| 62 | |
| 63 `level` | |
| 64 : `debug`, `info`, `warn` or `error` | |
| 65 | |
| 66 `message` | |
| 67 : The log message in `printf` format. Combine with `args` to get the | |
| 68 final message. | |
| 69 | |
| 70 `args` | |
| 71 : Array of extra arguments, corresponding to `printf`-style `%s` | |
| 72 formatting in the `message`. | |
| 73 | |
| 74 Formatted message | |
| 75 ----------------- | |
| 76 | |
| 77 If desired, at the obvious expense of performance, the formatted version of | |
| 78 the string can be included in the JSON object by specifying the `formatted_as` | |
| 79 key in the logger config: | |
| 80 | |
| 81 ``` {.lua} | |
| 82 log = { | |
| 83 -- ... other sinks ... | |
| 84 { to = "json", formatted_as = "msg_formatted", filename = "/var/log/prosody/prosody.json" }; | |
| 85 } | |
| 86 | |
| 87 ``` | |
| 88 | |
| 89 This will expose the formatted message in the JSON as separate `msg_formatted` | |
| 90 key. It is possible to override existing keys using this (for example, the | |
| 91 `message` key), but not advisible. |
