Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwei37 committed Aug 15, 2024
1 parent 2fe01fa commit 9d7d172
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ endif()
add_subdirectory(third_party/spdlog)
if(NOT DEFINED SPDLOG_ACTIVE_LEVEL)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_definitions(SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG)
add_compile_definitions(SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE)
else()
add_compile_definitions(SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO)
endif()
Expand Down
44 changes: 21 additions & 23 deletions runtime/include/bpftime_logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,35 @@
namespace bpftime
{

inline std::string expand_user_path(const std::string &inputPath)
{
if (inputPath.empty()) {
return "console";
}
inline std::string expand_user_path(const std::string &inputPath) {
if (inputPath.empty()) {
return "console";
}

if (inputPath[0] == '~') {
const char *homeDir = getenv("HOME");
if (!homeDir) {
return "console";
}
if (inputPath[0] == '~') {
const char* homeDir = getenv("HOME");
if (!homeDir) {
return "console";
}

if (inputPath.size() == 1 || inputPath[1] == '/') {
// Replace "~" with the home directory
return std::filesystem::path(homeDir) /
inputPath.substr(1);
} else {
// Handle cases like "~user/some/path"
return "console"; // Unsupported path format for
// simplicity
}
}

// Return the original path if no tilde expansion is needed
return inputPath;
if (inputPath.size() == 1 || inputPath[1] == '/') {
// Replace "~" with the home directory
std::string expandedPath = (std::filesystem::path(homeDir) / inputPath.substr(1)).string();
return expandedPath;
} else {
return "console"; // Unsupported path format
}
}

// Return the original path if no tilde expansion is needed
return inputPath;
}

inline void bpftime_set_logger(const std::string &target) noexcept
{
std::string logger_target = expand_user_path(target);

SPDLOG_INFO("Setting logger to {}", logger_target);
if (logger_target == "console") {
// Set logger to stderr
auto logger = spdlog::stderr_color_mt("stderr");
Expand Down

0 comments on commit 9d7d172

Please sign in to comment.