diff options
| -rw-r--r-- | DomeKey.xcodeproj/project.pbxproj | 4 | ||||
| -rw-r--r-- | DomeKey/log.c | 26 | ||||
| -rw-r--r-- | DomeKey/log.h | 11 | 
3 files changed, 41 insertions, 0 deletions
| diff --git a/DomeKey.xcodeproj/project.pbxproj b/DomeKey.xcodeproj/project.pbxproj index 3da05f9..110ee5b 100644 --- a/DomeKey.xcodeproj/project.pbxproj +++ b/DomeKey.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@  		D110C94A2122F1ED0094F963 /* libddhid.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D160C32221197983007D1B50 /* libddhid.a */; };  		D11184622125206E00961687 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D11184612125206E00961687 /* AppDelegate.m */; };  		D11CD06D217FECD9001FCB97 /* AquaticPrime.c in Sources */ = {isa = PBXBuildFile; fileRef = D11CD067217FECD9001FCB97 /* AquaticPrime.c */; }; +		D12B5B76218F31E300C6F7FC /* log.c in Sources */ = {isa = PBXBuildFile; fileRef = D12B5B71218F31E200C6F7FC /* log.c */; };  		D131C4D321663B6500801267 /* Mappings.m in Sources */ = {isa = PBXBuildFile; fileRef = D131C4D221663B6500801267 /* Mappings.m */; };  		D160C2A12118EF9D007D1B50 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D160C2A02118EF9D007D1B50 /* main.m */; };  		D18255B12180018C00ABC1E0 /* LicenseHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = D18255B02180018C00ABC1E0 /* LicenseHandler.m */; }; @@ -77,6 +78,7 @@  		D11184612125206E00961687 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };  		D11CD067217FECD9001FCB97 /* AquaticPrime.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = AquaticPrime.c; path = lib/AquaticPrime/Source/CoreFoundation/AquaticPrime.c; sourceTree = SOURCE_ROOT; };  		D11CD06C217FECD9001FCB97 /* AquaticPrime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AquaticPrime.h; path = lib/AquaticPrime/Source/CoreFoundation/AquaticPrime.h; sourceTree = SOURCE_ROOT; }; +		D12B5B71218F31E200C6F7FC /* log.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = log.c; sourceTree = "<group>"; };  		D131C4D121663B6500801267 /* Mappings.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Mappings.h; sourceTree = "<group>"; };  		D131C4D221663B6500801267 /* Mappings.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Mappings.m; sourceTree = "<group>"; };  		D160C29D2118EF9D007D1B50 /* DomeKey */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = DomeKey; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -141,6 +143,7 @@  				D18255B02180018C00ABC1E0 /* LicenseHandler.m */,  				D1EAA7A221803BB300A0AC35 /* XDG.h */,  				D1EAA7A321803BB300A0AC35 /* XDG.m */, +				D12B5B71218F31E200C6F7FC /* log.c */,  			);  			path = DomeKey;  			sourceTree = "<group>"; @@ -273,6 +276,7 @@  			isa = PBXSourcesBuildPhase;  			buildActionMask = 2147483647;  			files = ( +				D12B5B76218F31E300C6F7FC /* log.c in Sources */,  				D131C4D321663B6500801267 /* Mappings.m in Sources */,  				D1EAA7A421803BB300A0AC35 /* XDG.m in Sources */,  				D1C80CA021877E8200011088 /* Sounds.m in Sources */, diff --git a/DomeKey/log.c b/DomeKey/log.c new file mode 100644 index 0000000..f39e2bf --- /dev/null +++ b/DomeKey/log.c @@ -0,0 +1,26 @@ +#include "log.h" + +void teprintf(char const *fmt, ...) { +    // Format the current time +    time_t raw_time; +    size_t buffer_size = 35; +    char buffer[buffer_size]; +    time(&raw_time); +    struct tm *now = localtime(&raw_time); +    strftime(buffer, buffer_size, "%Y-%m-%dT%H:%M:%S%z", now); + +    // Prefix the time to the format string +    char *timestampped_fmt = malloc(strlen(buffer) + strlen(fmt) + 5); +    strcpy(timestampped_fmt, buffer); +    strcat(timestampped_fmt, " - "); +    strcat(timestampped_fmt, fmt); +    strcat(timestampped_fmt, "\n"); + +    // Print the log message +    va_list args; +    va_start(args, fmt); +    vfprintf(stderr, timestampped_fmt, args); +    va_end(args); + +    free(timestampped_fmt); +} diff --git a/DomeKey/log.h b/DomeKey/log.h index 7684143..e285f60 100644 --- a/DomeKey/log.h +++ b/DomeKey/log.h @@ -1,10 +1,21 @@  #ifndef LOG_H  #define LOG_H +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +  #define LogDebug(...) \      if ([[[[NSProcessInfo processInfo] environment] \          objectForKey:@"DOME_KEY_DEBUG"] isEqualToString:@"1"]) { \          NSLog(__VA_ARGS__); \      } + +// Print a log message prefixed with a timestamp to stderr. Format: +// 2018-11-04T14:35:58+0100 - Format string +void teprintf(char const *fmt, ...); +  #endif /* LOG_H */ | 
