Make the __FILE__ and __LINE__ part of the log message.
[apple-ir-control.git] / apple-ir-control.cc
index a48d7e15bdb6f6168bf129269d136e8266fb0e08..5a56489d56eace4d323873284ba145cd141d0523 100644 (file)
@@ -17,17 +17,20 @@ const CFStringRef kPrefDomain = CFSTR("com.apple.driver.AppleIRController");
 const CFStringRef kPrefEnabled = CFSTR("DeviceEnabled");
 
 #if NDEBUG
-bool VERBOSE = false;
+const bool VERBOSE = false;
 #else
-bool VERBOSE = true;
+const bool VERBOSE = true;
 #endif
 
+#define LOCATION_LINE(x) #x
+#define LOCATION(line) __FILE__ ":" LOCATION_LINE(line)
+
 #define LOG(msg, ...) do { \
     if (VERBOSE) { \
-      printf(msg "   [%s:%d]\n", ##__VA_ARGS__, __FILE__, __LINE__); \
+      printf("[" LOCATION(__LINE__) "] " msg "\n", ##__VA_ARGS__); \
     } \
   } while(0)
-#define ERROR(msg, ...) fprintf(stderr, msg "   [%s:%d]\n", ##__VA_ARGS__, __FILE__, __LINE__)
+#define ERROR(msg, ...) fprintf(stderr, "[" LOCATION(__LINE__) "] " msg "\n", ##__VA_ARGS__)
 
 class ScopedIOHIDManager {
  public:
@@ -104,7 +107,7 @@ const char* GetBooleanDescription(CFTypeRef boolean) {
 
 bool SynchronizePrefs() {
   bool rv = CFPreferencesSynchronize(kPrefDomain, kCFPreferencesAnyUser,
-          kCFPreferencesCurrentHost);
+      kCFPreferencesCurrentHost);
   if (!rv) {
     ERROR("Failed to CFPreferencesSynchronize");
   }