app_log.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*********************************************************************
  2. * _ _ _
  3. * _ __ | |_ _ | | __ _ | |__ ___
  4. * | '__|| __|(_)| | / _` || '_ \ / __|
  5. * | | | |_ _ | || (_| || |_) |\__ \
  6. * |_| \__|(_)|_| \__,_||_.__/ |___/
  7. *
  8. * www.rt-labs.com
  9. * Copyright 2021 rt-labs AB, Sweden.
  10. *
  11. * This software is dual-licensed under GPLv3 and a commercial
  12. * license. See the file LICENSE.md distributed with this software for
  13. * full license information.
  14. ********************************************************************/
  15. #include "app_log.h"
  16. #include <stdarg.h>
  17. #include <stdio.h>
  18. static int32_t log_level = APP_DEFAULT_LOG_LEVEL;
  19. void app_log_set_log_level (int32_t level)
  20. {
  21. log_level = level;
  22. }
  23. void app_log (int32_t level, const char * fmt, ...)
  24. {
  25. va_list list;
  26. if (level >= log_level)
  27. {
  28. va_start (list, fmt);
  29. vprintf (fmt, list);
  30. va_end (list);
  31. fflush (stdout);
  32. }
  33. }
  34. void app_log_print_bytes (int32_t level, const uint8_t * bytes, uint32_t len)
  35. {
  36. if (level >= log_level)
  37. {
  38. printf (" Bytes: ");
  39. for (uint32_t i = 0; i < len; i++)
  40. {
  41. printf ("%02X ", bytes[i]);
  42. }
  43. printf ("\n");
  44. }
  45. }