You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					43 lines
				
				1.1 KiB
			
		
		
			
		
	
	
					43 lines
				
				1.1 KiB
			| 
								 
											6 years ago
										 
									 | 
							
								#!/usr/bin/env python3
							 | 
						||
| 
								 | 
							
								import zmq
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								from typing import NoReturn
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								import cereal.messaging as messaging
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								from common.logging_extra import SwagLogFileFormatter
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								from system.swaglog import get_file_handler
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								def main() -> NoReturn:
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  log_handler = get_file_handler()
							 | 
						||
| 
								 | 
							
								  log_handler.setFormatter(SwagLogFileFormatter(None))
							 | 
						||
| 
								 | 
							
								  log_level = 20  # logging.INFO
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								  ctx = zmq.Context().instance()
							 | 
						||
| 
								 | 
							
								  sock = ctx.socket(zmq.PULL)
							 | 
						||
| 
								 | 
							
								  sock.bind("ipc:///tmp/logmessage")
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  # and we publish them
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  log_message_sock = messaging.pub_sock('logMessage')
							 | 
						||
| 
								 | 
							
								  error_log_message_sock = messaging.pub_sock('errorLogMessage')
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								  while True:
							 | 
						||
| 
								 | 
							
								    dat = b''.join(sock.recv_multipart())
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    level = dat[0]
							 | 
						||
| 
								 | 
							
								    record = dat[1:].decode("utf-8")
							 | 
						||
| 
								 | 
							
								    if level >= log_level:
							 | 
						||
| 
								 | 
							
								      log_handler.emit(record)
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								    # then we publish them
							 | 
						||
| 
								 | 
							
								    msg = messaging.new_message()
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    msg.logMessage = record
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    log_message_sock.send(msg.to_bytes())
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    if level >= 40:  # logging.ERROR
							 | 
						||
| 
								 | 
							
								      msg = messaging.new_message()
							 | 
						||
| 
								 | 
							
								      msg.errorLogMessage = record
							 | 
						||
| 
								 | 
							
								      error_log_message_sock.send(msg.to_bytes())
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								if __name__ == "__main__":
							 | 
						||
| 
								 | 
							
								  main()
							 |