logger_stdout.c 1.0 KB

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