From 174dba5d34a56f45e23ae9d3663e7123015b8cfc Mon Sep 17 00:00:00 2001 From: Jan Klass Date: Wed, 16 Jul 2025 17:14:11 +0200 Subject: [PATCH 1/3] Add `$env.NU_LOG_LEVEL` to special_variables.md --- book/special_variables.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/book/special_variables.md b/book/special_variables.md index 782f5c1d9ca..019b84be5f2 100644 --- a/book/special_variables.md +++ b/book/special_variables.md @@ -101,6 +101,37 @@ A list of directories which will be searched when using the `source`, `use`, or - [Module Path](./modules/using_modules.md#module-path) - [Configuration - `$NU_LIB_DIRS`](./configuration.md#nu-lib-dirs-constant) +### `$env.NU_LOG_LEVEL` + +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. + +```nu +nu -c '1 | print; use std/log; log debug 1111; 9 | print' +# => 1 +# => 9 + +nu -c '1 | print; use std/log; NU_LOG_LEVEL=debug log debug 1111; 9 | print' +# => 1 +# => 2025-07-12T21:27:30.080|DBG|1111 +# => 9 + +nu -c '1 | print; use std/log; $env.NU_LOG_LEVEL = "debug"; log debug 1111; 9 | print' +# => 1 +# => 2025-07-12T21:27:57.888|DBG|1111 +# => 9 +``` + +Note that `$env.NU_LOG_LEVEL` 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. + +```nu +nu --log-level 'debug' -c '1 | print; use std/log; log debug 1111; 9 | print' +# => … a lot more log messages, with references to the Nushell command Rust source files +# and without our own `log debug` message +# => 1 +# => 9 +# => … +``` + ### `$env.NU_PLUGIN_DIRS` A list of directories which will be searched when registering plugins with `plugin add`. See also: From d15ab2585adf0bb649069e1eed2483c629f5be88 Mon Sep 17 00:00:00 2001 From: Jan Klass Date: Wed, 16 Jul 2025 18:26:55 +0200 Subject: [PATCH 2/3] Elaborate context Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> --- book/special_variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/special_variables.md b/book/special_variables.md index 019b84be5f2..2308416782b 100644 --- a/book/special_variables.md +++ b/book/special_variables.md @@ -103,7 +103,7 @@ A list of directories which will be searched when using the `source`, `use`, or ### `$env.NU_LOG_LEVEL` -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. +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. ```nu nu -c '1 | print; use std/log; log debug 1111; 9 | print' From f3778a7b0eb40435567a01aee646b02790c455a8 Mon Sep 17 00:00:00 2001 From: Jan Klass Date: Wed, 16 Jul 2025 18:27:16 +0200 Subject: [PATCH 3/3] Elaborate context Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> --- book/special_variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/special_variables.md b/book/special_variables.md index 2308416782b..87900eab737 100644 --- a/book/special_variables.md +++ b/book/special_variables.md @@ -121,7 +121,7 @@ nu -c '1 | print; use std/log; $env.NU_LOG_LEVEL = "debug"; log debug 1111; 9 | # => 9 ``` -Note that `$env.NU_LOG_LEVEL` 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. +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. ```nu nu --log-level 'debug' -c '1 | print; use std/log; log debug 1111; 9 | print'