1
1
# Copyright 2014-2016 OpenMarket Ltd
2
+ # Copyright 2021 The Matrix.org Foundation C.I.C.
2
3
#
3
4
# Licensed under the Apache License, Version 2.0 (the "License");
4
5
# you may not use this file except in compliance with the License.
18
19
import sys
19
20
import threading
20
21
from string import Template
21
- from typing import TYPE_CHECKING , Any , Dict
22
+ from typing import TYPE_CHECKING , Any , Dict , Optional
22
23
23
24
import yaml
24
25
from zope .interface import implementer
40
41
from ._base import Config , ConfigError
41
42
42
43
if TYPE_CHECKING :
44
+ from synapse .config .homeserver import HomeServerConfig
43
45
from synapse .server import HomeServer
44
46
45
47
DEFAULT_LOG_CONFIG = Template (
141
143
class LoggingConfig (Config ):
142
144
section = "logging"
143
145
144
- def read_config (self , config , ** kwargs ):
146
+ def read_config (self , config , ** kwargs ) -> None :
145
147
if config .get ("log_file" ):
146
148
raise ConfigError (LOG_FILE_ERROR )
147
149
self .log_config = self .abspath (config .get ("log_config" ))
148
150
self .no_redirect_stdio = config .get ("no_redirect_stdio" , False )
149
151
150
- def generate_config_section (self , config_dir_path , server_name , ** kwargs ):
152
+ def generate_config_section (self , config_dir_path , server_name , ** kwargs ) -> str :
151
153
log_config = os .path .join (config_dir_path , server_name + ".log.config" )
152
154
return (
153
155
"""\
@@ -161,14 +163,14 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
161
163
% locals ()
162
164
)
163
165
164
- def read_arguments (self , args ) :
166
+ def read_arguments (self , args : argparse . Namespace ) -> None :
165
167
if args .no_redirect_stdio is not None :
166
168
self .no_redirect_stdio = args .no_redirect_stdio
167
169
if args .log_file is not None :
168
170
raise ConfigError (LOG_FILE_ERROR )
169
171
170
172
@staticmethod
171
- def add_arguments (parser ) :
173
+ def add_arguments (parser : argparse . ArgumentParser ) -> None :
172
174
logging_group = parser .add_argument_group ("logging" )
173
175
logging_group .add_argument (
174
176
"-n" ,
@@ -197,7 +199,9 @@ def generate_files(self, config: Dict[str, Any], config_dir_path: str) -> None:
197
199
log_config_file .write (DEFAULT_LOG_CONFIG .substitute (log_file = log_file ))
198
200
199
201
200
- def _setup_stdlib_logging (config , log_config_path , logBeginner : LogBeginner ) -> None :
202
+ def _setup_stdlib_logging (
203
+ config : "HomeServerConfig" , log_config_path : Optional [str ], logBeginner : LogBeginner
204
+ ) -> None :
201
205
"""
202
206
Set up Python standard library logging.
203
207
"""
@@ -230,7 +234,7 @@ def _setup_stdlib_logging(config, log_config_path, logBeginner: LogBeginner) ->
230
234
log_metadata_filter = MetadataFilter ({"server_name" : config .server .server_name })
231
235
old_factory = logging .getLogRecordFactory ()
232
236
233
- def factory (* args , ** kwargs ) :
237
+ def factory (* args : Any , ** kwargs : Any ) -> logging . LogRecord :
234
238
record = old_factory (* args , ** kwargs )
235
239
log_context_filter .filter (record )
236
240
log_metadata_filter .filter (record )
@@ -297,7 +301,7 @@ def _load_logging_config(log_config_path: str) -> None:
297
301
logging .config .dictConfig (log_config )
298
302
299
303
300
- def _reload_logging_config (log_config_path ) :
304
+ def _reload_logging_config (log_config_path : Optional [ str ]) -> None :
301
305
"""
302
306
Reload the log configuration from the file and apply it.
303
307
"""
@@ -311,8 +315,8 @@ def _reload_logging_config(log_config_path):
311
315
312
316
def setup_logging (
313
317
hs : "HomeServer" ,
314
- config ,
315
- use_worker_options = False ,
318
+ config : "HomeServerConfig" ,
319
+ use_worker_options : bool = False ,
316
320
logBeginner : LogBeginner = globalLogBeginner ,
317
321
) -> None :
318
322
"""
0 commit comments