10 @author: Philipp Schillinger 14 Realizes logging of active states. 17 LOG_FOLDER =
"~/.flexbe_logs" 22 if rospy.has_param(
"~log_folder"):
23 log_folder = os.path.expanduser(rospy.get_param(
"~log_folder"))
25 log_folder = os.path.expanduser(StateLogger.LOG_FOLDER)
27 if log_folder ==
"" or not rospy.get_param(
"~log_enabled",
False):
28 StateLogger.enabled =
False 31 if not os.path.exists(log_folder):
32 os.makedirs(log_folder)
35 if be_name
is not None:
36 name = be_name.replace(
" ",
"_").replace(
",",
"_").replace(
".",
"_").replace(
"/",
"_").lower()
38 filename = os.path.join(log_folder, name +
"_" + time.strftime(
"%Y-%m-%d-%H_%M_%S") +
".log")
40 logger = logging.getLogger(
'state_logger')
41 handler = logging.FileHandler(filename)
42 formatter = logging.Formatter(
'%(message)s')
43 handler.setFormatter(formatter)
44 logger.addHandler(handler)
47 logger.info(str(rospy.get_time()) +
"," + be_name +
",INIT,INIT,1,1")
49 StateLogger._logger = logger
50 StateLogger._handler = handler
56 Logs the execution of a state. 57 Should be called once when the state returns an outcome. 59 if not StateLogger.enabled:
return 60 StateLogger._logger.info(
61 str(rospy.get_time()) +
"," 65 + (
'1' if is_autonomous
else '0') +
"," 66 + (
'1' if is_executed
else '0')
72 if not StateLogger.enabled:
return 73 StateLogger._handler.close()
74 StateLogger._logger.removeHandler(StateLogger._handler)
def log_state_execution(statepath, stateclass, outcome, is_autonomous, is_executed)
def initialize(be_name=None)