11cb0ef41Sopenharmony_ci<!DOCTYPE html><html><head> 21cb0ef41Sopenharmony_ci<meta charset="utf-8"> 31cb0ef41Sopenharmony_ci<title>Logging</title> 41cb0ef41Sopenharmony_ci<style> 51cb0ef41Sopenharmony_cibody { 61cb0ef41Sopenharmony_ci background-color: #ffffff; 71cb0ef41Sopenharmony_ci color: #24292e; 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci margin: 0; 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci line-height: 1.5; 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; 141cb0ef41Sopenharmony_ci} 151cb0ef41Sopenharmony_ci#rainbar { 161cb0ef41Sopenharmony_ci height: 10px; 171cb0ef41Sopenharmony_ci background-image: linear-gradient(139deg, #fb8817, #ff4b01, #c12127, #e02aff); 181cb0ef41Sopenharmony_ci} 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cia { 211cb0ef41Sopenharmony_ci text-decoration: none; 221cb0ef41Sopenharmony_ci color: #0366d6; 231cb0ef41Sopenharmony_ci} 241cb0ef41Sopenharmony_cia:hover { 251cb0ef41Sopenharmony_ci text-decoration: underline; 261cb0ef41Sopenharmony_ci} 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_cipre { 291cb0ef41Sopenharmony_ci margin: 1em 0px; 301cb0ef41Sopenharmony_ci padding: 1em; 311cb0ef41Sopenharmony_ci border: solid 1px #e1e4e8; 321cb0ef41Sopenharmony_ci border-radius: 6px; 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci display: block; 351cb0ef41Sopenharmony_ci overflow: auto; 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci white-space: pre; 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci background-color: #f6f8fa; 401cb0ef41Sopenharmony_ci color: #393a34; 411cb0ef41Sopenharmony_ci} 421cb0ef41Sopenharmony_cicode { 431cb0ef41Sopenharmony_ci font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; 441cb0ef41Sopenharmony_ci font-size: 85%; 451cb0ef41Sopenharmony_ci padding: 0.2em 0.4em; 461cb0ef41Sopenharmony_ci background-color: #f6f8fa; 471cb0ef41Sopenharmony_ci color: #393a34; 481cb0ef41Sopenharmony_ci} 491cb0ef41Sopenharmony_cipre > code { 501cb0ef41Sopenharmony_ci padding: 0; 511cb0ef41Sopenharmony_ci background-color: inherit; 521cb0ef41Sopenharmony_ci color: inherit; 531cb0ef41Sopenharmony_ci} 541cb0ef41Sopenharmony_cih1, h2, h3 { 551cb0ef41Sopenharmony_ci font-weight: 600; 561cb0ef41Sopenharmony_ci} 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci#logobar { 591cb0ef41Sopenharmony_ci background-color: #333333; 601cb0ef41Sopenharmony_ci margin: 0 auto; 611cb0ef41Sopenharmony_ci padding: 1em 4em; 621cb0ef41Sopenharmony_ci} 631cb0ef41Sopenharmony_ci#logobar .logo { 641cb0ef41Sopenharmony_ci float: left; 651cb0ef41Sopenharmony_ci} 661cb0ef41Sopenharmony_ci#logobar .title { 671cb0ef41Sopenharmony_ci font-weight: 600; 681cb0ef41Sopenharmony_ci color: #dddddd; 691cb0ef41Sopenharmony_ci float: left; 701cb0ef41Sopenharmony_ci margin: 5px 0 0 1em; 711cb0ef41Sopenharmony_ci} 721cb0ef41Sopenharmony_ci#logobar:after { 731cb0ef41Sopenharmony_ci content: ""; 741cb0ef41Sopenharmony_ci display: block; 751cb0ef41Sopenharmony_ci clear: both; 761cb0ef41Sopenharmony_ci} 771cb0ef41Sopenharmony_ci 781cb0ef41Sopenharmony_ci#content { 791cb0ef41Sopenharmony_ci margin: 0 auto; 801cb0ef41Sopenharmony_ci padding: 0 4em; 811cb0ef41Sopenharmony_ci} 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci#table_of_contents > h2 { 841cb0ef41Sopenharmony_ci font-size: 1.17em; 851cb0ef41Sopenharmony_ci} 861cb0ef41Sopenharmony_ci#table_of_contents ul:first-child { 871cb0ef41Sopenharmony_ci border: solid 1px #e1e4e8; 881cb0ef41Sopenharmony_ci border-radius: 6px; 891cb0ef41Sopenharmony_ci padding: 1em; 901cb0ef41Sopenharmony_ci background-color: #f6f8fa; 911cb0ef41Sopenharmony_ci color: #393a34; 921cb0ef41Sopenharmony_ci} 931cb0ef41Sopenharmony_ci#table_of_contents ul { 941cb0ef41Sopenharmony_ci list-style-type: none; 951cb0ef41Sopenharmony_ci padding-left: 1.5em; 961cb0ef41Sopenharmony_ci} 971cb0ef41Sopenharmony_ci#table_of_contents li { 981cb0ef41Sopenharmony_ci font-size: 0.9em; 991cb0ef41Sopenharmony_ci} 1001cb0ef41Sopenharmony_ci#table_of_contents li a { 1011cb0ef41Sopenharmony_ci color: #000000; 1021cb0ef41Sopenharmony_ci} 1031cb0ef41Sopenharmony_ci 1041cb0ef41Sopenharmony_ciheader.title { 1051cb0ef41Sopenharmony_ci border-bottom: solid 1px #e1e4e8; 1061cb0ef41Sopenharmony_ci} 1071cb0ef41Sopenharmony_ciheader.title > h1 { 1081cb0ef41Sopenharmony_ci margin-bottom: 0.25em; 1091cb0ef41Sopenharmony_ci} 1101cb0ef41Sopenharmony_ciheader.title > .description { 1111cb0ef41Sopenharmony_ci display: block; 1121cb0ef41Sopenharmony_ci margin-bottom: 0.5em; 1131cb0ef41Sopenharmony_ci line-height: 1; 1141cb0ef41Sopenharmony_ci} 1151cb0ef41Sopenharmony_ci 1161cb0ef41Sopenharmony_cifooter#edit { 1171cb0ef41Sopenharmony_ci border-top: solid 1px #e1e4e8; 1181cb0ef41Sopenharmony_ci margin: 3em 0 4em 0; 1191cb0ef41Sopenharmony_ci padding-top: 2em; 1201cb0ef41Sopenharmony_ci} 1211cb0ef41Sopenharmony_ci</style> 1221cb0ef41Sopenharmony_ci</head> 1231cb0ef41Sopenharmony_ci<body> 1241cb0ef41Sopenharmony_ci<div id="banner"> 1251cb0ef41Sopenharmony_ci<div id="rainbar"></div> 1261cb0ef41Sopenharmony_ci<div id="logobar"> 1271cb0ef41Sopenharmony_ci<svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700"> 1281cb0ef41Sopenharmony_ci<polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon> 1291cb0ef41Sopenharmony_ci<polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon> 1301cb0ef41Sopenharmony_ci</svg> 1311cb0ef41Sopenharmony_ci<div class="title"> 1321cb0ef41Sopenharmony_cinpm command-line interface 1331cb0ef41Sopenharmony_ci</div> 1341cb0ef41Sopenharmony_ci</div> 1351cb0ef41Sopenharmony_ci</div> 1361cb0ef41Sopenharmony_ci 1371cb0ef41Sopenharmony_ci<section id="content"> 1381cb0ef41Sopenharmony_ci<header class="title"> 1391cb0ef41Sopenharmony_ci<h1 id="logging">Logging</h1> 1401cb0ef41Sopenharmony_ci<span class="description">Why, What & How We Log</span> 1411cb0ef41Sopenharmony_ci</header> 1421cb0ef41Sopenharmony_ci 1431cb0ef41Sopenharmony_ci<section id="table_of_contents"> 1441cb0ef41Sopenharmony_ci<h2 id="table-of-contents">Table of contents</h2> 1451cb0ef41Sopenharmony_ci<div id="_table_of_contents"><ul><li><a href="#description">Description</a></li><li><a href="#setting-log-file-location">Setting Log File Location</a></li><li><a href="#setting-log-levels">Setting Log Levels</a></li><ul><li><a href="#loglevel"><code>loglevel</code></a></li><ul><li><a href="#aliases">Aliases</a></li></ul><li><a href="#foreground-scripts"><code>foreground-scripts</code></a></li></ul><li><a href="#timing-information">Timing Information</a></li><li><a href="#registry-response-headers">Registry Response Headers</a></li><ul><li><a href="#npm-notice"><code>npm-notice</code></a></li></ul><li><a href="#logs-and-sensitive-information">Logs and Sensitive Information</a></li><li><a href="#see-also">See also</a></li></ul></div> 1461cb0ef41Sopenharmony_ci</section> 1471cb0ef41Sopenharmony_ci 1481cb0ef41Sopenharmony_ci<div id="_content"><h3 id="description">Description</h3> 1491cb0ef41Sopenharmony_ci<p>The <code>npm</code> CLI has various mechanisms for showing different levels of information back to end-users for certain commands, configurations & environments.</p> 1501cb0ef41Sopenharmony_ci<h3 id="setting-log-file-location">Setting Log File Location</h3> 1511cb0ef41Sopenharmony_ci<p>All logs are written to a debug log, with the path to that file printed if the execution of a command fails.</p> 1521cb0ef41Sopenharmony_ci<p>The default location of the logs directory is a directory named <code>_logs</code> inside the npm cache. This can be changed with the <code>logs-dir</code> config option.</p> 1531cb0ef41Sopenharmony_ci<p>For example, if you wanted to write all your logs to the current working directory, you could run: <code>npm install --logs-dir=.</code>. This is especially helpful in debugging a specific <code>npm</code> issue as you can run 1541cb0ef41Sopenharmony_cia command multiple times with different config values and then diff all the log files.</p> 1551cb0ef41Sopenharmony_ci<p>Log files will be removed from the <code>logs-dir</code> when the number of log files exceeds <code>logs-max</code>, with the oldest logs being deleted first.</p> 1561cb0ef41Sopenharmony_ci<p>To turn off logs completely set <code>--logs-max=0</code>.</p> 1571cb0ef41Sopenharmony_ci<h3 id="setting-log-levels">Setting Log Levels</h3> 1581cb0ef41Sopenharmony_ci<h4 id="loglevel"><code>loglevel</code></h4> 1591cb0ef41Sopenharmony_ci<p><code>loglevel</code> is a global argument/config that can be set to determine the type of information to be displayed.</p> 1601cb0ef41Sopenharmony_ci<p>The default value of <code>loglevel</code> is <code>"notice"</code> but there are several levels/types of logs available, including:</p> 1611cb0ef41Sopenharmony_ci<ul> 1621cb0ef41Sopenharmony_ci<li><code>"silent"</code></li> 1631cb0ef41Sopenharmony_ci<li><code>"error"</code></li> 1641cb0ef41Sopenharmony_ci<li><code>"warn"</code></li> 1651cb0ef41Sopenharmony_ci<li><code>"notice"</code></li> 1661cb0ef41Sopenharmony_ci<li><code>"http"</code></li> 1671cb0ef41Sopenharmony_ci<li><code>"info"</code></li> 1681cb0ef41Sopenharmony_ci<li><code>"verbose"</code></li> 1691cb0ef41Sopenharmony_ci<li><code>"silly"</code></li> 1701cb0ef41Sopenharmony_ci</ul> 1711cb0ef41Sopenharmony_ci<p>All logs pertaining to a level proceeding the current setting will be shown.</p> 1721cb0ef41Sopenharmony_ci<h5 id="aliases">Aliases</h5> 1731cb0ef41Sopenharmony_ci<p>The log levels listed above have various corresponding aliases, including:</p> 1741cb0ef41Sopenharmony_ci<ul> 1751cb0ef41Sopenharmony_ci<li><code>-d</code>: <code>--loglevel info</code></li> 1761cb0ef41Sopenharmony_ci<li><code>--dd</code>: <code>--loglevel verbose</code></li> 1771cb0ef41Sopenharmony_ci<li><code>--verbose</code>: <code>--loglevel verbose</code></li> 1781cb0ef41Sopenharmony_ci<li><code>--ddd</code>: <code>--loglevel silly</code></li> 1791cb0ef41Sopenharmony_ci<li><code>-q</code>: <code>--loglevel warn</code></li> 1801cb0ef41Sopenharmony_ci<li><code>--quiet</code>: <code>--loglevel warn</code></li> 1811cb0ef41Sopenharmony_ci<li><code>-s</code>: <code>--loglevel silent</code></li> 1821cb0ef41Sopenharmony_ci<li><code>--silent</code>: <code>--loglevel silent</code></li> 1831cb0ef41Sopenharmony_ci</ul> 1841cb0ef41Sopenharmony_ci<h4 id="foreground-scripts"><code>foreground-scripts</code></h4> 1851cb0ef41Sopenharmony_ci<p>The <code>npm</code> CLI began hiding the output of lifecycle scripts for <code>npm install</code> as of <code>v7</code>. 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 <code>package.json</code>. If you'd like to change this behavior & log this output you can set <code>foreground-scripts</code> to <code>true</code>.</p> 1861cb0ef41Sopenharmony_ci<h3 id="timing-information">Timing Information</h3> 1871cb0ef41Sopenharmony_ci<p>The <a href="../using-npm/config#timing.html"><code>--timing</code> config</a> can be set which does a few 1881cb0ef41Sopenharmony_cithings:</p> 1891cb0ef41Sopenharmony_ci<ol> 1901cb0ef41Sopenharmony_ci<li>Always shows the full path to the debug log regardless of command exit status</li> 1911cb0ef41Sopenharmony_ci<li>Write timing information to a process specific timing file in the cache or <code>logs-dir</code></li> 1921cb0ef41Sopenharmony_ci<li>Output timing information to the terminal</li> 1931cb0ef41Sopenharmony_ci</ol> 1941cb0ef41Sopenharmony_ci<p>This file contains a <code>timers</code> object where the keys are an identifier for the 1951cb0ef41Sopenharmony_ciportion of the process being timed and the value is the number of milliseconds it took to complete.</p> 1961cb0ef41Sopenharmony_ci<p>Sometimes it is helpful to get timing information without outputting anything to the terminal. For 1971cb0ef41Sopenharmony_ciexample, the performance might be affected by writing to the terminal. In this case you can use 1981cb0ef41Sopenharmony_ci<code>--timing --silent</code> which will still write the timing file, but not output anything to the terminal 1991cb0ef41Sopenharmony_ciwhile running.</p> 2001cb0ef41Sopenharmony_ci<h3 id="registry-response-headers">Registry Response Headers</h3> 2011cb0ef41Sopenharmony_ci<h4 id="npm-notice"><code>npm-notice</code></h4> 2021cb0ef41Sopenharmony_ci<p>The <code>npm</code> CLI reads from & logs any <code>npm-notice</code> 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.</p> 2031cb0ef41Sopenharmony_ci<p>This header is not cached, and will not be logged if the request is served from the cache.</p> 2041cb0ef41Sopenharmony_ci<h3 id="logs-and-sensitive-information">Logs and Sensitive Information</h3> 2051cb0ef41Sopenharmony_ci<p>The <code>npm</code> CLI makes a best effort to redact the following from terminal output and log files:</p> 2061cb0ef41Sopenharmony_ci<ul> 2071cb0ef41Sopenharmony_ci<li>Passwords inside basic auth URLs</li> 2081cb0ef41Sopenharmony_ci<li>npm tokens</li> 2091cb0ef41Sopenharmony_ci</ul> 2101cb0ef41Sopenharmony_ci<p>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 <code>--loglevel=silent</code> and <code>--logs-max=0</code> to ensure no logs are written to your terminal or filesystem.</p> 2111cb0ef41Sopenharmony_ci<h3 id="see-also">See also</h3> 2121cb0ef41Sopenharmony_ci<ul> 2131cb0ef41Sopenharmony_ci<li><a href="../using-npm/config.html">config</a></li> 2141cb0ef41Sopenharmony_ci</ul></div> 2151cb0ef41Sopenharmony_ci 2161cb0ef41Sopenharmony_ci<footer id="edit"> 2171cb0ef41Sopenharmony_ci<a href="https://github.com/npm/cli/edit/latest/docs/content/using-npm/logging.md"> 2181cb0ef41Sopenharmony_ci<svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;"> 2191cb0ef41Sopenharmony_ci<path fill-rule="evenodd" d="M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L10.811 3.75l1.439 1.44 1.263-1.263a.25.25 0 000-.354l-1.086-1.086zM11.189 6.25L9.75 4.81l-6.286 6.287a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.249.249 0 00.108-.064l6.286-6.286z"></path> 2201cb0ef41Sopenharmony_ci</svg> 2211cb0ef41Sopenharmony_ciEdit this page on GitHub 2221cb0ef41Sopenharmony_ci</a> 2231cb0ef41Sopenharmony_ci</footer> 2241cb0ef41Sopenharmony_ci</section> 2251cb0ef41Sopenharmony_ci 2261cb0ef41Sopenharmony_ci 2271cb0ef41Sopenharmony_ci 2281cb0ef41Sopenharmony_ci</body></html>