Skip to content

Commit cb7e2ab

Browse files
authored
Add $env.NU_LOG_LEVEL to special_variables.md
1 parent f5f5fb7 commit cb7e2ab

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

book/special_variables.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,37 @@ A list of directories which will be searched when using the `source`, `use`, or
118118
- [Module Path](./modules/using_modules.md#module-path)
119119
- [Configuration - `$NU_LIB_DIRS`](./configuration.md#nu-lib-dirs-constant)
120120

121+
### `$env.NU_LOG_LEVEL`
122+
123+
The [standard library](/book/standard_library.md) offers logging in `std/log`. The `NU_LOG_LEVEL` environment variable is used to define the log level being used.
124+
125+
```nu
126+
nu -c '1 | print; use std/log; log debug 1111; 9 | print'
127+
# => 1
128+
# => 9
129+
130+
nu -c '1 | print; use std/log; NU_LOG_LEVEL=debug log debug 1111; 9 | print'
131+
# => 1
132+
# => 2025-07-12T21:27:30.080|DBG|1111
133+
# => 9
134+
135+
nu -c '1 | print; use std/log; $env.NU_LOG_LEVEL = "debug"; log debug 1111; 9 | print'
136+
# => 1
137+
# => 2025-07-12T21:27:57.888|DBG|1111
138+
# => 9
139+
```
140+
141+
Note that `$env.NU_LIB_DIRS` is different from `nu --log-level`, which sets the log level for Nushell commands. It does not influence the `std/log` logging used in custom commands and scripts.
142+
143+
```nu
144+
nu --log-level 'debug' -c '1 | print; use std/log; log debug 1111; 9 | print'
145+
# => … a lot more log messages, with references to the Nushell command Rust source files
146+
# and without our own `log debug` message
147+
# => 1
148+
# => 9
149+
# => …
150+
```
151+
121152
### `$env.NU_PLUGIN_DIRS`
122153

123154
A list of directories which will be searched when registering plugins with `plugin add`. See also:

0 commit comments

Comments
 (0)