Skip to content

Commit

Permalink
Add support for plugin log handler
Browse files Browse the repository at this point in the history
  • Loading branch information
dmargala committed Oct 1, 2024
1 parent 0ee92a3 commit 66e7a4c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
44 changes: 20 additions & 24 deletions reframe/core/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,39 +678,35 @@ def emit(self, record):
raise LoggingError('logging failed') from e


_create_handler_registry = {
'file': _create_file_handler,
'filelog': _create_filelog_handler,
'syslog': _create_syslog_handler,
'stream': _create_stream_handler,
'graylog': _create_graylog_handler,
'httpjson': _create_httpjson_handler,
}


def register_plugin_handler(create_plugin_handler):
_create_handler_registry["plugin"] = create_plugin_handler


def _extract_handlers(site_config, handlers_group):
handler_prefix = f'logging/0/{handlers_group}'
handlers_list = site_config.get(handler_prefix)
handlers = []
for i, handler_config in enumerate(handlers_list):
handler_type = handler_config['type']
if handler_type == 'file':
hdlr = _create_file_handler(site_config, f'{handler_prefix}/{i}')
elif handler_type == 'filelog':
hdlr = _create_filelog_handler(
site_config, f'{handler_prefix}/{i}'
)
elif handler_type == 'syslog':
hdlr = _create_syslog_handler(site_config, f'{handler_prefix}/{i}')
elif handler_type == 'stream':
hdlr = _create_stream_handler(site_config, f'{handler_prefix}/{i}')
elif handler_type == 'graylog':
hdlr = _create_graylog_handler(
site_config, f'{handler_prefix}/{i}'
)
if hdlr is None:
getlogger().warning('could not initialize the '
'graylog handler; ignoring ...')
continue
elif handler_type == 'httpjson':
hdlr = _create_httpjson_handler(
site_config, f'{handler_prefix}/{i}'
)

try:
create_handler = _create_handler_registry[handler_type]
hdlr = create_handler(site_config, f'{handler_prefix}/{i}')
if hdlr is None:
getlogger().warning('could not initialize the '
'httpjson handler; ignoring ...')
f'{handler_type} handler; ignoring ...')
continue
else:
except KeyError:
# Should not enter here
raise AssertionError(f'unknown handler type: {handler_type}')

Expand Down
2 changes: 1 addition & 1 deletion reframe/schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"properties": {
"type": {
"type": "string",
"enum": ["file", "filelog", "graylog", "stream", "syslog", "httpjson"]
"enum": ["file", "filelog", "graylog", "stream", "syslog", "httpjson", "plugin"]
},
"level": {"$ref": "#/defs/loglevel"},
"format": {"type": "string"},
Expand Down

0 comments on commit 66e7a4c

Please sign in to comment.