Skip to content

Customize log filename via pattern tokens in ZEL_LOADER_LOG_FILE - #499

Open
MaciejPlewka wants to merge 2 commits into
oneapi-src:masterfrom
MaciejPlewka:loggerName
Open

Customize log filename via pattern tokens in ZEL_LOADER_LOG_FILE#499
MaciejPlewka wants to merge 2 commits into
oneapi-src:masterfrom
MaciejPlewka:loggerName

Conversation

@MaciejPlewka

Copy link
Copy Markdown

No description provided.

Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
@rwmcguir

rwmcguir commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

We have unit tests in the repo to test portions of this, perhaps you can add one to verify this operates?
You can ask AI to generate these, and put them as part of the CMakeFile in the ./test/ folder to execute with proper environment flags enabled. The body of the code looks solid.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds runtime expansion for ZEL_LOADER_LOG_FILE so log filenames can include per-process/per-run identifiers (PID, process name, timestamp), and documents the new behavior in the README.

Changes:

  • Implemented filename pattern expansion for %P (pid), %N (process name), %T (timestamp) when resolving ZEL_LOADER_LOG_FILE.
  • Added process-name sanitization and path basename extraction helpers used by the filename expander.
  • Updated README to describe filename token support and provide examples.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
source/utils/ze_logger.cpp Adds token expansion and supporting helpers; integrates resolved filename into logger creation and advanced-mode config output.
README.md Documents ZEL_LOADER_LOG_FILE token behavior and examples.
Comments suppressed due to low confidence (2)

source/utils/ze_logger.cpp:134

  • expandLogFilePattern() computes PID, process name (/proc/self/exe readlink), and timestamp even when the filename contains no '%' tokens (e.g., the default "ze_loader.log"). This adds avoidable overhead and extra syscalls during logger creation. Add a fast-path to return the pattern unchanged when it contains no '%' at all.
std::string expandLogFilePattern(const std::string &pattern) {
    if (pattern.empty()) {
        return pattern;
    }

source/utils/ze_logger.cpp:146

  • createLogger() and comments mention supporting a literal percent token ("%%"), but expandLogFilePattern() currently treats "%%" as two characters (it doesn't collapse to a single '%'). If you intend to support "%%" as an escape for a literal percent, handle it explicitly in the token switch.
    for (std::size_t i = 0; i < pattern.size(); ++i) {
        if (pattern[i] == '%' && i + 1 < pattern.size()) {
            switch (pattern[i + 1]) {
                case 'P':
                    expanded += pid;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +115 to +128
std::string startupTimestampForFileName() {
const auto now = std::chrono::system_clock::now();
const auto now_t = std::chrono::system_clock::to_time_t(now);
std::tm tm_buf{};
#ifdef _WIN32
localtime_s(&tm_buf, &now_t);
#else
localtime_r(&now_t, &tm_buf);
#endif

char timestamp[32] = {};
std::strftime(timestamp, sizeof(timestamp), "%Y%m%d-%H%M%S", &tm_buf);
return timestamp;
}
Comment thread README.md
Comment on lines +96 to +101
Supported filename pattern tokens:
- `%P` — process id
- `%N` — process executable base name
- `%T` — logger startup timestamp formatted as `YYYYMMDD-HHMMSS`

A `%` not followed by `P`, `N`, or `T` is kept verbatim in the filename.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants