1
0

test-log.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "log.h"
  2. #include <cstdlib>
  3. #include <thread>
  4. int main() {
  5. const int n_thread = 8;
  6. std::thread threads[n_thread];
  7. for (int i = 0; i < n_thread; i++) {
  8. threads[i] = std::thread([i]() {
  9. const int n_msg = 1000;
  10. for (int j = 0; j < n_msg; j++) {
  11. const int log_type = std::rand() % 4;
  12. switch (log_type) {
  13. case 0: LOG_INF("Thread %d: %d\n", i, j); break;
  14. case 1: LOG_WRN("Thread %d: %d\n", i, j); break;
  15. case 2: LOG_ERR("Thread %d: %d\n", i, j); break;
  16. case 3: LOG_DBG("Thread %d: %d\n", i, j); break;
  17. default:
  18. break;
  19. }
  20. if (rand () % 10 < 5) {
  21. common_log_set_timestamps(common_log_main(), rand() % 2);
  22. common_log_set_prefix (common_log_main(), rand() % 2);
  23. }
  24. }
  25. });
  26. }
  27. for (int i = 0; i < n_thread; i++) {
  28. threads[i].join();
  29. }
  30. return 0;
  31. }