11cb0ef41Sopenharmony_ci---
21cb0ef41Sopenharmony_cititle: Logging
31cb0ef41Sopenharmony_cisection: 7
41cb0ef41Sopenharmony_cidescription: Why, What & How We Log
51cb0ef41Sopenharmony_ci---
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci### Description
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciThe `npm` CLI has various mechanisms for showing different levels of information back to end-users for certain commands, configurations & environments.
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci### Setting Log File Location
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciAll logs are written to a debug log, with the path to that file printed if the execution of a command fails.
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciThe 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.
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciFor example, if you wanted to write all your logs to the current working directory, you could run: `npm install --logs-dir=.`.  This is especially helpful in debugging a specific `npm` issue as you can run
181cb0ef41Sopenharmony_cia command multiple times with different config values and then diff all the log files.
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciLog files will be removed from the `logs-dir` when the number of log files exceeds `logs-max`, with the oldest logs being deleted first.
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ciTo turn off logs completely set `--logs-max=0`.
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci### Setting Log Levels
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci#### `loglevel`
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci`loglevel` is a global argument/config that can be set to determine the type of information to be displayed.
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ciThe default value of `loglevel` is `"notice"` but there are several levels/types of logs available, including:
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci- `"silent"`
331cb0ef41Sopenharmony_ci- `"error"`
341cb0ef41Sopenharmony_ci- `"warn"`
351cb0ef41Sopenharmony_ci- `"notice"`
361cb0ef41Sopenharmony_ci- `"http"`
371cb0ef41Sopenharmony_ci- `"info"`
381cb0ef41Sopenharmony_ci- `"verbose"`
391cb0ef41Sopenharmony_ci- `"silly"`
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ciAll logs pertaining to a level proceeding the current setting will be shown.
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci##### Aliases
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ciThe log levels listed above have various corresponding aliases, including:
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci- `-d`: `--loglevel info`
481cb0ef41Sopenharmony_ci- `--dd`: `--loglevel verbose`
491cb0ef41Sopenharmony_ci- `--verbose`: `--loglevel verbose`
501cb0ef41Sopenharmony_ci- `--ddd`: `--loglevel silly`
511cb0ef41Sopenharmony_ci- `-q`: `--loglevel warn`
521cb0ef41Sopenharmony_ci- `--quiet`: `--loglevel warn`
531cb0ef41Sopenharmony_ci- `-s`: `--loglevel silent`
541cb0ef41Sopenharmony_ci- `--silent`: `--loglevel silent`
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci#### `foreground-scripts`
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ciThe `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`.
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci### Timing Information
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ciThe [`--timing` config](/using-npm/config#timing) can be set which does a few
631cb0ef41Sopenharmony_cithings:
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci1. Always shows the full path to the debug log regardless of command exit status
661cb0ef41Sopenharmony_ci1. Write timing information to a process specific timing file in the cache or `logs-dir`
671cb0ef41Sopenharmony_ci1. Output timing information to the terminal
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ciThis file contains a `timers` object where the keys are an identifier for the
701cb0ef41Sopenharmony_ciportion of the process being timed and the value is the number of milliseconds it took to complete.
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ciSometimes it is helpful to get timing information without outputting anything to the terminal. For
731cb0ef41Sopenharmony_ciexample, the performance might be affected by writing to the terminal. In this case you can use
741cb0ef41Sopenharmony_ci`--timing --silent` which will still write the timing file, but not output anything to the terminal
751cb0ef41Sopenharmony_ciwhile running.
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ci### Registry Response Headers
781cb0ef41Sopenharmony_ci
791cb0ef41Sopenharmony_ci#### `npm-notice`
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ciThe `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.
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ciThis header is not cached, and will not be logged if the request is served from the cache.
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_ci### Logs and Sensitive Information
861cb0ef41Sopenharmony_ci
871cb0ef41Sopenharmony_ciThe `npm` CLI makes a best effort to redact the following from terminal output and log files:
881cb0ef41Sopenharmony_ci
891cb0ef41Sopenharmony_ci- Passwords inside basic auth URLs
901cb0ef41Sopenharmony_ci- npm tokens
911cb0ef41Sopenharmony_ci
921cb0ef41Sopenharmony_ciHowever, 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.
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_ci### See also
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_ci* [config](/using-npm/config)
97