logger.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <stdio.h>
  2. #include <stdarg.h>
  3. #include <stdint.h>
  4. #include "logger.h"
  5. static uint32_t level_data[2];
  6. static int _get_level(int mod){
  7. int index = mod_bit_start(mod)/(32+1);
  8. mod = mod_bit_start(mod) % 32;
  9. return (level_data[index] >> mod) & LEVEL_MASK;
  10. }
  11. void set_log_level(int mod, int l){
  12. int index = mod_bit_start(mod)/(32+1);
  13. mod = mod_bit_start(mod) % 32;
  14. level_data[index] = (level_data[index] & (~(LEVEL_MASK<<mod))) | ((l & LEVEL_MASK)<<mod);
  15. }
  16. static void log_out(char *fmt, va_list args){
  17. vprintf(fmt, args);
  18. }
  19. void log_debug(int mod, char *fmt, ...){
  20. if (_get_level(mod) >= L_debug){
  21. va_list args;
  22. va_start(args, fmt);
  23. log_out(fmt, args);
  24. va_end(args);
  25. }
  26. }
  27. void log_warning(int mod, char *fmt, ...){
  28. if (_get_level(mod) >= L_warning){
  29. va_list args;
  30. va_start(args, fmt);
  31. log_out(fmt, args);
  32. va_end(args);
  33. }
  34. }
  35. void log_error(int mod, char *fmt, ...){
  36. if (_get_level(mod) >= L_error){
  37. va_list args;
  38. va_start(args, fmt);
  39. log_out(fmt, args);
  40. va_end(args);
  41. }
  42. }
  43. //rewrite the fputc, so that the printf,vprintf can log the info the can
  44. //static char log_buffer[8];
  45. //static int log_index = 0;
  46. int fputc(int c, FILE *fp){
  47. return 1;
  48. }