Browse Source

add timezone to the logs

StalderT 6 years ago
parent
commit
12be0ad68c
4 changed files with 8 additions and 2 deletions
  1. 3 0
      include/ua_types.h
  2. 0 1
      plugins/ua_clock.c
  3. 1 1
      plugins/ua_log_stdout.c
  4. 4 0
      tests/testing-plugins/testing_clock.c

+ 3 - 0
include/ua_types.h

@@ -183,6 +183,9 @@ typedef int64_t UA_DateTime;
 /* Datetime of 1 Jan 1970 00:00 */
 #define UA_DATETIME_UNIX_EPOCH (11644473600LL * UA_SEC_TO_DATETIME)
 
+/* Diff between local time and UTC time */
+UA_DateTime UA_DateTime_diffLocalTimeUTC(void);
+
 /* The current time in UTC time*/
 UA_DateTime UA_EXPORT UA_DateTime_nowUtcTime(void);
 

+ 0 - 1
plugins/ua_clock.c

@@ -59,7 +59,6 @@ UA_DateTime UA_DateTime_nowUtcTime(void) {
 }
 
 /* credit to https://stackoverflow.com/questions/13804095/get-the-time-zone-gmt-offset-in-c */
-static
 UA_DateTime UA_DateTime_diffLocalTimeUTC(void) {
     time_t gmt, rawtime = time(NULL);
 

+ 1 - 1
plugins/ua_log_stdout.c

@@ -51,7 +51,7 @@ UA_Log_Stdout(UA_LogLevel level, UA_LogCategory category,
 #ifdef UA_ENABLE_MULTITHREADING
     pthread_mutex_lock(&printf_mutex);
 #endif
-    printf("[%.23s] %s/%s" ANSI_COLOR_RESET "\t", t.data, logLevelNames[level], logCategoryNames[category]);
+    printf("[%.23s (UTC%+.1f)] %s/%s" ANSI_COLOR_RESET "\t", t.data, (float)(UA_DateTime_diffLocalTimeUTC() / UA_SEC_TO_DATETIME)/3600.0, logLevelNames[level], logCategoryNames[category]);
     vprintf(msg, args);
     printf("\n");
     fflush(stdout);

+ 4 - 0
tests/testing-plugins/testing_clock.c

@@ -24,6 +24,10 @@
 
 UA_DateTime testingClock = 0;
 
+UA_DateTime UA_DateTime_diffLocalTimeUTC(void){
+    return 0;
+}
+
 UA_DateTime UA_DateTime_nowUtcTime(void) {
     return testingClock;
 }