Logging: don't emit ANSI color codes if !isatty()
This CL makes a bunch of changes to logging:
- Move the core logic to a dedicated .cc file
- Add a timestamp in front of the logs (wall time % 1000)
to better debug across processe (not in the logcat case)s.
- Enables the coloured output only when stderr is a tty.
- Fixes the truncation of the filename to be left-truncated
rather than right-truncated (which is more useful in general).
Bug: 145150184
Change-Id: Idd7864057ed9411cea0da94ffb7ef520c21bef4f
diff --git a/test/client_api_example.cc b/test/client_api_example.cc
index e0f813d..62f04c6 100644
--- a/test/client_api_example.cc
+++ b/test/client_api_example.cc
@@ -16,6 +16,7 @@
#include "perfetto/tracing.h"
+#include <chrono>
#include <thread>
#include "protos/perfetto/config/gpu/gpu_counter_config.pbzero.h"
@@ -100,6 +101,6 @@
auto* cnt = gpu_packet->add_counters();
cnt->set_counter_id(1);
});
- sleep(1);
+ std::this_thread::sleep_for(std::chrono::seconds(1));
}
}