dependabot/npm_and_yarn/main/eslint-10.4.0
@reggi/path-to-regexp
dependabot/npm_and_yarn/main/copy-to-clipboard-4.0.2
dependabot/npm_and_yarn/main/eslint-10.4.0
dependabot/npm_and_yarn/main/npmcli/eslint-config-7.0.0
dependabot/npm_and_yarn/main/proc-log-7.0.0
dependabot/npm_and_yarn/npm_and_yarn-826852524d
dependabot/npm_and_yarn/npm_and_yarn-ab9a7f4bc2
deprecate-totp-2fa
dhei/classic-tokens
gat-bypass-2fa-docs
jpg619/fix-accessibility-content-flow
jpg619/version-bump-tar-2
kartykp/gat-bypass-2fa-docs
kartykp/upgrade-path-to-regex
main
maitxn/version-bump-tar
patch-1
reggi/cache-based-on-version
reggi/dev-engines
reggi/fix-transform-prettier
reggi/overrides
update-search-sensitivity
| 1 | --- |
| 2 | title: Logging |
| 3 | section: 7 |
| 4 | description: Why, What & How We Log |
| 5 | github_repo: npm/cli |
| 6 | github_branch: release/v8 |
| 7 | github_path: docs/lib/content/using-npm/logging.md |
| 8 | redirect_from: |
| 9 | - /cli-documentation/v8/misc/logging |
| 10 | - /cli-documentation/v8/using-npm/logging |
| 11 | - /cli/v8/misc/logging |
| 12 | --- |
| 13 | |
| 14 | ### Description |
| 15 | |
| 16 | The `npm` CLI has various mechanisms for showing different levels of information back to end-users for certain commands, configurations & environments. |
| 17 | |
| 18 | ### Setting Log File Location |
| 19 | |
| 20 | All logs are written to a debug log, with the path to that file printed if the execution of a command fails. |
| 21 | |
| 22 | The default location of the logs directory is a directory named `_logs` inside the npm cache. This can be changed with the `logs-dir` config option. |
| 23 | |
| 24 | Log files will be removed from the `logs-dir` when the number of log files exceeds `logs-max`, with the oldest logs being deleted first. |
| 25 | |
| 26 | To turn off logs completely set `--logs-max=0`. |
| 27 | |
| 28 | ### Setting Log Levels |
| 29 | |
| 30 | #### `loglevel` |
| 31 | |
| 32 | `loglevel` is a global argument/config that can be set to determine the type of information to be displayed. |
| 33 | |
| 34 | The default value of `loglevel` is `"notice"` but there are several levels/types of logs available, including: |
| 35 | |
| 36 | - `"silent"` |
| 37 | - `"error"` |
| 38 | - `"warn"` |
| 39 | - `"notice"` |
| 40 | - `"http"` |
| 41 | - `"timing"` |
| 42 | - `"info"` |
| 43 | - `"verbose"` |
| 44 | - `"silly"` |
| 45 | |
| 46 | All logs pertaining to a level proceeding the current setting will be shown. |
| 47 | |
| 48 | ##### Aliases |
| 49 | |
| 50 | The log levels listed above have various corresponding aliases, including: |
| 51 | |
| 52 | - `-d`: `--loglevel info` |
| 53 | - `--dd`: `--loglevel verbose` |
| 54 | - `--verbose`: `--loglevel verbose` |
| 55 | - `--ddd`: `--loglevel silly` |
| 56 | - `-q`: `--loglevel warn` |
| 57 | - `--quiet`: `--loglevel warn` |
| 58 | - `-s`: `--loglevel silent` |
| 59 | - `--silent`: `--loglevel silent` |
| 60 | |
| 61 | #### `foreground-scripts` |
| 62 | |
| 63 | 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`. |
| 64 | |
| 65 | ### Timing Information |
| 66 | |
| 67 | The `--timing` config can be set which does two things: |
| 68 | |
| 69 | 1. Always shows the full path to the debug log regardless of command exit status |
| 70 | 1. Write timing information to a timing file in the cache or `logs-dir` |
| 71 | |
| 72 | This file is a newline delimited list of JSON objects that can be inspected to see timing data for each task in a `npm` CLI run. |
| 73 | |
| 74 | ### Registry Response Headers |
| 75 | |
| 76 | #### `npm-notice` |
| 77 | |
| 78 | 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. |
| 79 | |
| 80 | This header is not cached, and will not be logged if the request is served from the cache. |
| 81 | |
| 82 | ### Logs and Sensitive Information |
| 83 | |
| 84 | The `npm` CLI makes a best effort to redact the following from terminal output and log files: |
| 85 | |
| 86 | - Passwords inside basic auth URLs |
| 87 | - npm tokens |
| 88 | |
| 89 | However, this behavior should not be relied on to keep all possible sensitive information redacted. If you are concerned about secrets in your log file or terminal output, you can use `--loglevel=silent` and `--logs-max=0` to ensure no logs are written to your terminal or filesystem. |
| 90 | |
| 91 | ### See also |
| 92 | |
| 93 | - [config](/cli/v8/using-npm/config) |