Skip to content

Commit c27347d

Browse files
committed
Update docs to reflect default logging behavior
Signed-off-by: Russell McGuire <russell.w.mcguire@intel.com>
1 parent 610a01e commit c27347d

2 files changed

Lines changed: 48 additions & 24 deletions

File tree

README.md

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,47 @@ This will enforce the Loader to print all errors whether fatal or non-fatal to s
5656
# Logging to File - PREVIEW
5757
The Level Zero Loader provides built-in logging controlled via environment variables:
5858

59-
`ZEL_ENABLE_LOADER_LOGGING=1`
59+
| Environment Variable | Default | Description |
60+
|---|---|---|
61+
| `ZEL_ENABLE_LOADER_LOGGING` | `0` | Set to `1` to enable file logging |
62+
| `ZEL_LOADER_LOG_CONSOLE` | `0` | Set to `1` to enable console (stderr) logging |
63+
| `ZEL_LOADER_LOGGING_LEVEL` | `warn` | Log level: `trace`, `debug`, `info`, `warn`, `error`, `critical`, `off` |
64+
| `ZEL_LOADER_LOG_DIR` | `~/.oneapi_logs` | Directory to write the log file into |
65+
| `ZEL_LOADER_LOG_FILE` | `ze_loader.log` | Log filename (**deprecated**, will be removed in a future release) |
66+
| `ZEL_LOADER_LOG_PATTERN` | see below | Custom log format pattern |
67+
68+
## Output destination
69+
70+
The two flags control output as follows:
6071

61-
`ZEL_LOADER_LOG_DIR='/directory/path'`
72+
| `ZEL_ENABLE_LOADER_LOGGING` | `ZEL_LOADER_LOG_CONSOLE` | Output |
73+
|---|---|---|
74+
| `0` (default) | `0` (default) | Logging disabled — no file or console output |
75+
| `0` | `1` | Console output to **stderr** at the configured level |
76+
| `1` | `0` | File output to `ZEL_LOADER_LOG_DIR/ZEL_LOADER_LOG_FILE` |
77+
| `1` | `1` | Console output to **stderr** — file path is ignored |
6278

63-
`ZEL_LOADER_LOGGING_LEVEL=debug`
79+
> **Note:** When both `ZEL_ENABLE_LOADER_LOGGING=1` and `ZEL_LOADER_LOG_CONSOLE=1` are set,
80+
> output goes to the console only. The file path configuration is not used. If persistent file
81+
> capture is required, set `ZEL_LOADER_LOG_CONSOLE=0`.
6482
65-
Default Log Pattern (Does not need to be set, please see below):
66-
`ZEL_LOADER_LOG_PATTERN='[%Y-%m-%d %H:%M:%S.%e] [thread-id: %t] [%^%l%$] %v'`
83+
The log directory (`ZEL_LOADER_LOG_DIR`) is created automatically on first use if it does not exist.
6784

68-
Valid logging levels are trace, debug, info, warn, error, critical, off.
69-
Logging is disabled by default but when enabled the default level is 'warn'.
70-
The default log file is 'ze_loader.log' in '.oneapi_logs' in the current
71-
user's home directory.
85+
## Log pattern
86+
87+
Default pattern (used when `ZEL_LOADER_LOG_PATTERN` is not set):
88+
```
89+
[%Y-%m-%d %H:%M:%S.%e] [thread-id: %t] [%^%l%$] %v
90+
```
7291

73-
The default log pattern includes timestamps, thread IDs, log levels, and messages.
74-
You can customize the pattern using `ZEL_LOADER_LOG_PATTERN`. Supported pattern flags:
75-
- `%Y-%m-%d %H:%M:%S.%e` - timestamp with milliseconds (must appear as this full sequence)
76-
- `%t` - thread id
77-
- `%P` - process id
78-
- `%l` - log level
79-
- `%^` - begin color range (no-op if output is not a TTY)
80-
- `%$` - end color range
81-
- `%v` - the actual log message
92+
Supported pattern tokens:
93+
- `%Y-%m-%d %H:%M:%S.%e` — timestamp with milliseconds (must appear as this exact sequence)
94+
- `%t` — thread id
95+
- `%P` — process id
96+
- `%l` — log level label
97+
- `%^` — begin color range (no-op when output is not a TTY)
98+
- `%$` — end color range
99+
- `%v` — log message
82100

83101
This feature is in early development and is preview only.
84102

@@ -97,8 +115,10 @@ To print successful API call results, set
97115
Otherwise, only error results will be printed in the API trace output.
98116
NOTE: This will become the default behavior in future releases. for now, please set the env var to enable this logging feature.
99117

100-
By default logs will be written to the log file, as described above. To print the logs
101-
to stderr instead, `ZEL_LOADER_LOG_CONSOLE=1` needs to be set.
118+
By default logs will be written to the log file as described above. To print logs
119+
to stderr instead of a file, set `ZEL_LOADER_LOG_CONSOLE=1`. Note that when
120+
`ZEL_LOADER_LOG_CONSOLE=1`, the file path configuration is ignored — output goes
121+
to the console only.
102122

103123
The API logging output format includes both function entry and exit information, showing parameter names on entry and parameter values with the result code on exit. Each log entry is timestamped and includes the thread-id, logger name, log level. Example output:
104124

source/utils/ze_logger.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,18 @@ std::shared_ptr<ZeLogger> createLogger() {
494494
log_pattern = custom_pattern;
495495
}
496496

497-
// When logging is disabled, return a console-sink logger at level off.
498-
// This avoids any file system access (open/create) for the default case.
499-
if (!logging_enabled) {
497+
const bool log_console = getenv_tobool("ZEL_LOADER_LOG_CONSOLE");
498+
499+
// Honour the matrix:
500+
// logging_enabled=0, log_console=0 → no-op (level off, no file I/O)
501+
// logging_enabled=0, log_console=1 → console (stderr), configured level
502+
// logging_enabled=1, log_console=0 → file sink, configured level
503+
// logging_enabled=1, log_console=1 → console (stderr), configured level
504+
if (!logging_enabled && !log_console) {
500505
return std::make_shared<ZeLogger>(/*use_stderr=*/true, LogLevel::off, log_pattern);
501506
}
502507

503508
LogLevel level = logLevelFromString(log_level);
504-
const bool log_console = getenv_tobool("ZEL_LOADER_LOG_CONSOLE");
505509

506510
std::shared_ptr<ZeLogger> logger;
507511
std::string output_dest;

0 commit comments

Comments
 (0)