text_formatter.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <cstddef>
  6. #include <memory>
  7. namespace Log {
  8. class Logger;
  9. struct Entry;
  10. class Filter;
  11. /**
  12. * Attempts to trim an arbitrary prefix from `path`, leaving only the part starting at `root`. It's
  13. * intended to be used to strip a system-specific build directory from the `__FILE__` macro,
  14. * leaving only the path relative to the sources root.
  15. *
  16. * @param path The input file path as a null-terminated string
  17. * @param root The name of the root source directory as a null-terminated string. Path up to and
  18. * including the last occurence of this name will be stripped
  19. * @return A pointer to the same string passed as `path`, but starting at the trimmed portion
  20. */
  21. const char* TrimSourcePath(const char* path, const char* root = "src");
  22. /// Formats a log entry into the provided text buffer.
  23. void FormatLogMessage(const Entry& entry, char* out_text, size_t text_len);
  24. /// Formats and prints a log entry to stderr.
  25. void PrintMessage(const Entry& entry);
  26. /**
  27. * Logging loop that repeatedly reads messages from the provided logger and prints them to the
  28. * console. It is the baseline barebones log outputter.
  29. */
  30. void TextLoggingLoop(std::shared_ptr<Logger> logger, const Filter* filter);
  31. }