logger_stdout.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.h"
  9. void print_time() {
  10. UA_DateTime now = UA_DateTime_now();
  11. UA_ByteString str;
  12. UA_DateTime_toString(now, &str);
  13. printf("\"%.*s\"}", str.length, str.data);
  14. UA_ByteString_deleteMembers(&str);
  15. }
  16. #define LOG_FUNCTION(LEVEL) \
  17. void log_##LEVEL(UA_LoggerCategory category, const char *msg, ...) { \
  18. va_list args; \
  19. puts("##LEVEL - "); \
  20. print_time(); \
  21. puts(" - "); \
  22. va_start(args, msg); \
  23. vprintf(msg, args); \
  24. puts("\n"); \
  25. va_end(args); \
  26. }
  27. LOG_FUNCTION(trace)
  28. LOG_FUNCTION(debug)
  29. LOG_FUNCTION(info)
  30. LOG_FUNCTION(warning)
  31. LOG_FUNCTION(error)
  32. LOG_FUNCTION(fatal)
  33. void Logger_Stdout_init(UA_Logger *logger) {
  34. *logger = (UA_Logger){
  35. .log_trace = log_trace,
  36. .log_debug = log_debug,
  37. .log_info = log_info,
  38. .log_warning = log_warning,
  39. .log_error = log_error,
  40. .log_fatal = log_fatal
  41. };
  42. }