@@ -678,39 +678,35 @@ def emit(self, record):
678678 raise LoggingError ('logging failed' ) from e
679679
680680
681+ _create_handler_registry = {
682+ 'file' : _create_file_handler ,
683+ 'filelog' : _create_filelog_handler ,
684+ 'syslog' : _create_syslog_handler ,
685+ 'stream' : _create_stream_handler ,
686+ 'graylog' : _create_graylog_handler ,
687+ 'httpjson' : _create_httpjson_handler ,
688+ }
689+
690+
691+ def register_plugin_handler (create_plugin_handler ):
692+ _create_handler_registry ["plugin" ] = create_plugin_handler
693+
694+
681695def _extract_handlers (site_config , handlers_group ):
682696 handler_prefix = f'logging/0/{ handlers_group } '
683697 handlers_list = site_config .get (handler_prefix )
684698 handlers = []
685699 for i , handler_config in enumerate (handlers_list ):
686700 handler_type = handler_config ['type' ]
687- if handler_type == 'file' :
688- hdlr = _create_file_handler (site_config , f'{ handler_prefix } /{ i } ' )
689- elif handler_type == 'filelog' :
690- hdlr = _create_filelog_handler (
691- site_config , f'{ handler_prefix } /{ i } '
692- )
693- elif handler_type == 'syslog' :
694- hdlr = _create_syslog_handler (site_config , f'{ handler_prefix } /{ i } ' )
695- elif handler_type == 'stream' :
696- hdlr = _create_stream_handler (site_config , f'{ handler_prefix } /{ i } ' )
697- elif handler_type == 'graylog' :
698- hdlr = _create_graylog_handler (
699- site_config , f'{ handler_prefix } /{ i } '
700- )
701- if hdlr is None :
702- getlogger ().warning ('could not initialize the '
703- 'graylog handler; ignoring ...' )
704- continue
705- elif handler_type == 'httpjson' :
706- hdlr = _create_httpjson_handler (
707- site_config , f'{ handler_prefix } /{ i } '
708- )
701+
702+ try :
703+ create_handler = _create_handler_registry [handler_type ]
704+ hdlr = create_handler (site_config , f'{ handler_prefix } /{ i } ' )
709705 if hdlr is None :
710706 getlogger ().warning ('could not initialize the '
711- 'httpjson handler; ignoring ...' )
707+ f' { handler_type } handler; ignoring ...' )
712708 continue
713- else :
709+ except KeyError :
714710 # Should not enter here
715711 raise AssertionError (f'unknown handler type: { handler_type } ' )
716712
0 commit comments