ua_log_stdout.c 1.1 KB

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