Skip to content

Commit

Permalink
Change loader log file location
Browse files Browse the repository at this point in the history
Signed-off-by: Jemale Lockett <jemale.lockett@intel.com>
  • Loading branch information
Jemale committed Jun 17, 2024
1 parent b5def34 commit 4b1f9ee
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
39 changes: 37 additions & 2 deletions source/loader/ze_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
#include "driver_discovery.h"
#include <iostream>

#ifdef __linux__
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#endif // __linux__

namespace loader
{
///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -261,16 +267,45 @@ namespace loader
auto discoveredDrivers = discoverEnabledDrivers();
std::string loadLibraryErrorValue;


const char *home_dir = "";
#ifdef _WIN32
std::string home_dir_string = getenv_string("USERPROFILE");
if (home_dir == ""){
auto home_drive = getenv_string("HOMEDRIVE");
auto home_path = getenv_string("HOMEPATH");
if ((home_drive != "") && (home_path != "")) {
home_dir_string = home_drive + home_path;
} else {
home_dir_string = ".";
}
}
home_dir = home_dir_string.c_str();
#else
home_dir = getenv("HOME");

if ((home_dir = getenv("HOME")) == NULL) {
home_dir = getpwuid(getuid())->pw_dir;
if (home_dir == NULL) {
home_dir = ".";
}
}
#endif
auto loader_file = getenv_string("ZEL_LOADER_LOG_FILE");
if (loader_file.empty()){
loader_file = LOADER_LOG_FILE_DEFAULT;
}

std::string full_log_file_path = "";

#ifdef _WIN32
full_log_file_path = std::string(home_dir) + "\\" + LOADER_LOG_FILE_DIRECTORY + "\\" + loader_file;
#else
full_log_file_path = std::string(home_dir) + "/" + LOADER_LOG_FILE_DIRECTORY + "/" + loader_file;
#endif
auto logging_enabled = getenv_tobool( "ZEL_ENABLE_LOADER_LOGGING" );

auto log_level = getenv_string("ZEL_LOADER_LOGGING_LEVEL");
zel_logger = std::make_shared<Logger>("ze_loader", loader_file, !log_level.empty() ? log_level : "warn", logging_enabled);
zel_logger = std::make_shared<Logger>("ze_loader", full_log_file_path, !log_level.empty() ? log_level : "warn", logging_enabled);
if ((log_level == "trace") && !debugTraceEnabled) {
debugTraceEnabled = true;
zel_logger->log_to_console = false;
Expand Down
1 change: 1 addition & 0 deletions source/utils/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define level_zero_loader_LOGGING_HPP

#define LOADER_LOG_FILE_DEFAULT "ze_loader.log"
#define LOADER_LOG_FILE_DIRECTORY ".oneapi_logs"

#include <iostream>
#include <sstream>
Expand Down

0 comments on commit 4b1f9ee

Please sign in to comment.