Skip to content

Commit fa73721

Browse files
authored
Add info about echo, print and log commands to the book (#870)
* Add info about echo, print and log commands to the book * Minor changes --------- Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
1 parent b895063 commit fa73721

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

assets/images/0_79_std_log.png

13.2 KB
Loading

book/stdout_stderr_exit_codes.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@ If we try to run the external `cat` on a file that doesn't exist, we can see wha
5454
╰───────────┴─────────────────────────────────────────────╯
5555
```
5656

57+
## `echo`, `print`, and `log` commands
58+
59+
The [`echo`](/commands/docs/echo.md) command is mainly for _pipes_. It returns its arguments, ignoring the piped-in value. There is usually little reason to use this over just writing the values as-is.
60+
61+
In contrast, the [`print`](/commands/docs/print.md) command prints the given values to stdout as plain text. It can be used to write to standard error output, as well. Unlike [`echo`](/commands/docs/echo.md), this command does not return any value (`print | describe` will return "nothing"). Since this command has no output, there is no point in piping it with other commands.
62+
63+
The [standard library](/book/standard_library.md) has commands to write out messages in different logging levels. For example:
64+
65+
@[code](@snippets/book/std_log.nu)
66+
67+
![Log message examples](../assets/images/0_79_std_log.png)
68+
69+
The log level for output can be set with the `NU_LOG_LEVEL` environment variable:
70+
71+
```
72+
NU_LOG_LEVEL=DEBUG nu std_log.nu
73+
```
74+
5775
## Using `out>`, `err>` to redirect stdout and stderr to files
5876

5977
If you want to redirect output to file, you can just type something like this:

snippets/book/std_log.nu

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use std 'log debug'
2+
use std 'log info'
3+
use std 'log warning'
4+
use std 'log error'
5+
use std 'log critical'
6+
7+
def main [] {
8+
log debug "Debug message"
9+
log info "Info message"
10+
log warning "Warning message"
11+
log error "Error message"
12+
log critical "Critical message"
13+
}

0 commit comments

Comments
 (0)