logger_stdout.c 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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. const char *LogLevelNames[6] = {"trace", "debug", "info", "warning", "error", "fatal"};
  9. const char *LogCategoryNames[6] = {"network", "channel", "session", "server", "client", "userland"};
  10. #if ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ > 4 || defined(__clang__))
  11. #pragma GCC diagnostic push
  12. #pragma GCC diagnostic ignored "-Wformat-nonliteral"
  13. #endif
  14. void Logger_Stdout(UA_LogLevel level, UA_LogCategory category, const char *msg, ...) {
  15. UA_String time = UA_DateTime_toString(UA_DateTime_now());
  16. printf("[%.23s] %s/%s\t", time.data, LogLevelNames[level], LogCategoryNames[category]);
  17. UA_ByteString_deleteMembers(&time);
  18. va_list ap;
  19. va_start(ap, msg);
  20. vprintf(msg, ap);
  21. va_end(ap);
  22. printf("\n");
  23. }
  24. #if ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ > 4 || defined(__clang__))
  25. #pragma GCC diagnostic pop
  26. #endif