Commits

Tuukka Norri committed f2bf92b

iOS compatibility

Comments (0)

Files changed (2)

Sources/BXLogger.h

 BX_EXPORT void BXDeprecationWarning ();
 
 
+#if ! (defined (TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
 BX_EXPORT void BXLogSetLogFile (NSBundle *bundle);
+#endif
+
+
 BX_EXPORT void BXLog (char const *fileName, 
 					  char const *functionName, 
 					  void const *functionAddress, 

Sources/BXLogger.m

 
 
 #import "BXLogger.h"
+#import "BXArraySize.h"
 #import <dlfcn.h>
 #import <unistd.h>
+#import <sys/time.h>
 
 
 enum BXLogLevel BXLogLevel = kBXLogLevelWarning;
 static const unsigned long long kLogFileTruncateSize = 1024 * 128; 
 
 
+#if ! (defined (TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
 static void TruncateLogFile (NSString *filePath)
 {
 	NSFileManager *fm = [[NSFileManager alloc] init];
 	}	
 	[fm release];
 }
+#endif
 
 
 static inline
 }
 
 
+#if ! (defined (TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
 void
 BXLogSetLogFile (NSBundle *bundle)
 {
 					GetMacOSStatusCommentString (err));
 	}
 }
+#endif
 
 
 void BXSetLogLevel (enum BXLogLevel level)
 void
 BXLog_v (char const *fileName, char const *functionName, void const *functionAddress, int line, enum BXLogLevel level, NSString * const messageFmt, va_list args)
 {
+	char dateBuffer [32] = {};
+	struct timeval tv = {};
+	struct tm tm = {};
+	gettimeofday (&tv, NULL);
+	gmtime_r (&tv.tv_sec, &tm);
+	strftime (dateBuffer, BXArraySize (dateBuffer), "%Y-%m-%d %H:%M:%S", &tm);
+	
 	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
 	char *executable = CopyExecutableName ();
 	char *library = CopyLibraryName (functionAddress);
 	const char *file = LastPathComponent (fileName);
+	const char isMain = ([NSThread isMainThread] ? 'm' : 's');
 	
-	NSString *date = [[NSDate date] descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S.%F" timeZone: nil locale: nil];
 	NSString *message = [[[NSString alloc] initWithFormat: messageFmt arguments: args] autorelease];
-		
-	const char isMain = ([NSThread isMainThread] ? 'm' : 's');
-	fprintf (stderr, "%23s  %s (%s) [%d %p%c]  %s:%d  %s \t%8s %s\n", 
-		[date UTF8String], executable, library ?: "???", getpid (), [NSThread currentThread], isMain, file, line, functionName, LogLevel (level), [message UTF8String]);
+	fprintf (stderr, "%19s.%.lf %s (%s) [%d %p%c]  %s:%d  %s \t%8s %s\n", 
+		dateBuffer, 1000.0 * tv.tv_usec, executable, library ?: "???", getpid (), [NSThread currentThread], isMain, file, line, functionName, LogLevel (level), [message UTF8String]);
 	fflush (stderr);
 	
 	//For GC.
-	[date self];
 	[message self];
 	
 	if (executable)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.