4from google.protobuf.json_format
import MessageToJson
5from google.protobuf.message
import Message
as Msg
11 extract_opmon_file_path,
18 """Publish operational monitoring metrics to file or stream."""
23 log_level: int | str = logging.INFO,
24 rich_handler: bool =
False,
26 """Construct the object to publish OpMon metrics to stdout."""
28 self.
loglog = logging.getLogger(
"OpMonPublisher")
29 if not isinstance(log_level, int):
31 self.
loglog.setLevel(log_level)
32 self.
loglog.addHandler(setup_rich_handler())
37 if self.
confconf.opmon_type ==
"stdout":
39 handler = setup_rich_handler()
41 handler = logging.StreamHandler(sys.stdout)
43 elif self.
confconf.opmon_type ==
"file":
45 handler = logging.FileHandler(self.
confconf.path)
46 elif self.
confconf.opmon_type ==
"stream":
47 self.
loglog.
error(
"Type must not be stream to use file or stdout handling.")
62 self, logger: logging.Logger, level: int | str, message: str
64 """Log the metric with the appropriate level."""
72 custom_origin: dict[str, str] |
None =
None,
73 level: int | str |
None =
None,
75 """Publish the message to either a file or the terminal."""
76 if not isinstance(message, Msg):
77 self.
loglog.
error(
"Passed message needs to be of type google.protobuf.message")
82 if not isinstance(level, int):
87 metric = self.
to_entry(message=message, custom_origin=custom_origin)
89 publishing_logger = logging.getLogger(f
"{self.publisher.name}.{target_topic}")
None publish(self, Msg message, dict[str, str]|None custom_origin=None, int|str|None level=None)
None __init__(self, OpMonConf conf, int|str log_level=logging.INFO, bool rich_handler=False)
None publish_message(self, logging.Logger logger, int|str level, str message)
OpMonEntry to_entry(self, Msg message, dict[str, str]|None custom_origin)
str log_level_to_str(self, str|int level)
int log_level_to_int(self, str|int level)
str extract_topic(self, Msg message)
Factory couldn t std::string alg_name Invalid configuration error