The log level for output can be set with the `NU_LOG_LEVEL` environment variable:
```nu
NU_LOG_LEVEL=DEBUG nu std_log.nu
```
## File Redirections
If you want to redirect stdout of an external command to a file, you can use `out>` followed by a file path. Similarly, you can use `err>` to redirect stderr:
```nu
cat unknown.txt out> out.log err> err.log
```
If you want to redirect both stdout and stderr to the same file, you can use `out+err>`:
```nu
cat unknown.txt out+err> log.log
```
Note that `out` can be shortened to just `o`, and `err` can be shortened to just `e`. So, the following examples are equivalent to the previous ones above:
```nu
cat unknown.txt o> out.log e> err.log
cat unknown.txt o+e> log.log
```
Also, any expression can be used for the file path, as long as it is a string value:
```nu
use std
cat unknown.txt o+e> (std null-device)
```
Note that file redirections are scoped to an expression and apply to all external commands in the expression. In the example below, `out.txt` will contain `hello\nworld`:
```nu
let text = "hello\nworld"
($text | head -n 1; $text | tail -n 1) o> out.txt
```
Pipes and additional file redirections inside the expression will override any file redirections applied from the outside.
## Pipe Redirections
If a regular pipe `|` comes after an external command, it redirects the stdout of the external command as input to the next command. To instead redirect the stderr of the external command, you can use the stderr pipe, `err>|` or `e>|`:
```nu
cat unknown.txt e>| str upcase
```
Of course, there is a corresponding pipe for combined stdout and stderr, `out+err>|` or `o+e>|`:
```nu
nu -c 'print output; print -e error' o+e>| str upcase
```
Unlike file redirections, pipe redirections do not apply to all commands inside an expression. Rather, only the last command in the expression is affected. For example, only `cmd2` in the snippet below will have its stdout and stderr redirected by the pipe.
```nu
(cmd1; cmd2) o+e>| cmd3
```
## Raw Streams
Both stdout and stderr are represented as "raw streams" inside of Nushell. These are streams of bytes rather than the structured data used by internal Nushell commands.
Because streams of bytes can be difficult to work with, especially given how common it is to use output as if it was text data, Nushell attempts to convert raw streams into text data. This allows other commands to pull on the output of external commands and receive strings they can further process.
Nushell attempts to convert to text using UTF-8. If at any time the conversion fails, the rest of the stream is assumed to always be bytes.
If you want more control over the decoding of the byte stream, you can use the [`decode`](/commands/docs/decode.md) command. The [`decode`](/commands/docs/decode.md) command can be inserted into the pipeline after the external, or other raw stream-creating command, and will handle decoding the bytes based on the argument you give decode. For example, you could decode shift-jis text this way:
```nu
0x[8a 4c] | decode shift-jis
# => 貝
```