|
| 1 | +--- |
| 2 | +title: Logging |
| 3 | +section: 7 |
| 4 | +description: Why, What & How we Log |
| 5 | +--- |
| 6 | + |
| 7 | +### Description |
| 8 | + |
| 9 | +The `npm` CLI has various mechanisms for showing different levels of information back to end-users for certain commands, configurations & environments. |
| 10 | + |
| 11 | +### Setting Log Levels |
| 12 | + |
| 13 | +#### `loglevel` |
| 14 | + |
| 15 | +`loglevel` is a global argument/config that can be set to determine the type of information to be displayed. |
| 16 | + |
| 17 | +The default value of `loglevel` is `"notice"` but there are several levels/types of logs available, including: |
| 18 | + |
| 19 | +- `"silent"` |
| 20 | +- `"error"` |
| 21 | +- `"warn"` |
| 22 | +- `"notice"` |
| 23 | +- `"http"` |
| 24 | +- `"timing"` |
| 25 | +- `"info"` |
| 26 | +- `"verbose"` |
| 27 | +- `"silly"` |
| 28 | + |
| 29 | +All logs pertaining to a level proceeding the current setting will be shown. |
| 30 | + |
| 31 | +All logs are written to a debug log, with the path to that file printed if the execution of a command fails. |
| 32 | + |
| 33 | +##### Aliases |
| 34 | + |
| 35 | +The log levels listed above have various corresponding aliases, including: |
| 36 | + |
| 37 | +- `-d`: `--loglevel info` |
| 38 | +- `--dd`: `--loglevel verbose` |
| 39 | +- `--verbose`: `--loglevel verbose` |
| 40 | +- `--ddd`: `--loglevel silly` |
| 41 | +- `-q`: `--loglevel warn` |
| 42 | +- `--quiet`: `--loglevel warn` |
| 43 | +- `-s`: `--loglevel silent` |
| 44 | +- `--silent`: `--loglevel silent` |
| 45 | + |
| 46 | +#### `foreground-scripts` |
| 47 | + |
| 48 | +The `npm` CLI began hiding the output of lifecycle scripts for `npm install` as of `v7`. Notably, this means you will not see logs/output from packages that may be using "install scripts" to display information back to you or from your own project's scripts defined in `package.json`. If you'd like to change this behavior & log this output you can set `foreground-scripts` to `true`. |
| 49 | + |
| 50 | +### Registry Response Headers |
| 51 | + |
| 52 | +#### `npm-notice` |
| 53 | + |
| 54 | +The `npm` CLI reads from & logs any `npm-notice` headers that are returned from the configured registry. This mechanism can be used by third-party registries to provide useful information when network-dependent requests occur. |
| 55 | + |
| 56 | +This header is not cached, and will not be logged if the request is served from the cache. |
| 57 | + |
| 58 | +### See also |
| 59 | + |
| 60 | +* [config](/using-npm/config) |
0 commit comments