You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The module uses a static logger designed for use across module files within the **Containers Toolkit**. It supports configurable log levels, console output, optional log file writing, and integration with the **Windows Event Log**.
103
+
The logger supports the following log levels:
104
+
105
+
- `DEBUG`
106
+
- `INFO`
107
+
- `WARNING`
108
+
- `ERROR`
109
+
- `FATAL`
110
+
111
+
For more details on the logger, please refer to the [Logger documentation](./docs/LOGGER.md).
112
+
113
+
#### Logging Environment Variables
114
+
115
+
The logger uses the following environment variables to configure its behavior:
| `$env:CTK_LOG_LEVEL` | Sets the minimum log level. Accepted values are: `DEBUG`, `INFO`, `WARNING`, `ERROR`, and `FATAL`. Defaults to `INFO` if not set. |
120
+
| `$env:CTK_LOG_FILE` | Path to a file where logs should be written. If not set, logs will be written to the console and Windows Event Log (for applicable levels). **Note:** The logger does not handle log file rotation or cleanup—use external tooling for that. |
121
+
| `$env:SKIP_CTK_LOGGING` | If set to `"true"`, suppresses console output for all log levels except `DEBUG` (when `$DebugPreference` is not `"SilentlyContinue"`). Logging to file (if set) and to the Windows Event Log (excluding `DEBUG`) still occurs. |
122
+
100
123
## Important Notes
101
124
102
125
1. Requires elevated PowerShell to run some commands.
[Logger]::Error("Failed to register buildkit service. Containerd conf file not found at $cniConfPath.`n`t1. Ensure that the required CNI plugins are installed or you can install them using 'Install-WinCNIPlugin'.`n`t2. Create the file to resolve this issue .`n`t3. Rerun this command 'Register-BuildkitdService'")
292
-
Throw"Failed to register buildkit service. Containerd conf file not found at $cniConfPath."
291
+
[Logger]::Fatal("Failed to register buildkit service. Containerd conf file not found at $cniConfPath.`n`t1. Ensure that the required CNI plugins are installed or you can install them using 'Install-WinCNIPlugin'.`n`t2. Create the file to resolve this issue .`n`t3. Rerun this command 'Register-BuildkitdService'")
A static PowerShell logger designed for use across module files within the **Containers Toolkit**. It supports configurable log levels, console output, optional log file writing, and integration with the **Windows Event Log**.
- Logs messages to the **console**, **optional log file**, and the **Windows Event Log** (for applicable levels).
9
+
- Minimum log level is determined dynamically from the `CTK_LOG_LEVEL` environment variable or PowerShell’s `$DebugPreference`.
10
+
- Allows suppressing console output using the SKIP_CTK_LOGGING environment variable — similar to running in a quiet mode.
11
+
12
+
## Debug Logging Behavior
13
+
14
+
-`DEBUG` messages are only shown in the console if:
15
+
16
+
-`$DebugPreference` is not `"SilentlyContinue"`, **or**
17
+
- the environment variable `CTK_LOG_LEVEL` is set to `"DEBUG"`.
18
+
-`DEBUG` messages are **not** written to the Windows Event Log.
19
+
20
+
## Usage
21
+
22
+
To use the logger, you need to import the module (if it is not already imported).
23
+
24
+
```PowerShell
25
+
using using module "..\Private\logger.psm1"
26
+
```
27
+
28
+
## Log Levels
29
+
30
+
The logger supports the following log levels:
31
+
32
+
### Info level
33
+
34
+
```PowerShell
35
+
[Logger]::Log("This is a test message") # Defaults to INFO level
36
+
[Logger]::Log("This is a test message", "INFO")
37
+
[Logger]::Info("This is a test message")
38
+
39
+
INFO: [2025-05-20T08:23:12Z] [Install-Nerdctl:42]: "This is a test message"
40
+
```
41
+
42
+
### Debug level
43
+
44
+
To enable `DEBUG` level logging, set the environment variable `CTK_LOG_LEVEL` to `"DEBUG"` or ensure `$DebugPreference` is not set to `"SilentlyContinue"`.
45
+
46
+
```PowerShell
47
+
[Logger]::Log("This is a test message", "DEBUG")
48
+
[Logger]::Debug("This is a test message")
49
+
50
+
DEBUG: [2025-05-20T08:23:12Z] [Install-Nerdctl:42]: "This is a test message"
51
+
```
52
+
53
+
### Warning level
54
+
55
+
```PowerShell
56
+
[Logger]::Log("This is a test message", "WARNING")
57
+
[Logger]::Warning("This is a test message")
58
+
59
+
WARNING: [2025-05-20T08:23:12Z] [Install-Nerdctl:42]: "This is a test message"
60
+
```
61
+
62
+
### Error level
63
+
64
+
```PowerShell
65
+
[Logger]::Log("This is a test message", "ERROR")
66
+
[Logger]::Error("This is a test message")
67
+
68
+
ERROR: [2025-05-20T08:23:12Z] [Install-Nerdctl:42]: "This is a test message"
69
+
```
70
+
71
+
### Fatal level
72
+
73
+
Throws a terminating error.
74
+
75
+
```PowerShell
76
+
[Logger]::Log("This is a test message", "FATAL")
77
+
[Logger]::Fatal("This is a test message")
78
+
79
+
80
+
FATAL: [2025-05-20T08:23:12Z] [Install-Nerdctl:42]: "This is a test message"
81
+
Exception: Uncaught Critical message
82
+
```
83
+
84
+
## Environment Variables
85
+
86
+
The logger uses the following environment variables to configure its behavior:
|`$env:CTK_LOG_LEVEL`| Sets the minimum log level. Accepted values are: `DEBUG`, `INFO`, `WARNING`, `ERROR`, and `FATAL`. Defaults to `INFO` if not set. |
91
+
|`$env:CTK_LOG_FILE`| Path to a file where logs should be written. If not set, logs will be written to the console and Windows Event Log (for applicable levels). **Note:** The logger does not handle log file rotation or cleanup—use external tooling for that. |
92
+
|`$env:SKIP_CTK_LOGGING`| If set to `"true"`, suppresses console output for all log levels except `DEBUG` (when `$DebugPreference` is not `"SilentlyContinue"`). Logging to file (if set) and to the Windows Event Log (excluding `DEBUG`) still occurs. |
0 commit comments