[clang-format] Fix a bug in aligning comments above PPDirective (#72791)
[llvm-project.git] / clang / utils / CIndex / completion_logger_server.py
blobff33331fc53c564814611da88811138a38012319
1 #!/usr/bin/env python
2 from __future__ import absolute_import, division, print_function
3 import sys
4 from socket import *
5 from time import strftime
6 import datetime
9 def main():
10 if len(sys.argv) < 4:
11 print("completion_logger_server.py <listen address> <listen port> <log file>")
12 exit(1)
14 host = sys.argv[1]
15 port = int(sys.argv[2])
16 buf = 1024 * 8
17 addr = (host, port)
19 # Create socket and bind to address
20 UDPSock = socket(AF_INET, SOCK_DGRAM)
21 UDPSock.bind(addr)
23 print("Listing on {0}:{1} and logging to '{2}'".format(host, port, sys.argv[3]))
25 # Open the logging file.
26 f = open(sys.argv[3], "a")
28 # Receive messages
29 while 1:
30 data, addr = UDPSock.recvfrom(buf)
31 if not data:
32 break
33 else:
34 f.write("{ ")
35 f.write(
36 '"time": "{0}"'.format(
37 datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
40 f.write(', "sender": "{0}" '.format(addr[0]))
41 f.write(', "data": ')
42 f.write(data)
43 f.write(" }\n")
44 f.flush()
46 # Close socket
47 UDPSock.close()
50 if __name__ == "__main__":
51 main()