nushell/crates/nu-std/std/log.nu

304 lines
8.1 KiB
Plaintext
Raw Normal View History

Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
export-env {
remove let-env, focus on mutating $env (#9574) # Description For years, Nushell has used `let-env` to set a single environment variable. As our work on scoping continued, we refined what it meant for a variable to be in scope using `let` but never updated how `let-env` would work. Instead, `let-env` confusingly created mutations to the command's copy of `$env`. So, to help fix the mental model and point people to the right way of thinking about what changing the environment means, this PR removes `let-env` to encourage people to think of it as updating the command's environment variable via mutation. Before: ``` let-env FOO = "BAR" ``` Now: ``` $env.FOO = "BAR" ``` It's also a good reminder that the environment owned by the command is in the `$env` variable rather than global like it is in other shells. # User-Facing Changes BREAKING CHANGE BREAKING CHANGE This completely removes `let-env FOO = "BAR"` so that we can focus on `$env.FOO = "BAR"`. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After / Before Submitting integration scripts to update: - :heavy_check_mark: [starship](https://github.com/starship/starship/blob/master/src/init/starship.nu) - :heavy_check_mark: [virtualenv](https://github.com/pypa/virtualenv/blob/main/src/virtualenv/activation/nushell/activate.nu) - :heavy_check_mark: [atuin](https://github.com/ellie/atuin/blob/main/atuin/src/shell/atuin.nu) (PR: https://github.com/ellie/atuin/pull/1080) - :x: [zoxide](https://github.com/ajeetdsouza/zoxide/blob/main/templates/nushell.txt) (PR: https://github.com/ajeetdsouza/zoxide/pull/587) - :heavy_check_mark: [oh-my-posh](https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/src/shell/scripts/omp.nu) (pr: https://github.com/JanDeDobbeleer/oh-my-posh/pull/4011)
2023-06-30 21:57:51 +02:00
$env.LOG_ANSI = {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
"CRITICAL": (ansi red_bold),
"ERROR": (ansi red),
"WARNING": (ansi yellow),
"INFO": (ansi default),
"DEBUG": (ansi default_dimmed)
}
remove let-env, focus on mutating $env (#9574) # Description For years, Nushell has used `let-env` to set a single environment variable. As our work on scoping continued, we refined what it meant for a variable to be in scope using `let` but never updated how `let-env` would work. Instead, `let-env` confusingly created mutations to the command's copy of `$env`. So, to help fix the mental model and point people to the right way of thinking about what changing the environment means, this PR removes `let-env` to encourage people to think of it as updating the command's environment variable via mutation. Before: ``` let-env FOO = "BAR" ``` Now: ``` $env.FOO = "BAR" ``` It's also a good reminder that the environment owned by the command is in the `$env` variable rather than global like it is in other shells. # User-Facing Changes BREAKING CHANGE BREAKING CHANGE This completely removes `let-env FOO = "BAR"` so that we can focus on `$env.FOO = "BAR"`. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After / Before Submitting integration scripts to update: - :heavy_check_mark: [starship](https://github.com/starship/starship/blob/master/src/init/starship.nu) - :heavy_check_mark: [virtualenv](https://github.com/pypa/virtualenv/blob/main/src/virtualenv/activation/nushell/activate.nu) - :heavy_check_mark: [atuin](https://github.com/ellie/atuin/blob/main/atuin/src/shell/atuin.nu) (PR: https://github.com/ellie/atuin/pull/1080) - :x: [zoxide](https://github.com/ajeetdsouza/zoxide/blob/main/templates/nushell.txt) (PR: https://github.com/ajeetdsouza/zoxide/pull/587) - :heavy_check_mark: [oh-my-posh](https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/src/shell/scripts/omp.nu) (pr: https://github.com/JanDeDobbeleer/oh-my-posh/pull/4011)
2023-06-30 21:57:51 +02:00
$env.LOG_LEVEL = {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
"CRITICAL": 50,
"ERROR": 40,
"WARNING": 30,
"INFO": 20,
"DEBUG": 10
}
remove let-env, focus on mutating $env (#9574) # Description For years, Nushell has used `let-env` to set a single environment variable. As our work on scoping continued, we refined what it meant for a variable to be in scope using `let` but never updated how `let-env` would work. Instead, `let-env` confusingly created mutations to the command's copy of `$env`. So, to help fix the mental model and point people to the right way of thinking about what changing the environment means, this PR removes `let-env` to encourage people to think of it as updating the command's environment variable via mutation. Before: ``` let-env FOO = "BAR" ``` Now: ``` $env.FOO = "BAR" ``` It's also a good reminder that the environment owned by the command is in the `$env` variable rather than global like it is in other shells. # User-Facing Changes BREAKING CHANGE BREAKING CHANGE This completely removes `let-env FOO = "BAR"` so that we can focus on `$env.FOO = "BAR"`. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After / Before Submitting integration scripts to update: - :heavy_check_mark: [starship](https://github.com/starship/starship/blob/master/src/init/starship.nu) - :heavy_check_mark: [virtualenv](https://github.com/pypa/virtualenv/blob/main/src/virtualenv/activation/nushell/activate.nu) - :heavy_check_mark: [atuin](https://github.com/ellie/atuin/blob/main/atuin/src/shell/atuin.nu) (PR: https://github.com/ellie/atuin/pull/1080) - :x: [zoxide](https://github.com/ajeetdsouza/zoxide/blob/main/templates/nushell.txt) (PR: https://github.com/ajeetdsouza/zoxide/pull/587) - :heavy_check_mark: [oh-my-posh](https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/src/shell/scripts/omp.nu) (pr: https://github.com/JanDeDobbeleer/oh-my-posh/pull/4011)
2023-06-30 21:57:51 +02:00
$env.LOG_PREFIX = {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
"CRITICAL": "CRT",
"ERROR": "ERR",
"WARNING": "WRN",
"INFO": "INF",
"DEBUG": "DBG"
}
remove let-env, focus on mutating $env (#9574) # Description For years, Nushell has used `let-env` to set a single environment variable. As our work on scoping continued, we refined what it meant for a variable to be in scope using `let` but never updated how `let-env` would work. Instead, `let-env` confusingly created mutations to the command's copy of `$env`. So, to help fix the mental model and point people to the right way of thinking about what changing the environment means, this PR removes `let-env` to encourage people to think of it as updating the command's environment variable via mutation. Before: ``` let-env FOO = "BAR" ``` Now: ``` $env.FOO = "BAR" ``` It's also a good reminder that the environment owned by the command is in the `$env` variable rather than global like it is in other shells. # User-Facing Changes BREAKING CHANGE BREAKING CHANGE This completely removes `let-env FOO = "BAR"` so that we can focus on `$env.FOO = "BAR"`. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After / Before Submitting integration scripts to update: - :heavy_check_mark: [starship](https://github.com/starship/starship/blob/master/src/init/starship.nu) - :heavy_check_mark: [virtualenv](https://github.com/pypa/virtualenv/blob/main/src/virtualenv/activation/nushell/activate.nu) - :heavy_check_mark: [atuin](https://github.com/ellie/atuin/blob/main/atuin/src/shell/atuin.nu) (PR: https://github.com/ellie/atuin/pull/1080) - :x: [zoxide](https://github.com/ajeetdsouza/zoxide/blob/main/templates/nushell.txt) (PR: https://github.com/ajeetdsouza/zoxide/pull/587) - :heavy_check_mark: [oh-my-posh](https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/src/shell/scripts/omp.nu) (pr: https://github.com/JanDeDobbeleer/oh-my-posh/pull/4011)
2023-06-30 21:57:51 +02:00
$env.LOG_SHORT_PREFIX = {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
"CRITICAL": "C",
"ERROR": "E",
"WARNING": "W",
"INFO": "I",
"DEBUG": "D"
}
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
remove underline from std NU_LOG_FORMAT (#10604) # Description This PR removes the underline from the log format. It's been messing things up for me since there is no ansi reset in the log format and therefore everything after it is underlined. This PR should end things like this. ![image](https://github.com/nushell/nushell/assets/343840/17e6dc87-11ba-4395-aac3-f70872b9182a) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-10-04 20:30:49 +02:00
$env.NU_LOG_FORMAT = $"%ANSI_START%%DATE%|%LEVEL%|%MSG%%ANSI_STOP%"
$env.NU_LOG_DATE_FORMAT = "%Y-%m-%dT%H:%M:%S%.3f"
}
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
def log-types [] {
(
{
"CRITICAL": {
"ansi": $env.LOG_ANSI.CRITICAL,
"level": $env.LOG_LEVEL.CRITICAL,
"prefix": $env.LOG_PREFIX.CRITICAL,
"short_prefix": $env.LOG_SHORT_PREFIX.CRITICAL
},
"ERROR": {
"ansi": $env.LOG_ANSI.ERROR,
"level": $env.LOG_LEVEL.ERROR,
"prefix": $env.LOG_PREFIX.ERROR,
"short_prefix": $env.LOG_SHORT_PREFIX.ERROR
},
"WARNING": {
"ansi": $env.LOG_ANSI.WARNING,
"level": $env.LOG_LEVEL.WARNING,
"prefix": $env.LOG_PREFIX.WARNING,
"short_prefix": $env.LOG_SHORT_PREFIX.WARNING
},
"INFO": {
"ansi": $env.LOG_ANSI.INFO,
"level": $env.LOG_LEVEL.INFO,
"prefix": $env.LOG_PREFIX.INFO,
"short_prefix": $env.LOG_SHORT_PREFIX.INFO
},
"DEBUG": {
"ansi": $env.LOG_ANSI.DEBUG,
"level": $env.LOG_LEVEL.DEBUG,
"prefix": $env.LOG_PREFIX.DEBUG,
"short_prefix": $env.LOG_SHORT_PREFIX.DEBUG
}
}
)
}
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
def parse-string-level [
level: string
] {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
let level = ($level | str upcase)
if $level in [$env.LOG_PREFIX.CRITICAL $env.LOG_SHORT_PREFIX.CRITICAL "CRIT" "CRITICAL"] {
$env.LOG_LEVEL.CRITICAL
} else if $level in [$env.LOG_PREFIX.ERROR $env.LOG_SHORT_PREFIX.ERROR "ERROR"] {
$env.LOG_LEVEL.ERROR
} else if $level in [$env.LOG_PREFIX.WARNING $env.LOG_SHORT_PREFIX.WARNING "WARN" "WARNING"] {
$env.LOG_LEVEL.WARNING
} else if $level in [$env.LOG_PREFIX.DEBUG $env.LOG_SHORT_PREFIX.DEBUG "DEBUG"] {
$env.LOG_LEVEL.DEBUG
} else {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
$env.LOG_LEVEL.INFO
}
}
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
def parse-int-level [
level: int,
--short (-s)
] {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
if $level >= $env.LOG_LEVEL.CRITICAL {
if $short {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
$env.LOG_SHORT_PREFIX.CRITICAL
} else {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
$env.LOG_PREFIX.CRITICAL
}
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
} else if $level >= $env.LOG_LEVEL.ERROR {
if $short {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
$env.LOG_SHORT_PREFIX.ERROR
} else {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
$env.LOG_PREFIX.ERROR
}
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
} else if $level >= $env.LOG_LEVEL.WARNING {
if $short {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
$env.LOG_SHORT_PREFIX.WARNING
} else {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
$env.LOG_PREFIX.WARNING
}
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
} else if $level >= $env.LOG_LEVEL.INFO {
if $short {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
$env.LOG_SHORT_PREFIX.INFO
} else {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
$env.LOG_PREFIX.INFO
}
} else {
if $short {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
$env.LOG_SHORT_PREFIX.DEBUG
} else {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
$env.LOG_PREFIX.DEBUG
}
}
}
def current-log-level [] {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
let env_level = ($env.NU_LOG_LEVEL? | default ($env.LOG_LEVEL.INFO))
try {
$env_level | into int
} catch {
parse-string-level $env_level
}
}
def now [] {
date now | format date $env.NU_LOG_DATE_FORMAT
}
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
def handle-log [
message: string,
formatting: record,
format_string: string,
short: bool
] {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
let log_format = if ($format_string | is-empty) {
$env.NU_LOG_FORMAT
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
} else {
$format_string
}
let prefix = if $short {
$formatting.short_prefix
} else {
$formatting.prefix
}
custom $message $log_format $formatting.level --level-prefix $prefix --ansi $formatting.ansi
}
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
# Logging module
#
# Log formatting placeholders:
# - %MSG%: message to be logged
# - %DATE%: date of log
# - %LEVEL%: string prefix for the log level
# - %ANSI_START%: ansi formatting
# - %ANSI_STOP%: literally (ansi reset)
#
# Note: All placeholders are optional, so "" is still a valid format
#
# Example: $"%ANSI_START%%DATE%|%LEVEL%|(ansi u)%MSG%%ANSI_STOP%"
export def main [] {}
# Log a critical message
export def critical [
message: string, # A message
--short (-s) # Whether to use a short prefix
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
--format (-f): string # A format (for further reference: help std log)
] {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
handle-log $message (log-types | get CRITICAL) $format $short
}
# Log an error message
export def error [
message: string, # A message
--short (-s) # Whether to use a short prefix
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
--format (-f): string # A format (for further reference: help std log)
] {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
handle-log $message (log-types | get ERROR) $format $short
}
# Log a warning message
export def warning [
message: string, # A message
--short (-s) # Whether to use a short prefix
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
--format (-f): string # A format (for further reference: help std log)
] {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
handle-log $message (log-types | get WARNING) $format $short
}
# Log an info message
export def info [
message: string, # A message
--short (-s) # Whether to use a short prefix
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
--format (-f): string # A format (for further reference: help std log)
] {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
handle-log $message (log-types | get INFO) $format $short
}
# Log a debug message
export def debug [
message: string, # A message
--short (-s) # Whether to use a short prefix
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
--format (-f): string # A format (for further reference: help std log)
] {
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
handle-log $message (log-types | get DEBUG) $format $short
}
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
def log-level-deduction-error [
type: string
span: record<start: int, end: int>
log_level: int
] {
error make {
msg: $"(ansi red_bold)Cannot deduce ($type) for given log level: ($log_level).(ansi reset)"
label: {
text: ([
"Invalid log level."
$" Available log levels in $env.LOG_LEVEL:"
($env.LOG_LEVEL | to text | lines | each {|it| $" ($it)" } | to text)
] | str join "\n")
span: $span
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
}
}
}
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
# Log a message with a specific format and verbosity level, with either configurable or auto-deduced %LEVEL% and %ANSI_START% placeholder extensions
export def custom [
message: string, # A message
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
format: string, # A format (for further reference: help std log)
log_level: int # A log level (has to be one of the $env.LOG_LEVEL values for correct ansi/prefix deduction)
--level-prefix (-p): string # %LEVEL% placeholder extension
--ansi (-a): string # %ANSI_START% placeholder extension
] {
if (current-log-level) > ($log_level) {
return
}
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
let valid_levels_for_defaulting = [
$env.LOG_LEVEL.CRITICAL
$env.LOG_LEVEL.ERROR
$env.LOG_LEVEL.WARNING
$env.LOG_LEVEL.INFO
$env.LOG_LEVEL.DEBUG
]
let prefix = if ($level_prefix | is-empty) {
if ($log_level not-in $valid_levels_for_defaulting) {
log-level-deduction-error "log level prefix" (metadata $log_level).span $log_level
}
parse-int-level $log_level
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
} else {
$level_prefix
}
let ansi = if ($ansi | is-empty) {
if ($log_level not-in $valid_levels_for_defaulting) {
log-level-deduction-error "ansi" (metadata $log_level).span $log_level
}
(
log-types
| values
| each {|record|
if ($record.level == $log_level) {
$record.ansi
}
} | first
)
} else {
$ansi
}
print --stderr ([
["%MSG%" $message]
["%DATE%" (now)]
Logger constants refactored, `format` argument added, better formatting of failed (non) equality assertions (#9315) # Description I have (hopefully) simplified the `log.nu` internal structure and added customizable log format for all `log` commands # User-Facing Changes - [x] Replaced constants with env records for: - ansi (newly added) - log level - prefix - short prefix - [x] Added `format` argument to all log commands - [x] Assertions for (not) equality (equal, not equal, greater, lesser...) now put left and right values inside `'` quotes, so the assertions for strings are more meaningful - [x] Documented the %-formatting of log messages # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-04 10:43:40 +02:00
["%LEVEL%" $prefix]
["%ANSI_START%" $ansi]
["%ANSI_STOP%" (ansi reset)]
] | reduce --fold $format {
|it, acc| $acc | str replace --all $it.0 $it.1
})
}