-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Change the default log config to reduce disk I/O and storage #8040
Changes from 6 commits
1af663d
29b921e
ed8a183
07465f0
5936b1a
c2fc81e
5590a73
dd0b6f2
e7d2a9e
62289fa
538efd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Change the default log config to reduce disk I/O and storage for new servers. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,33 +11,41 @@ formatters: | |
| precise: | ||
| format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s' | ||
|
|
||
| filters: | ||
| context: | ||
| (): synapse.logging.context.LoggingContextFilter | ||
| request: "" | ||
|
|
||
| handlers: | ||
| file: | ||
| class: logging.handlers.RotatingFileHandler | ||
| class: logging.handlers.TimedRotatingFileHandler | ||
| formatter: precise | ||
| filename: /var/log/matrix-synapse/homeserver.log | ||
| maxBytes: 104857600 | ||
| backupCount: 10 | ||
| filters: [context] | ||
| when: midnight | ||
| backupCount: 3 # Does not include the current log file. | ||
| encoding: utf8 | ||
|
|
||
| # Default to buffering writes to log file for efficiency. This means that | ||
| # will be a delay for WARNING/INFO/DEBUG logs to get written, but ERROR | ||
| # logs will still be flushed immediately. | ||
| buffer: | ||
| class: logging.handlers.MemoryHandler | ||
| target: file | ||
| capacity: 100 | ||
|
||
|
|
||
| console: | ||
richvdh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| class: logging.StreamHandler | ||
| formatter: precise | ||
| filters: [context] | ||
|
|
||
| loggers: | ||
| synapse.storage.SQL: | ||
| # beware: increasing this to DEBUG will make synapse log sensitive | ||
| # information such as access tokens. | ||
| level: INFO | ||
|
|
||
| twisted: | ||
| # We send the twisted logging directly to the file handler, | ||
| # to work around https://github.com/matrix-org/synapse/issues/3471 | ||
| handlers: [file] | ||
| propagate: false | ||
|
|
||
| root: | ||
| level: INFO | ||
| handlers: [file, console] | ||
| handlers: [buffer] | ||
|
|
||
| disable_existing_loggers: false | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,34 +55,42 @@ | |
| format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - \ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw: remember that the docker image has its own default log config; please update it to keep it in sync. |
||
| %(request)s - %(message)s' | ||
|
|
||
| filters: | ||
| context: | ||
| (): synapse.logging.context.LoggingContextFilter | ||
| request: "" | ||
|
|
||
| handlers: | ||
| file: | ||
| class: logging.handlers.RotatingFileHandler | ||
| class: logging.handlers.TimedRotatingFileHandler | ||
| formatter: precise | ||
| filename: ${log_file} | ||
| maxBytes: 104857600 | ||
| backupCount: 10 | ||
| filters: [context] | ||
| when: midnight | ||
| backupCount: 3 # Does not include the current log file. | ||
| encoding: utf8 | ||
|
|
||
| # Default to buffering writes to log file for efficiency. This means that | ||
| # will be a delay for WARNING/INFO/DEBUG logs to get written, but ERROR | ||
| # logs will still be flushed immediately. | ||
| buffer: | ||
| class: logging.handlers.MemoryHandler | ||
| target: file | ||
| capacity: 100 | ||
|
|
||
| console: | ||
| class: logging.StreamHandler | ||
| formatter: precise | ||
| filters: [context] | ||
|
|
||
| loggers: | ||
| synapse.storage.SQL: | ||
| # beware: increasing this to DEBUG will make synapse log sensitive | ||
| # information such as access tokens. | ||
| level: INFO | ||
|
|
||
| twisted: | ||
| # We send the twisted logging directly to the file handler, | ||
| # to work around https://github.com/matrix-org/synapse/issues/3471 | ||
| handlers: [file] | ||
| propagate: false | ||
|
|
||
| root: | ||
| level: INFO | ||
| handlers: [file, console] | ||
| handlers: [buffer] | ||
|
|
||
| disable_existing_loggers: false | ||
| """ | ||
|
|
@@ -168,11 +176,26 @@ def _setup_stdlib_logging(config, log_config, logBeginner: LogBeginner): | |
|
|
||
| handler = logging.StreamHandler() | ||
| handler.setFormatter(formatter) | ||
| handler.addFilter(LoggingContextFilter(request="")) | ||
| logger.addHandler(handler) | ||
| else: | ||
| logging.config.dictConfig(log_config) | ||
|
|
||
| # We add a log record factory that runs all messages through the | ||
| # LoggingContextFilter so that we get the context *at the time we log* | ||
| # rather than when we write to a handler. This can be done in config using | ||
| # filter options, but care must when using e.g. MemoryHandler to buffer | ||
| # writes. | ||
|
|
||
| log_filter = LoggingContextFilter(request="") | ||
| old_factory = logging.getLogRecordFactory() | ||
|
|
||
| def factory(*args, **kwargs): | ||
| record = old_factory(*args, **kwargs) | ||
| log_filter.filter(record) | ||
| return record | ||
|
|
||
| logging.setLogRecordFactory(factory) | ||
|
|
||
| # Route Twisted's native logging through to the standard library logging | ||
| # system. | ||
| observer = STDLibLogObserver() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.