| 66 | |
| 67 | template <Mode LogMode = Mode::None, typename... Args> |
| 68 | bool print(const std::string_view str, Args... args) |
| 69 | { |
| 70 | if constexpr (LogMode == Mode::Debug) |
| 71 | fmt::print("[{}DEBUG\033[0m] {}", Style(173, 216, 230), Style(173, 216, 230)); |
| 72 | |
| 73 | if constexpr (LogMode == Mode::Info) |
| 74 | fmt::print("[{}INFO\033[0m] {}", Style(144, 238, 144), Style(144, 238, 144)); |
| 75 | |
| 76 | if constexpr (LogMode == Mode::Warning) |
| 77 | fmt::print("[{}WARNING\033[0m] {}", Style(255, 255, 224), Style(255, 255, 224)); |
| 78 | |
| 79 | if constexpr (LogMode == Mode::Error) |
| 80 | fmt::print("[{}ERROR\033[0m] {}", Style(255, 114, 118), Style(255, 114, 118)); |
| 81 | |
| 82 | if constexpr (LogMode == Mode::Alert) |
| 83 | fmt::print("[{}ALERT\033[0m] {}", Style(255, 0, 0), Style(255, 0, 0)); |
| 84 | |
| 85 | fmt::print(str.data(), std::forward<Args>(args)...); |
| 86 | fmt::print("\033[0m"); |
| 87 | |
| 88 | if constexpr (LogMode != Mode::None) |
| 89 | { |
| 90 | const auto binja_string = |
| 91 | fmt::format("[BINARYNINJA] {}", fmt::format(str.data(), std::forward<Args>(args)...)); |
| 92 | BinaryNinja::Log(static_cast<BNLogLevel>(LogMode), "%s", binja_string.c_str()); |
| 93 | } |
| 94 | |
| 95 | return true; |
| 96 | } |
| 97 | } // namespace Log |
| 98 | |
| 99 | /* overloading Log::Style for fmtlib so that we don't need to call .AsAnsi() when formatting */ |