logger_stdout.c 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  3. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  4. */
  5. #include <stdio.h>
  6. #include <stdarg.h>
  7. #include "logger_stdout.h"
  8. #include "ua_types_generated.h"
  9. const char *LogLevelNames[6] = {"trace", "debug", "info", "warning", "error", "fatal"};
  10. const char *LogCategoryNames[6] = {"network", "channel", "session", "server", "client", "userland"};
  11. #if ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ > 4 || defined(__clang__))
  12. #pragma GCC diagnostic push
  13. #pragma GCC diagnostic ignored "-Wformat-nonliteral"
  14. #endif
  15. void Logger_Stdout(UA_LogLevel level, UA_LogCategory category, const char *msg, ...) {
  16. UA_String t = UA_DateTime_toString(UA_DateTime_now());
  17. printf("[%.23s] %s/%s\t", t.data, LogLevelNames[level], LogCategoryNames[category]);
  18. UA_ByteString_deleteMembers(&t);
  19. va_list ap;
  20. va_start(ap, msg);
  21. vprintf(msg, ap);
  22. va_end(ap);
  23. printf("\n");
  24. }
  25. #if ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ > 4 || defined(__clang__))
  26. #pragma GCC diagnostic pop
  27. #endif