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/tools/trace_to_text/main.cc b/tools/trace_to_text/main.cc
index efcc053..8d1e811 100644
--- a/tools/trace_to_text/main.cc
+++ b/tools/trace_to_text/main.cc
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <stdio.h>
+
#include <fstream>
#include <iostream>
#include <limits>
@@ -34,6 +36,10 @@
#define PERFETTO_GET_GIT_REVISION() "unknown"
#endif
+#if !PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
+#include <unistd.h>
+#endif
+
namespace perfetto {
namespace trace_to_text {
namespace {