Browse Source

Attempt 2, using asl_log instead of NSLog because it errored.

Matt Coburn 5 years ago
parent
commit
4a8dd1e91a
3 changed files with 12 additions and 30 deletions
  1. 0 1
      CMakeLists.txt
  2. 0 15
      Source/Native/custom/enet_apple_logging.h
  3. 12 14
      Source/Native/custom/enet_logging.h

+ 0 - 1
CMakeLists.txt

@@ -35,7 +35,6 @@ set(ENET_SRCS
 	${ENET_SRCDIR}/enet.h
 	${ENET_SRCDIR}/custom/enet_logging.h
 	${ENET_SRCDIR}/custom/enet_iosFixes.h
-	${ENET_SRCDIR}/custom/enet_apple_logging.h
 )
 
 if(ENET_DEBUG)

+ 0 - 15
Source/Native/custom/enet_apple_logging.h

@@ -1,15 +0,0 @@
-#ifndef ENET_APPLE_LOGGING_H
-#define ENET_APPLE_LOGGING_H
-// Partly used from StackOverflow:
-// https://stackoverflow.com/questions/8372484/nslog-style-debug-messages-from-c-code
-// Only compile this in if we're on an Apple-based system.
-#if __APPLE__
-	#include <CoreFoundation/CoreFoundation.h>
-	extern "C" void NSLog(CFStringRef format, ...);
-
-	#define AppleNSLog(fmt, ...) \
-	{ \
-		NSLog(CFSTR(fmt), ##__VA_ARGS__); \
-	}
-#endif
-#endif

+ 12 - 14
Source/Native/custom/enet_logging.h

@@ -7,8 +7,8 @@
 
 // Apple Specific things.
 #if __APPLE__
-	#include <TargetConditionals.h>
-	#include <CoreFoundation/CoreFoundation.h>
+	#include <TargetConditionals.h> // <-- Not needed?
+    #include <asl.h>
 #endif
 
 // TODO: Make better filenames; ie. enet_log.pid.txt
@@ -42,33 +42,31 @@ static inline void enet_log(enum enet_log_type type, const char *func, int line,
 	struct tm *local_time = localtime(&tstamp);
 	char time_buf[64];
 
-	time_buf[strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S", local_time)] = '\0';
-
 #if __APPLE__
 	// Logging has changed, hopefully this will dump it into your Console.app
 	// on macOS/iOS.
-	
+    char logStringBuf[512];
+    
 	// Prefix
-	printf("Enet: %s [%s] [%s:%d] ", time_buf, enet_log_type_names[type], func, line);
-
-	va_start(args, fmt);
-	// TESTING
-	AppleNSLog(fmt, args);
-	// vprintf(fmt, args);	
+    va_start(args, fmt);
+    vsprintf(logStringBuf, fmt, args);
+    asl_log(NULL, NULL, ASL_LEVEL_ERR, "%s", logStringBuf);
 	va_end(args);
-
-	printf("\n");
 #else
+    // Timestamp
+    time_buf[strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S", local_time)] = '\0';
+    
 	// Open the log file
 	if (!enet_log_fp) enet_log_fp = fopen(ENET_LOG_FILE, "a");
 	if (!enet_log_fp) return;
 
+    // Print the log into the file
 	fprintf(enet_log_fp, "%s [%s] [%s:%d] ", time_buf, enet_log_type_names[type], func, line);
 	va_start(args, fmt);
 	vfprintf(enet_log_fp, fmt, args);
 	va_end(args);
-
 	fprintf(enet_log_fp, "\n");
+    // Close the file
 	fflush(enet_log_fp);
 #endif