File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -1162,3 +1162,60 @@ If you use a Python-based configuration file, you can define your custom launche
11621162 .. note ::
11631163
11641164 In versions prior to 4.0, launchers could only be implemented inside the source code tree of ReFrame.
1165+
1166+
1167+ .. _custom-loggers :
1168+
1169+ Implementing a custom log handler
1170+ ---------------------------------
1171+
1172+ Here's an example implementation of a custom log handler defined in a Python-based configuration file.
1173+
1174+ Define a custom log handler class based on :class: `~logging.Handler ` which uses a custom logging API:
1175+
1176+ .. code-block :: python
1177+
1178+ import logging
1179+ import mylogger
1180+
1181+ class MyLoggerHandler (logging .Handler ):
1182+ def __init__ (self , key ):
1183+ super ().__init__ ()
1184+ self .key = key
1185+
1186+ def emit (self , record ):
1187+ myrecord = {
1188+ ' value' : record.check_perf_value,
1189+ }
1190+ mylogger.log(self .key, myrecord)
1191+
1192+ Apply the :func: `~reframe.core.logging.register_log_handler ` decorator to a function returns an instance of the custom log handler:
1193+
1194+ .. code-block :: python
1195+
1196+ from reframe.core.logging import register_log_handler
1197+
1198+ @register_log_handler (" mylogger" )
1199+ def _create_mylogger_handler (site_config , config_prefix ):
1200+ key = site_config.get(f ' { config_prefix} /key ' )
1201+ return MyLoggerHandler(key)
1202+
1203+
1204+ Finally, add a handler entry with type matching registered name for the custom log handler to the site config:
1205+
1206+ .. code-block :: python
1207+
1208+ site_configuration = {
1209+ ' logging' : [
1210+ {
1211+ ' handlers' : [
1212+ {
1213+ ' type' : ' mylogger' ,
1214+ ' key' : ' abc' ,
1215+ },
1216+ ...
1217+ ]
1218+ }
1219+ ],
1220+ ...
1221+ }
You can’t perform that action at this time.
0 commit comments