日志
选择命令行版本:
See Details
目录
描述
¥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.
例如,如果你想将所有日志写入当前工作目录,你可以运行:npm install --logs-dir=.
。这对于调试特定的 npm
问题特别有用,因为你可以使用不同的配置值多次运行命令,然后比较所有日志文件。
¥For 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 a command multiple times with different config values and then diff all the log files.
当日志文件数量超过 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"
-
"info"
-
"verbose"
-
"silly"
将显示与进行当前设置的级别有关的所有日志。
¥All logs pertaining to a level proceeding the current setting will be shown.