├── README.md ├── RemoteLog.h └── rlogserver.py /README.md: -------------------------------------------------------------------------------- 1 | ## Usage 2 | 3 | RemoteLog supports all the format specifiers of `NSLog` so it should be very easy to migrate to. 4 | 5 | - Copy `RemoteLog.h` to `$THEOS/include` 6 | - Change the ip addresses in the `RemoteLog.h` file to match your computer's ip address 7 | - Include the header in any source files you want to use it in: 8 | ``` 9 | #include 10 | ``` 11 | - Replace calls to `NSLog` with calls to `RLog`: 12 | ``` 13 | RLog(@"Test log: %@", someObject); 14 | ``` 15 | - Run the python server on your computer and watch the logs coming in :) 16 | -------------------------------------------------------------------------------- /RemoteLog.h: -------------------------------------------------------------------------------- 1 | #ifndef _REMOTE_LOG_H_ 2 | #define _REMOTE_LOG_H_ 3 | 4 | #import 5 | #import 6 | #import 7 | #import 8 | 9 | // change this to match your destination (server) IP address 10 | #define RLOG_IP_ADDRESS "replace with ip" 11 | #define RLOG_PORT 11909 12 | 13 | __attribute__((unused)) static void RLogv(NSString* format, va_list args) 14 | { 15 | #if DEBUG 16 | NSString* str = [[NSString alloc] initWithFormat:format arguments:args]; 17 | 18 | int sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); 19 | if (sd <= 0) 20 | { 21 | NSLog(@"[RemoteLog] Error: Could not open socket"); 22 | return; 23 | } 24 | 25 | int broadcastEnable = 1; 26 | int ret = setsockopt(sd, SOL_SOCKET, SO_BROADCAST, &broadcastEnable, sizeof(broadcastEnable)); 27 | if (ret) 28 | { 29 | NSLog(@"[RemoteLog] Error: Could not open set socket to broadcast mode"); 30 | close(sd); 31 | return; 32 | } 33 | 34 | struct sockaddr_in broadcastAddr; 35 | memset(&broadcastAddr, 0, sizeof broadcastAddr); 36 | broadcastAddr.sin_family = AF_INET; 37 | inet_pton(AF_INET, RLOG_IP_ADDRESS, &broadcastAddr.sin_addr); 38 | broadcastAddr.sin_port = htons(RLOG_PORT); 39 | 40 | char* request = (char*)[str UTF8String]; 41 | ret = sendto(sd, request, strlen(request), 0, (struct sockaddr*)&broadcastAddr, sizeof broadcastAddr); 42 | if (ret < 0) 43 | { 44 | NSLog(@"[RemoteLog] Error: Could not send broadcast"); 45 | close(sd); 46 | return; 47 | } 48 | close(sd); 49 | #endif 50 | } 51 | 52 | __attribute__((unused)) static void RLog(NSString* format, ...) 53 | { 54 | #if DEBUG 55 | va_list args; 56 | va_start(args, format); 57 | RLogv(format, args); 58 | va_end(args); 59 | #endif 60 | } 61 | #endif 62 | -------------------------------------------------------------------------------- /rlogserver.py: -------------------------------------------------------------------------------- 1 | # created by Tonyk7 2 | import logging 3 | import socket 4 | 5 | # change this to match the port in RemoteLog.h 6 | rlog_port = 11909 7 | 8 | # code is from: https://gist.github.com/majek/1763628 9 | def udp_server(host="0.0.0.0", port=rlog_port): 10 | s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 11 | s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 12 | s.bind((host, port)) 13 | 14 | while True: 15 | (data, addr) = s.recvfrom(128*1024) 16 | yield data 17 | 18 | for data in udp_server(): 19 | print(data.decode('utf-8').strip()) 20 | --------------------------------------------------------------------------------