android: add logging

This commit is contained in:
BreadFish64 2019-02-15 20:37:36 -06:00
parent 9848610ea2
commit f767b5fdef
10 changed files with 160 additions and 30 deletions

View file

@ -259,7 +259,7 @@ Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsign
entry.timestamp = duration_cast<std::chrono::microseconds>(steady_clock::now() - time_origin);
entry.log_class = log_class;
entry.log_level = log_level;
entry.filename = Common::TrimSourcePath(filename);
entry.filename = Common::TrimSourcePath(filename, {R"(\.\.)", "src"}).data();
entry.line_num = line_nr;
entry.function = function;
entry.message = std::move(message);

View file

@ -7,6 +7,7 @@
#include <codecvt>
#include <cstdlib>
#include <locale>
#include <regex>
#include <sstream>
#include "common/common_paths.h"
#include "common/logging/log.h"
@ -210,25 +211,17 @@ std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t
return std::string(buffer, len);
}
const char* TrimSourcePath(const char* path, const char* root) {
const char* p = path;
while (*p != '\0') {
const char* next_slash = p;
while (*next_slash != '\0' && *next_slash != '/' && *next_slash != '\\') {
++next_slash;
}
bool is_src = Common::ComparePartialString(p, next_slash, root);
p = next_slash;
if (*p != '\0') {
++p;
}
if (is_src) {
path = p;
}
std::string TrimSourcePath(const std::string& file_path, const std::vector<std::string>& roots) {
// match from beginning of path to dir sep
std::string regex_src = R"(.*([\/\\]|^)()";
// plus the last occurrence of any root
for (auto root = roots.begin(); root < roots.end() - 1; ++root) {
regex_src += '(' + *root + ")|";
}
return path;
regex_src += '(' + roots.back() + ')';
// plus dir sep
regex_src += R"()[\/\\])";
std::regex regex(regex_src);
return std::regex_replace(file_path, regex, "");
}
} // namespace Common

View file

@ -69,11 +69,11 @@ std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t
* intended to be used to strip a system-specific build directory from the `__FILE__` macro,
* leaving only the path relative to the sources root.
*
* @param path The input file path as a null-terminated string
* @param root The name of the root source directory as a null-terminated string. Path up to and
* including the last occurrence of this name will be stripped
* @return A pointer to the same string passed as `path`, but starting at the trimmed portion
* @param path The input file path as a string
* @param roots The name of the root source directorys as a vector of strings. Path up to and
* including the last occurrence of these names will be stripped
* @return The trimmed path as a string
*/
const char* TrimSourcePath(const char* path, const char* root = "src");
std::string TrimSourcePath(const std::string& file_path, const std::vector<std::string>& roots);
} // namespace Common