logger_stdout.c 1.1 KB

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