ua_log_stdout.c 1.2 KB

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