Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Structured Logging
  2. A structured logging system can be useful when your logs are destined for a
  3. machine to parse and process. By maintaining its machine-readable characteristics,
  4. it enables more efficient searching and aggregations when consumed by software
  5. such as the [ELK stack](https://opensource.com/article/18/9/open-source-log-aggregation-tools).
  6. Synapse's structured logging system is configured via the file that Synapse's
  7. `log_config` config option points to. The file should include a formatter which
  8. uses the `synapse.logging.TerseJsonFormatter` class included with Synapse and a
  9. handler which uses the above formatter.
  10. There is also a `synapse.logging.JsonFormatter` option which does not include
  11. a timestamp in the resulting JSON. This is useful if the log ingester adds its
  12. own timestamp.
  13. A structured logging configuration looks similar to the following:
  14. ```yaml
  15. version: 1
  16. formatters:
  17. structured:
  18. class: synapse.logging.TerseJsonFormatter
  19. handlers:
  20. file:
  21. class: logging.handlers.TimedRotatingFileHandler
  22. formatter: structured
  23. filename: /path/to/my/logs/homeserver.log
  24. when: midnight
  25. backupCount: 3 # Does not include the current log file.
  26. encoding: utf8
  27. loggers:
  28. synapse:
  29. level: INFO
  30. handlers: [remote]
  31. synapse.storage.SQL:
  32. level: WARNING
  33. ```
  34. The above logging config will set Synapse as 'INFO' logging level by default,
  35. with the SQL layer at 'WARNING', and will log to a file, stored as JSON.
  36. It is also possible to configure Synapse to log to a remote endpoint by using the
  37. `synapse.logging.RemoteHandler` class included with Synapse. It takes the
  38. following arguments:
  39. - `host`: Hostname or IP address of the log aggregator.
  40. - `port`: Numerical port to contact on the host.
  41. - `maximum_buffer`: (Optional, defaults to 1000) The maximum buffer size to allow.
  42. A remote structured logging configuration looks similar to the following:
  43. ```yaml
  44. version: 1
  45. formatters:
  46. structured:
  47. class: synapse.logging.TerseJsonFormatter
  48. handlers:
  49. remote:
  50. class: synapse.logging.RemoteHandler
  51. formatter: structured
  52. host: 10.1.2.3
  53. port: 9999
  54. loggers:
  55. synapse:
  56. level: INFO
  57. handlers: [remote]
  58. synapse.storage.SQL:
  59. level: WARNING
  60. ```
  61. The above logging config will set Synapse as 'INFO' logging level by default,
  62. with the SQL layer at 'WARNING', and will log JSON formatted messages to a
  63. remote endpoint at 10.1.2.3:9999.