|
| 1 | +# Structured Logging |
| 2 | + |
| 3 | +A structured logging system can be useful when your logs are destined for a machine to parse and process. By maintaining its machine-readable characteristics, it enables more efficient searching and aggregations when consumed by software such as the "ELK stack". |
| 4 | + |
| 5 | +Synapse's structured logging system is configured via the file that Synapse's `log_config` config option points to. The file must be YAML and contain `structured: true`. It must contain a list of "drains" (places where logs go to). |
| 6 | + |
| 7 | +A structured logging configuration looks similar to the following: |
| 8 | + |
| 9 | +```yaml |
| 10 | +structured: true |
| 11 | + |
| 12 | +loggers: |
| 13 | + synapse: |
| 14 | + level: INFO |
| 15 | + synapse.storage.SQL: |
| 16 | + level: WARNING |
| 17 | + |
| 18 | +drains: |
| 19 | + console: |
| 20 | + type: console |
| 21 | + location: stdout |
| 22 | + file: |
| 23 | + type: file_json |
| 24 | + location: homeserver.log |
| 25 | +``` |
| 26 | +
|
| 27 | +The above logging config will set Synapse as 'INFO' logging level by default, with the SQL layer at 'WARNING', and will have two logging drains (to the console and to a file, stored as JSON). |
| 28 | +
|
| 29 | +## Drain Types |
| 30 | +
|
| 31 | +Drain types can be specified by the `type` key. |
| 32 | + |
| 33 | +### `console` |
| 34 | + |
| 35 | +Outputs human-readable logs to the console. |
| 36 | + |
| 37 | +Arguments: |
| 38 | + |
| 39 | +- `location`: Either `stdout` or `stderr`. |
| 40 | + |
| 41 | +### `console_json` |
| 42 | + |
| 43 | +Outputs machine-readable JSON logs to the console. |
| 44 | + |
| 45 | +Arguments: |
| 46 | + |
| 47 | +- `location`: Either `stdout` or `stderr`. |
| 48 | + |
| 49 | +### `console_json_terse` |
| 50 | + |
| 51 | +Outputs machine-readable JSON logs to the console, separated by newlines. This |
| 52 | +format is not designed to be read and re-formatted into human-readable text, but |
| 53 | +is optimal for a logging aggregation system. |
| 54 | + |
| 55 | +Arguments: |
| 56 | + |
| 57 | +- `location`: Either `stdout` or `stderr`. |
| 58 | + |
| 59 | +### `file` |
| 60 | + |
| 61 | +Outputs human-readable logs to a file. |
| 62 | + |
| 63 | +Arguments: |
| 64 | + |
| 65 | +- `location`: An absolute path to the file to log to. |
| 66 | + |
| 67 | +### `file_json` |
| 68 | + |
| 69 | +Outputs machine-readable logs to a file. |
| 70 | + |
| 71 | +Arguments: |
| 72 | + |
| 73 | +- `location`: An absolute path to the file to log to. |
| 74 | + |
| 75 | +### `network_json_terse` |
| 76 | + |
| 77 | +Delivers machine-readable JSON logs to a log aggregator over TCP. This is |
| 78 | +compatible with LogStash's TCP input with the codec set to `json_lines`. |
| 79 | + |
| 80 | +Arguments: |
| 81 | + |
| 82 | +- `host`: Hostname or IP address of the log aggregator. |
| 83 | +- `port`: Numerical port to contact on the host. |
0 commit comments