logger_stdout.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 "logger_stdout.h"
  7. #include "ua_types.h"
  8. static void print_time(void) {
  9. UA_DateTime now = UA_DateTime_now();
  10. UA_ByteString str;
  11. UA_DateTime_toString(now, &str);
  12. printf("%.*s", str.length, str.data);
  13. UA_ByteString_deleteMembers(&str);
  14. }
  15. #define LOG_FUNCTION(LEVEL) \
  16. static void log_##LEVEL(UA_LoggerCategory category, const char *msg) { \
  17. printf("["); \
  18. print_time(); \
  19. printf("] " #LEVEL "/%s\t%s\n", UA_LoggerCategoryNames[category], msg); \
  20. }
  21. LOG_FUNCTION(trace)
  22. LOG_FUNCTION(debug)
  23. LOG_FUNCTION(info)
  24. LOG_FUNCTION(warning)
  25. LOG_FUNCTION(error)
  26. LOG_FUNCTION(fatal)
  27. UA_Logger Logger_Stdout_new(void) {
  28. return (UA_Logger){
  29. .log_trace = log_trace,
  30. .log_debug = log_debug,
  31. .log_info = log_info,
  32. .log_warning = log_warning,
  33. .log_error = log_error,
  34. .log_fatal = log_fatal
  35. };
  36. }