Skip to content

Commit 18ecfd1

Browse files
committed
Change loader log file location
Also apply upstream patch to fix Windows directory creation Resolves: VLCLJ-2205 Signed-off-by: Jemale Lockett <[email protected]>
1 parent 2b75038 commit 18ecfd1

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,17 @@ This will enforce the Loader to print all errors whether fatal or non-fatal to s
4444
The Level Zero Loader uses spdlog logging and can be controlled via environment variables:
4545

4646
`ZEL_ENABLE_LOADER_LOGGING=1`
47-
`ZEL_LOADER_LOG_FILE=/path/to/logfile`
47+
48+
[DEPRECATED] `ZEL_LOADER_LOG_FILE=/path/to/logfile`
49+
50+
`ZEL_LOADER_LOG_DIR='/directory/path'`
51+
4852
`ZEL_LOADER_LOGGING_LEVEL=debug`
4953

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

5459
This feature is in early development and is preview only.
5560

source/loader/ze_loader.cpp

+41-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
#include "driver_discovery.h"
1111
#include <iostream>
1212

13+
#ifdef __linux__
14+
#include <unistd.h>
15+
#include <sys/types.h>
16+
#include <pwd.h>
17+
#endif // __linux__
18+
1319
namespace loader
1420
{
1521
///////////////////////////////////////////////////////////////////////////////
@@ -261,16 +267,49 @@ namespace loader
261267
auto discoveredDrivers = discoverEnabledDrivers();
262268
std::string loadLibraryErrorValue;
263269

270+
auto log_directory = getenv_string("ZEL_LOADER_LOG_DIR");
271+
if (log_directory.empty()) {
272+
std::string home_dir;
273+
#ifdef _WIN32
274+
home_dir = getenv_string("USERPROFILE");
275+
if (home_dir == ""){
276+
auto home_drive = getenv_string("HOMEDRIVE");
277+
auto home_path = getenv_string("HOMEPATH");
278+
if ((home_drive != "") && (home_path != "")) {
279+
home_dir = home_drive + home_path;
280+
} else {
281+
home_dir = ".";
282+
}
283+
}
284+
log_directory = home_dir + "\\" + LOADER_LOG_FILE_DIRECTORY;
285+
#else
286+
home_dir = getenv_string("HOME");
264287

288+
if (home_dir == "") {
289+
auto pwdir = getpwuid(getuid())->pw_dir;
290+
home_dir = (pwdir == NULL) ? "." : std::string(pwdir);
291+
}
292+
log_directory = home_dir + "/" + LOADER_LOG_FILE_DIRECTORY;
293+
#endif
294+
}
265295
auto loader_file = getenv_string("ZEL_LOADER_LOG_FILE");
266296
if (loader_file.empty()){
267-
loader_file = LOADER_LOG_FILE_DEFAULT;
297+
loader_file = LOADER_LOG_FILE;
298+
} else {
299+
auto log_depr_msg = "ZEL_LOADER_LOG_FILE will be deprecated in a future release";
300+
std::cout << log_depr_msg << std::endl;
268301
}
269302

303+
std::string full_log_file_path = "";
304+
#ifdef _WIN32
305+
full_log_file_path = log_directory + "\\" + loader_file;
306+
#else
307+
full_log_file_path = log_directory + "/" + loader_file;
308+
#endif
270309
auto logging_enabled = getenv_tobool( "ZEL_ENABLE_LOADER_LOGGING" );
271310

272311
auto log_level = getenv_string("ZEL_LOADER_LOGGING_LEVEL");
273-
zel_logger = std::make_shared<Logger>("ze_loader", loader_file, !log_level.empty() ? log_level : "warn", logging_enabled);
312+
zel_logger = std::make_shared<Logger>("ze_loader", full_log_file_path, !log_level.empty() ? log_level : "warn", logging_enabled);
274313
if ((log_level == "trace") && !debugTraceEnabled) {
275314
debugTraceEnabled = true;
276315
zel_logger->log_to_console = false;

source/utils/logging.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
#define FMT_HEADER_ONLY
1414
#endif
1515

16-
#define LOADER_LOG_FILE_DEFAULT "ze_loader.log"
16+
#define LOADER_LOG_FILE "ze_loader.log"
17+
#define LOADER_LOG_FILE_DIRECTORY ".oneapi_logs"
1718

1819
#include <iostream>
1920
#include <sstream>

third_party/spdlog_headers/spdlog/details/os-inl.h

+9
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,15 @@ SPDLOG_INLINE bool create_dir(const filename_t &path) {
534534
}
535535

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

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

0 commit comments

Comments
 (0)