from usr.bin.guard import GuardContext # 刷新容器 guard_context = GuardContext() guard_context.refresh() def func(*args, **kwargs): """ :param args: ('anonymous',) 发送人, 默认是'anonymous'无需关心 :param kwargs: 格式如下 { 'message':{ 'message_id':2, # 消息ID 'sender':'anonymous', # 发送人 'message':'xxx', # 可以获取日志消息, 'from_event':'LOG', # 从那个事件或服务来的 'msg_type':255 # 消息类型, 默认是255 } } :return: """ print("func + {}".format(kwargs['message']['message'])) # 获取服务 log_ser = guard_context.get_server("log") # 订阅服务 log_ser.set_level("DEBUG") # 获取日志客户端 app_log = guard_context.get_logger("app") # 打印日志 app_log.debug("this is a debug log") app_log.info("this is a debug log") app_log.warning("this is a debug log") app_log.error("this is a debug log") app_log.critical("this is a debug log") # 可以订阅日志 log_ser.subscribe(func) app_log.debug("this is a debug log") app_log.info("this is a debug log") app_log.warning("this is a debug log") app_log.error("this is a debug log") app_log.critical("this is a debug log")