Skip to content

Commit dea39ef

Browse files
Kissakifdncred
andauthored
Add $env.NU_LOG_LEVEL to Special Variables (#1976)
* Add `$env.NU_LOG_LEVEL` to special_variables.md * Elaborate context Co-authored-by: Darren Schroeder <[email protected]> * Elaborate context Co-authored-by: Darren Schroeder <[email protected]> --------- Co-authored-by: Darren Schroeder <[email protected]>
1 parent 6dbce64 commit dea39ef

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
@@ -101,6 +101,37 @@ A list of directories which will be searched when using the `source`, `use`, or
101101
- [Module Path](./modules/using_modules.md#module-path)
102102
- [Configuration - `$NU_LIB_DIRS`](./configuration.md#nu-lib-dirs-constant)
103103

104+
### `$env.NU_LOG_LEVEL`
105+
106+
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 for custom commands, modules, and scripts.
107+
108+
```nu
109+
nu -c '1 | print; use std/log; log debug 1111; 9 | print'
110+
# => 1
111+
# => 9
112+
113+
nu -c '1 | print; use std/log; NU_LOG_LEVEL=debug log debug 1111; 9 | print'
114+
# => 1
115+
# => 2025-07-12T21:27:30.080|DBG|1111
116+
# => 9
117+
118+
nu -c '1 | print; use std/log; $env.NU_LOG_LEVEL = "debug"; log debug 1111; 9 | print'
119+
# => 1
120+
# => 2025-07-12T21:27:57.888|DBG|1111
121+
# => 9
122+
```
123+
124+
Note that `$env.NU_LOG_LEVEL` is different from `nu --log-level`, which sets the log level for built-in native Rust Nushell commands. It does not influence the `std/log` logging used in custom commands and scripts.
125+
126+
```nu
127+
nu --log-level 'debug' -c '1 | print; use std/log; log debug 1111; 9 | print'
128+
# => … a lot more log messages, with references to the Nushell command Rust source files
129+
# and without our own `log debug` message
130+
# => 1
131+
# => 9
132+
# => …
133+
```
134+
104135
### `$env.NU_PLUGIN_DIRS`
105136

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

0 commit comments

Comments
 (0)