@@ -243,6 +243,7 @@ def __init__(self) -> None:
243243 self ._robot_output_file : Optional [str ] = None
244244 self .output_messages : bool = False
245245 self .output_log : bool = False
246+ self .output_timestamps : bool = False
246247 self .group_output : bool = False
247248 self .hit_counts : Dict [HitCountEntry , int ] = {}
248249 self .last_fail_message : Optional [str ] = None
@@ -1013,53 +1014,52 @@ def log_message(self, message: Dict[str, Any]) -> None:
10131014 level = message ["level" ]
10141015 msg = message ["message" ]
10151016
1016- if message [ " level" ] == "FAIL" :
1017+ if level == "FAIL" :
10171018 self .last_fail_message = msg
10181019
1020+ if self .output_log :
1021+ self ._send_log_event (message ["timestamp" ], level , msg , OutputCategory .CONSOLE )
1022+
1023+ def _send_log_event (self , timestamp : str , level : str , msg : str , category : Union [OutputCategory , str ]) -> None :
10191024 current_frame = self .full_stack_frames [0 ] if self .full_stack_frames else None
10201025 source = (
10211026 Source (path = str (self .map_path_to_client (current_frame .source )))
1022- if current_frame and current_frame .source
1027+ if current_frame and current_frame .is_file and current_frame . source
10231028 else None
10241029 )
10251030 line = current_frame .line if current_frame else None
10261031
1027- if self .output_log :
1028- self .send_event (
1029- self ,
1030- OutputEvent (
1031- body = OutputEventBody (
1032- output = f"\u001b [38;5;237m{ message ['timestamp' ].split (' ' , 1 )[1 ]} "
1033- f" { self .MESSAGE_COLORS .get (level , '' )} { level } \u001b [0m: { msg } \n " ,
1034- category = OutputCategory .CONSOLE ,
1035- source = source ,
1036- line = line if line is not None else 0 ,
1037- column = 0 if source is not None else None ,
1038- )
1039- ),
1040- )
1032+ self .send_event (
1033+ self ,
1034+ OutputEvent (
1035+ body = OutputEventBody (
1036+ output = self ._build_output (level , msg , timestamp ),
1037+ category = category ,
1038+ source = source ,
1039+ line = line if line is not None else 0 ,
1040+ column = 0 if source is not None else None ,
1041+ )
1042+ ),
1043+ )
1044+
1045+ def _build_output (self , level : str , msg : str , timestamp : str ) -> str :
1046+ return (
1047+ (f"\u001b [38;5;237m{ timestamp .split (' ' , 1 )[1 ]} \u001b [0m " if self .output_timestamps else "" )
1048+ + (f"[ { self .MESSAGE_COLORS .get (level , '' )} { level } \u001b [0m ] " if level != "INFO" else "" )
1049+ + f"{ msg } \n "
1050+ )
10411051
10421052 def message (self , message : Dict [str , Any ]) -> None :
10431053 level = message ["level" ]
10441054 current_frame = self .full_stack_frames [0 ] if self .full_stack_frames else None
1055+
10451056 if (
10461057 self .output_messages
10471058 or current_frame is not None
10481059 and current_frame .type != "KEYWORD"
10491060 and level in ["FAIL" , "ERROR" , "WARN" ]
10501061 ):
1051- msg = message ["message" ]
1052-
1053- self .send_event (
1054- self ,
1055- OutputEvent (
1056- body = OutputEventBody (
1057- output = f"\u001b [38;5;237m{ message ['timestamp' ].split (' ' , 1 )[1 ]} "
1058- f" { self .MESSAGE_COLORS .get (level , '' )} { level } \u001b [0m: { msg } \n " ,
1059- category = OutputCategory .CONSOLE ,
1060- )
1061- ),
1062- )
1062+ self ._send_log_event (message ["timestamp" ], level , message ["message" ], "messages" )
10631063
10641064 def get_scopes (self , frame_id : int ) -> List [Scope ]:
10651065 result : List [Scope ] = []
0 commit comments