1LOGGING(7) LOGGING(7)
2
3
4
6 Logging - Why, What & How We Log
7
8 Description
9 The npm CLI has various mechanisms for showing different levels of in‐
10 formation back to end-users for certain commands, configurations & en‐
11 vironments.
12
13 Setting Log File Location
14 All logs are written to a debug log, with the path to that file printed
15 if the execution of a command fails.
16
17 The default location of the logs directory is a directory named _logs
18 inside the npm cache. This can be changed with the logs-dir config op‐
19 tion.
20
21 For example, if you wanted to write all your logs to the current work‐
22 ing directory, you could run: npm install --logs-dir=.. This is espe‐
23 cially helpful in debugging a specific npm issue as you can run a com‐
24 mand multiple times with different config values and then diff all the
25 log files.
26
27 Log files will be removed from the logs-dir when the number of log
28 files exceeds logs-max, with the oldest logs being deleted first.
29
30 To turn off logs completely set --logs-max=0.
31
32 Setting Log Levels
33 loglevel
34 loglevel is a global argument/config that can be set to determine the
35 type of information to be displayed.
36
37 The default value of loglevel is "notice" but there are several lev‐
38 els/types of logs available, including:
39
40 • "silent"
41
42 • "error"
43
44 • "warn"
45
46 • "notice"
47
48 • "http"
49
50 • "info"
51
52 • "verbose"
53
54 • "silly"
55
56
57 All logs pertaining to a level proceeding the current setting will be
58 shown.
59
60 Aliases
61 The log levels listed above have various corresponding aliases, includ‐
62 ing:
63
64 • -d: --loglevel info
65
66 • --dd: --loglevel verbose
67
68 • --verbose: --loglevel verbose
69
70 • --ddd: --loglevel silly
71
72 • -q: --loglevel warn
73
74 • --quiet: --loglevel warn
75
76 • -s: --loglevel silent
77
78 • --silent: --loglevel silent
79
80
81 foreground-scripts
82 The npm CLI began hiding the output of lifecycle scripts for npm in‐
83 stall as of v7. Notably, this means you will not see logs/output from
84 packages that may be using "install scripts" to display information
85 back to you or from your own project's scripts defined in package.json.
86 If you'd like to change this behavior & log this output you can set
87 foreground-scripts to true.
88
89 Timing Information
90 The --timing config ⟨/using-npm/config#timing⟩ can be set which does a
91 few things:
92
93 1. Always shows the full path to the debug log regardless of command
94 exit status
95
96 2. Write timing information to a process specific timing file in the
97 cache or logs-dir
98
99 3. Output timing information to the terminal
100
101
102 This file contains a timers object where the keys are an identifier for
103 the portion of the process being timed and the value is the number of
104 milliseconds it took to complete.
105
106 Sometimes it is helpful to get timing information without outputting
107 anything to the terminal. For example, the performance might be af‐
108 fected by writing to the terminal. In this case you can use --timing
109 --silent which will still write the timing file, but not output any‐
110 thing to the terminal while running.
111
112 Registry Response Headers
113 npm-notice
114 The npm CLI reads from & logs any npm-notice headers that are returned
115 from the configured registry. This mechanism can be used by third-party
116 registries to provide useful information when network-dependent re‐
117 quests occur.
118
119 This header is not cached, and will not be logged if the request is
120 served from the cache.
121
122 Logs and Sensitive Information
123 The npm CLI makes a best effort to redact the following from terminal
124 output and log files:
125
126 • Passwords inside basic auth URLs
127
128 • npm tokens
129
130
131 However, this behavior should not be relied on to keep all possible
132 sensitive information redacted. If you are concerned about secrets in
133 your log file or terminal output, you can use --loglevel=silent and
134 --logs-max=0 to ensure no logs are written to your terminal or filesys‐
135 tem.
136
137 See also
138 • npm help config
139
140
141
142 November 2023 LOGGING(7)