Forráskód Böngészése

Apple NSLog test commit 1

Matt Coburn 5 éve
szülő
commit
fae6d12e04

+ 1 - 0
CMakeLists.txt

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

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

@@ -0,0 +1,15 @@
+#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

+ 13 - 9
Source/Native/custom/enet_logging.h

@@ -1,15 +1,18 @@
 #ifndef ENET_LOGGING_H
 #ifndef ENET_LOGGING_H
 #define ENET_LOGGING_H
 #define ENET_LOGGING_H
 
 
+// Include basic things used for our logging facility.
 #include <stdarg.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdio.h>
 
 
+// Apple Specific things.
 #if __APPLE__
 #if __APPLE__
 	#include <TargetConditionals.h>
 	#include <TargetConditionals.h>
+	#include <CoreFoundation/CoreFoundation.h>
 #endif
 #endif
 
 
 // TODO: Make better filenames; ie. enet_log.pid.txt
 // TODO: Make better filenames; ie. enet_log.pid.txt
-#define ENET_LOG_FILE "enet_log.txt"
+#define ENET_LOG_FILE "enet_debug.log"
 
 
 static FILE *enet_log_fp = NULL;
 static FILE *enet_log_fp = NULL;
 
 
@@ -41,16 +44,17 @@ static inline void enet_log(enum enet_log_type type, const char *func, int line,
 
 
 	time_buf[strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S", local_time)] = '\0';
 	time_buf[strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S", local_time)] = '\0';
 
 
-#if __APPLE__ && TARGET_OS_IPHONE
-	// https://github.com/SoftwareGuy/ENet-CSharp/issues/15
-	// iOS Debugging - File Access Permission (#blameApple)
-	// Can't write to files without the file permission... so don't do that if we're on Apple.
-
+#if __APPLE__
+	// Logging has changed, hopefully this will dump it into your Console.app
+	// on macOS/iOS.
+	
 	// Prefix
 	// Prefix
-	printf("%s [%s] [%s:%d] ", time_buf, enet_log_type_names[type], func, line);
+	printf("Enet: %s [%s] [%s:%d] ", time_buf, enet_log_type_names[type], func, line);
 
 
-	va_start(args, fmt);	
-	vprintf(fmt, args);	
+	va_start(args, fmt);
+	// TESTING
+	AppleNSLog(fmt, args);
+	// vprintf(fmt, args);	
 	va_end(args);
 	va_end(args);
 
 
 	printf("\n");
 	printf("\n");

+ 0 - 1
bump.txt

@@ -1 +0,0 @@
-Bump