Customize log filename via pattern tokens in ZEL_LOADER_LOG_FILE - #499
Customize log filename via pattern tokens in ZEL_LOADER_LOG_FILE#499MaciejPlewka wants to merge 2 commits into
Conversation
Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
|
We have unit tests in the repo to test portions of this, perhaps you can add one to verify this operates? |
There was a problem hiding this comment.
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 resolvingZEL_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.
| 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; | ||
| } |
| 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. |
No description provided.