codekingpro/portable-devtools
115k
1---
2title: Logging
3section: 7
4description: Why, What & How we Log
5---
6
7### Description
8
9The `npm` CLI has various mechanisms for showing different levels of information back to end-users for certain commands, configurations & environments.
10
11### Setting Log File Location
12
13All logs are written to a debug log, with the path to that file printed if the execution of a command fails.
14
15The default location of the logs directory is a directory named `_logs` inside the npm cache.
16This can be changed with the `logs-dir` config option.
17
18For example, if you wanted to write all your logs to the current working directory, you could run: `npm install --logs-dir=.`.
19This is especially helpful in debugging a specific `npm` issue as you can run a command multiple times with different config values and then diff all the log files.
20
21Log files will be removed from the `logs-dir` when the number of log files exceeds `logs-max`, with the oldest logs being deleted first.
22
23To turn off logs completely set `--logs-max=0`.
24
25### Setting Log Levels
26
27#### `loglevel`
28
29`loglevel` is a global argument/config that can be set to determine the type of information to be displayed.
30
31The default value of `loglevel` is `"notice"` but there are several levels/types of logs available, including:
32
33- `"silent"`
34- `"error"`
35- `"warn"`
36- `"notice"`
37- `"http"`
38- `"info"`
39- `"verbose"`
40- `"silly"`
41
42All logs pertaining to a level preceding the current setting will be shown.
43
44##### Aliases
45
46The log levels listed above have various corresponding aliases, including:
47
48- `-d`: `--loglevel info`
49- `--dd`: `--loglevel verbose`
50- `--verbose`: `--loglevel verbose`
51- `--ddd`: `--loglevel silly`
52- `-q`: `--loglevel warn`
53- `--quiet`: `--loglevel warn`
54- `-s`: `--loglevel silent`
55- `--silent`: `--loglevel silent`
56
57#### `foreground-scripts`
58
59The `npm` CLI began hiding the output of lifecycle scripts for `npm install` as of `v7`.
60Notably, 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`.
61If you'd like to change this behavior & log this output you can set `foreground-scripts` to `true`.
62
63### Timing Information
64
65The [`--timing` config](/using-npm/config#timing) can be set which does a few things:
66
671. Always shows the full path to the debug log regardless of command exit status
681. Write timing information to a process specific timing file in the cache or `logs-dir`
691. Output timing information to the terminal
70
71This file contains a `timers` object where the keys are an identifier for the portion of the process being timed and the value is the number of milliseconds it took to complete.
72
73Sometimes it is helpful to get timing information without outputting anything to the terminal.
74For example, the performance might be affected by writing to the terminal.
75In this case you can use
76`--timing --silent` which will still write the timing file, but not output anything to the terminal while running.
77
78### Registry Response Headers
79
80#### `npm-notice`
81
82The `npm` CLI reads from & logs any `npm-notice` headers that are returned from the configured registry.
83This mechanism can be used by third-party registries to provide useful information when network-dependent requests occur.
84
85This header is not cached, and will not be logged if the request is served from the cache.
86
87### Logs and Sensitive Information
88
89The `npm` CLI makes a best effort to redact the following from terminal output and log files:
90
91- Passwords inside basic auth URLs
92- npm tokens
93
94However, this behavior should not be relied on to keep all possible sensitive information redacted.
95If 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.
96
97### See also
98
99* [config](/using-npm/config)
100 