Skip to content

Commit

Permalink
Change loader log file location
Browse files Browse the repository at this point in the history
Also apply upstream patch to fix Windows directory creation

Resolves: VLCLJ-2205

Signed-off-by: Jemale Lockett <jemale.lockett@intel.com>
  • Loading branch information
Jemale committed Jun 26, 2024
1 parent 2b75038 commit 18ecfd1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,17 @@ This will enforce the Loader to print all errors whether fatal or non-fatal to s
The Level Zero Loader uses spdlog logging and can be controlled via environment variables:

`ZEL_ENABLE_LOADER_LOGGING=1`
`ZEL_LOADER_LOG_FILE=/path/to/logfile`

[DEPRECATED] `ZEL_LOADER_LOG_FILE=/path/to/logfile`

`ZEL_LOADER_LOG_DIR='/directory/path'`

`ZEL_LOADER_LOGGING_LEVEL=debug`

Valid logging levels are trace, debug, info, warn, error, critical, off.
Logging is disabled by default but when enabled the default level is 'warn'.
The default log file is 'ze_loader.log' in the current directory
The default log file is 'ze_loader.log' in '.oneapi_logs' in the current
user's home directory.

This feature is in early development and is preview only.

Expand Down
43 changes: 41 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,49 @@ namespace loader
auto discoveredDrivers = discoverEnabledDrivers();
std::string loadLibraryErrorValue;

auto log_directory = getenv_string("ZEL_LOADER_LOG_DIR");
if (log_directory.empty()) {
std::string home_dir;
#ifdef _WIN32
home_dir = 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 = home_drive + home_path;
} else {
home_dir = ".";
}
}
log_directory = home_dir + "\\" + LOADER_LOG_FILE_DIRECTORY;
#else
home_dir = getenv_string("HOME");

if (home_dir == "") {
auto pwdir = getpwuid(getuid())->pw_dir;
home_dir = (pwdir == NULL) ? "." : std::string(pwdir);
}
log_directory = home_dir + "/" + LOADER_LOG_FILE_DIRECTORY;
#endif
}
auto loader_file = getenv_string("ZEL_LOADER_LOG_FILE");
if (loader_file.empty()){
loader_file = LOADER_LOG_FILE_DEFAULT;
loader_file = LOADER_LOG_FILE;
} else {
auto log_depr_msg = "ZEL_LOADER_LOG_FILE will be deprecated in a future release";
std::cout << log_depr_msg << std::endl;
}

std::string full_log_file_path = "";
#ifdef _WIN32
full_log_file_path = log_directory + "\\" + loader_file;
#else
full_log_file_path = log_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
3 changes: 2 additions & 1 deletion source/utils/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#define FMT_HEADER_ONLY
#endif

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

#include <iostream>
#include <sstream>
Expand Down
9 changes: 9 additions & 0 deletions third_party/spdlog_headers/spdlog/details/os-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,15 @@ SPDLOG_INLINE bool create_dir(const filename_t &path) {
}

auto subdir = path.substr(0, token_pos);
#ifdef _WIN32
// if subdir is just a drive letter, add a slash e.g. "c:"=>"c:\",
// otherwise path_exists(subdir) returns false (issue #3079)
const bool is_drive = subdir.length() == 2 && subdir[1] == ':';
if (is_drive) {
subdir += '\\';
token_pos++;
}
#endif

if (!subdir.empty() && !path_exists(subdir) && !mkdir_(subdir)) {
return false; // return error if failed creating dir
Expand Down

0 comments on commit 18ecfd1

Please sign in to comment.