目录
选择命令行版本:
目录
描述
¥Description
npm
CLI 具有多种机制,可针对某些命令、配置和环境向终端用户显示不同级别的信息。
¥The npm
CLI has various mechanisms for showing different levels of information back to end-users for certain commands, configurations & environments.
设置日志文件位置
¥Setting Log File Location
所有日志都写入调试日志,如果命令执行失败,则打印该文件的路径。
¥All logs are written to a debug log, with the path to that file printed if the execution of a command fails.
日志目录的默认位置是 npm 缓存中名为 _logs
的目录。这可以通过 logs-dir
配置选项进行更改。
¥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.
当日志文件数量超过 logs-max
时,日志文件将从 logs-dir
中删除,最旧的日志首先被删除。
¥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.
要完全关闭日志,请设置 --logs-max=0
。
¥To turn off logs completely set --logs-max=0
.
设置日志级别
¥Setting Log Levels
loglevel
loglevel
是一个全局参数/配置,可以设置它来确定要显示的信息类型。
¥loglevel
is a global argument/config that can be set to determine the type of information to be displayed.
loglevel
的默认值为 "notice"
,但有多种级别/类型的日志可用,包括:
¥The default value of loglevel
is "notice"
but there are several levels/types of logs available, including:
-
"silent"
-
"error"
-
"warn"
-
"notice"
-
"http"
-
"timing"
-
"info"
-
"verbose"
-
"silly"
将显示与进行当前设置的级别有关的所有日志。
¥All logs pertaining to a level proceeding the current setting will be shown.
别名
¥Aliases
上面列出的日志级别有各种对应的别名,包括:
¥The log levels listed above have various corresponding aliases, including:
-
-d
:--loglevel info
-
--dd
:--loglevel verbose
-
--verbose
:--loglevel verbose
-
--ddd
:--loglevel silly
-
-q
:--loglevel warn
-
--quiet
:--loglevel warn
-
-s
:--loglevel silent
-
--silent
:--loglevel silent
foreground-scripts
从 v7
开始,npm
CLI 开始隐藏 npm install
的生命周期脚本的输出。值得注意的是,这意味着你将看不到可能使用 "安装脚本" 向你显示信息的包的日志/输出,或者你自己在 package.json
中定义的项目脚本的日志/输出。如果你想更改此行为并记录此输出,你可以将 foreground-scripts
设置为 true
。
¥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
.
时间信息
¥Timing Information
--timing
配置可以设置做两件事:
¥The --timing
config can be set which does two things:
-
无论命令退出状态如何,始终显示调试日志的完整路径
¥Always shows the full path to the debug log regardless of command exit status
-
将时序信息写入缓存或
logs-dir
中的时序文件¥Write timing information to a timing file in the cache or
logs-dir
此文件是 JSON 对象的换行符分隔列表,可以检查这些对象以查看 npm
CLI 运行中每个任务的计时数据。
¥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.
注册表响应标头
¥Registry Response Headers
npm-notice
npm
CLI 读取并记录从配置的注册表返回的任何 npm-notice
标头。第三方注册机构可以使用此机制在发生网络相关请求时提供有用的信息。
¥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.
此标头未缓存,如果请求是从缓存中提供的,则不会记录。
¥This header is not cached, and will not be logged if the request is served from the cache.
日志和敏感信息
¥Logs and Sensitive Information
npm
CLI 尽最大努力从终端输出和日志文件中编辑以下内容:
¥The npm
CLI makes a best effort to redact the following from terminal output and log files:
-
基本身份验证 URL 中的密码
¥Passwords inside basic auth URLs
-
npm 令牌
¥npm tokens
但是,不应依赖此行为来编辑所有可能的敏感信息。如果你担心日志文件或终端输出中的秘密,你可以使用 --loglevel=silent
和 --logs-max=0
来确保没有日志写入你的终端或文件系统。
¥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.
也可以看看
¥See also