New group logging
This commit is contained in:
1 parent
400837b41a
commit
cded4a0200
14 files changed
+324
-75
No files matched your search
+23
-7
@@ -1,6 +1,7 @@
|
||||
#import appdaemon.plugins.hass.hassapi as hass
|
||||
import enum
|
||||
from datetime import datetime
|
||||
from contextlib import nullcontext
|
||||
#from pickle import FALSE
|
||||
|
||||
from adexpressioncontext import ADExpressionContext
|
||||
@@ -56,6 +57,7 @@ class Evaluator():
|
||||
|
||||
self.__no_log_prefix = parser.parse_args('no_log_prefix',False) #as no_log_prefix is used to feedback parser error, it need to be defined first
|
||||
condition_name = parser.parse_args('condition_name',None,['log_prefix'])
|
||||
self.__trace_name = ', '.join(map(str, condition_name)) if isinstance(condition_name, list) else str(condition_name or 'condition')
|
||||
if condition_name:
|
||||
if isinstance(condition_name,list):
|
||||
for name in condition_name:
|
||||
@@ -161,14 +163,24 @@ class Evaluator():
|
||||
raise e
|
||||
|
||||
|
||||
def __log_group(self):
|
||||
# SmartObject itself implements LoggerInterface, but many evaluators are
|
||||
# constructed with only the app as their API and no logger_interface kwarg.
|
||||
logger = self.__logger_interface or self.__appdaemon_api
|
||||
group_scope = getattr(logger, 'log_group', None)
|
||||
if callable(group_scope):
|
||||
return group_scope('smartcondition', self.__trace_name)
|
||||
return nullcontext()
|
||||
|
||||
def evaluate(self,log = True):
|
||||
try: result = self.__evaluate()
|
||||
except EvaluationException as e:
|
||||
self.__log(f"{e}",level = "ERROR")
|
||||
return None
|
||||
if log:
|
||||
self.log_evaluation_result()
|
||||
return result
|
||||
with self.__log_group():
|
||||
try: result = self.__evaluate()
|
||||
except EvaluationException as e:
|
||||
self.__log(f"{e}",level = "ERROR")
|
||||
return None
|
||||
if log:
|
||||
self.log_evaluation_result()
|
||||
return result
|
||||
|
||||
def log_callback_trigger_reason(self):
|
||||
if self.__callback_trigger_reason_log_string:
|
||||
@@ -491,6 +503,10 @@ class Evaluator():
|
||||
self.__last_evaluation_result = new_result
|
||||
|
||||
def __trigger_callbacks(self,trigger_reason,triggered_from_activation = False):
|
||||
with self.__log_group():
|
||||
return self.__trigger_callbacks_in_group(trigger_reason, triggered_from_activation)
|
||||
|
||||
def __trigger_callbacks_in_group(self,trigger_reason,triggered_from_activation = False):
|
||||
has_log_trigger_reason = False
|
||||
has_evaluation_result = False
|
||||
|
||||
|
||||
Reference in new issue
Block a user