diff options
author | Luke Karrys <luke@lukekarrys.com> | 2022-03-19 07:31:37 +0300 |
---|---|---|
committer | Nathan Fritz <fritzy@github.com> | 2022-03-24 23:21:44 +0300 |
commit | cc6c09431d7fe2db8ac1dc7a707f2dab7a7a1f83 (patch) | |
tree | 834f053afb6dc6ddf1ab4e36a6a5e8e9f4c8124b /tap-snapshots | |
parent | 81afa5a8838c71a3a5037e2c8b4ae196e19fe0d7 (diff) |
feat: add logs-dir config to set custom logging location
This also allows logs-max to be set to 0 to disable log file writing.
Closes #4466
Closes #4206
Diffstat (limited to 'tap-snapshots')
6 files changed, 222 insertions, 86 deletions
diff --git a/tap-snapshots/test/lib/commands/config.js.test.cjs b/tap-snapshots/test/lib/commands/config.js.test.cjs index 0806c68ca..f98e74c06 100644 --- a/tap-snapshots/test/lib/commands/config.js.test.cjs +++ b/tap-snapshots/test/lib/commands/config.js.test.cjs @@ -89,6 +89,7 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna "location": "user", "lockfile-version": null, "loglevel": "notice", + "logs-dir": null, "logs-max": 10, "long": false, "maxsockets": 15, @@ -242,6 +243,7 @@ local-address = null location = "user" lockfile-version = null loglevel = "notice" +logs-dir = null logs-max = 10 ; long = false ; overridden by cli maxsockets = 15 diff --git a/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs b/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs index 4d3a6f150..d7c430802 100644 --- a/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs +++ b/tap-snapshots/test/lib/utils/config/definitions.js.test.cjs @@ -85,6 +85,7 @@ Array [ "location", "lockfile-version", "loglevel", + "logs-dir", "logs-max", "long", "maxsockets", @@ -1099,6 +1100,16 @@ Any logs of a higher level than the setting are shown. The default is See also the \`foreground-scripts\` config. ` +exports[`test/lib/utils/config/definitions.js TAP > config description for logs-dir 1`] = ` +#### \`logs-dir\` + +* Default: A directory named \`_logs\` inside the cache +* Type: null or Path + +The location of npm's log directory. See [\`npm logging\`](/using-npm/logging) +for more information. +` + exports[`test/lib/utils/config/definitions.js TAP > config description for logs-max 1`] = ` #### \`logs-max\` @@ -1106,6 +1117,8 @@ exports[`test/lib/utils/config/definitions.js TAP > config description for logs- * Type: Number The maximum number of log files to store. + +If set to 0, no log files will be written for the current run. ` exports[`test/lib/utils/config/definitions.js TAP > config description for long 1`] = ` @@ -1721,9 +1734,9 @@ exports[`test/lib/utils/config/definitions.js TAP > config description for timin * Default: false * Type: Boolean -If true, writes an \`npm-debug\` log to \`_logs\` and timing information to -\`_timing.json\`, both in your cache, even if the command completes -successfully. \`_timing.json\` is a newline delimited list of JSON objects. +If true, writes a debug log to \`logs-dir\` and timing information to +\`_timing.json\` in the cache, even if the command completes successfully. +\`_timing.json\` is a newline delimited list of JSON objects. You can quickly view it with this [json](https://npm.im/json) command line: \`npm exec -- json -g < ~/.npm/_timing.json\`. diff --git a/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs b/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs index 94ddbe2b1..2647bc31b 100644 --- a/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs +++ b/tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs @@ -901,6 +901,17 @@ See also the \`foreground-scripts\` config. <!-- automatically generated, do not edit manually --> <!-- see lib/utils/config/definitions.js --> +#### \`logs-dir\` + +* Default: A directory named \`_logs\` inside the cache +* Type: null or Path + +The location of npm's log directory. See [\`npm logging\`](/using-npm/logging) +for more information. + +<!-- automatically generated, do not edit manually --> +<!-- see lib/utils/config/definitions.js --> + #### \`logs-max\` * Default: 10 @@ -908,6 +919,8 @@ See also the \`foreground-scripts\` config. The maximum number of log files to store. +If set to 0, no log files will be written for the current run. + <!-- automatically generated, do not edit manually --> <!-- see lib/utils/config/definitions.js --> @@ -1502,9 +1515,9 @@ particular, use care when overriding this setting for public packages. * Default: false * Type: Boolean -If true, writes an \`npm-debug\` log to \`_logs\` and timing information to -\`_timing.json\`, both in your cache, even if the command completes -successfully. \`_timing.json\` is a newline delimited list of JSON objects. +If true, writes a debug log to \`logs-dir\` and timing information to +\`_timing.json\` in the cache, even if the command completes successfully. +\`_timing.json\` is a newline delimited list of JSON objects. You can quickly view it with this [json](https://npm.im/json) command line: \`npm exec -- json -g < ~/.npm/_timing.json\`. diff --git a/tap-snapshots/test/lib/utils/error-message.js.test.cjs b/tap-snapshots/test/lib/utils/error-message.js.test.cjs index 6316f04fd..8e772e869 100644 --- a/tap-snapshots/test/lib/utils/error-message.js.test.cjs +++ b/tap-snapshots/test/lib/utils/error-message.js.test.cjs @@ -500,6 +500,18 @@ Object { exports[`test/lib/utils/error-message.js TAP eacces/eperm {"windows":false,"loaded":true,"cachePath":false,"cacheDest":false} > must match snapshot 2`] = ` Array [ Array [ + "title", + "npm", + ], + Array [ + "argv", + "", + ], + Array [ + "logfile", + "logs-max:10 dir:{CWD}/test/lib/utils/tap-testdir-error-message-eacces-eperm--windows-false-loaded-true-cachePath-false-cacheDest-false-/cache/_logs", + ], + Array [ "logfile", "{CWD}/test/lib/utils/tap-testdir-error-message-eacces-eperm--windows-false-loaded-true-cachePath-false-cacheDest-false-/cache/_logs/{DATE}-debug-0.log", ], @@ -528,6 +540,18 @@ Object { exports[`test/lib/utils/error-message.js TAP eacces/eperm {"windows":false,"loaded":true,"cachePath":false,"cacheDest":true} > must match snapshot 2`] = ` Array [ Array [ + "title", + "npm", + ], + Array [ + "argv", + "", + ], + Array [ + "logfile", + "logs-max:10 dir:{CWD}/test/lib/utils/tap-testdir-error-message-eacces-eperm--windows-false-loaded-true-cachePath-false-cacheDest-true-/cache/_logs", + ], + Array [ "logfile", "{CWD}/test/lib/utils/tap-testdir-error-message-eacces-eperm--windows-false-loaded-true-cachePath-false-cacheDest-true-/cache/_logs/{DATE}-debug-0.log", ], @@ -559,6 +583,18 @@ Object { exports[`test/lib/utils/error-message.js TAP eacces/eperm {"windows":false,"loaded":true,"cachePath":true,"cacheDest":false} > must match snapshot 2`] = ` Array [ Array [ + "title", + "npm", + ], + Array [ + "argv", + "", + ], + Array [ + "logfile", + "logs-max:10 dir:{CWD}/test/lib/utils/tap-testdir-error-message-eacces-eperm--windows-false-loaded-true-cachePath-true-cacheDest-false-/cache/_logs", + ], + Array [ "logfile", "{CWD}/test/lib/utils/tap-testdir-error-message-eacces-eperm--windows-false-loaded-true-cachePath-true-cacheDest-false-/cache/_logs/{DATE}-debug-0.log", ], @@ -590,6 +626,18 @@ Object { exports[`test/lib/utils/error-message.js TAP eacces/eperm {"windows":false,"loaded":true,"cachePath":true,"cacheDest":true} > must match snapshot 2`] = ` Array [ Array [ + "title", + "npm", + ], + Array [ + "argv", + "", + ], + Array [ + "logfile", + "logs-max:10 dir:{CWD}/test/lib/utils/tap-testdir-error-message-eacces-eperm--windows-false-loaded-true-cachePath-true-cacheDest-true-/cache/_logs", + ], + Array [ "logfile", "{CWD}/test/lib/utils/tap-testdir-error-message-eacces-eperm--windows-false-loaded-true-cachePath-true-cacheDest-true-/cache/_logs/{DATE}-debug-0.log", ], @@ -768,6 +816,18 @@ Object { exports[`test/lib/utils/error-message.js TAP eacces/eperm {"windows":true,"loaded":true,"cachePath":false,"cacheDest":false} > must match snapshot 2`] = ` Array [ Array [ + "title", + "npm", + ], + Array [ + "argv", + "", + ], + Array [ + "logfile", + "logs-max:10 dir:{CWD}/test/lib/utils/tap-testdir-error-message-eacces-eperm--windows-true-loaded-true-cachePath-false-cacheDest-false-/cache/_logs", + ], + Array [ "logfile", "{CWD}/test/lib/utils/tap-testdir-error-message-eacces-eperm--windows-true-loaded-true-cachePath-false-cacheDest-false-/cache/_logs/{DATE}-debug-0.log", ], @@ -807,6 +867,18 @@ Object { exports[`test/lib/utils/error-message.js TAP eacces/eperm {"windows":true,"loaded":true,"cachePath":false,"cacheDest":true} > must match snapshot 2`] = ` Array [ Array [ + "title", + "npm", + ], + Array [ + "argv", + "", + ], + Array [ + "logfile", + "logs-max:10 dir:{CWD}/test/lib/utils/tap-testdir-error-message-eacces-eperm--windows-true-loaded-true-cachePath-false-cacheDest-true-/cache/_logs", + ], + Array [ "logfile", "{CWD}/test/lib/utils/tap-testdir-error-message-eacces-eperm--windows-true-loaded-true-cachePath-false-cacheDest-true-/cache/_logs/{DATE}-debug-0.log", ], @@ -846,6 +918,18 @@ Object { exports[`test/lib/utils/error-message.js TAP eacces/eperm {"windows":true,"loaded":true,"cachePath":true,"cacheDest":false} > must match snapshot 2`] = ` Array [ Array [ + "title", + "npm", + ], + Array [ + "argv", + "", + ], + Array [ + "logfile", + "logs-max:10 dir:{CWD}/test/lib/utils/tap-testdir-error-message-eacces-eperm--windows-true-loaded-true-cachePath-true-cacheDest-false-/cache/_logs", + ], + Array [ "logfile", "{CWD}/test/lib/utils/tap-testdir-error-message-eacces-eperm--windows-true-loaded-true-cachePath-true-cacheDest-false-/cache/_logs/{DATE}-debug-0.log", ], @@ -885,6 +969,18 @@ Object { exports[`test/lib/utils/error-message.js TAP eacces/eperm {"windows":true,"loaded":true,"cachePath":true,"cacheDest":true} > must match snapshot 2`] = ` Array [ Array [ + "title", + "npm", + ], + Array [ + "argv", + "", + ], + Array [ + "logfile", + "logs-max:10 dir:{CWD}/test/lib/utils/tap-testdir-error-message-eacces-eperm--windows-true-loaded-true-cachePath-true-cacheDest-true-/cache/_logs", + ], + Array [ "logfile", "{CWD}/test/lib/utils/tap-testdir-error-message-eacces-eperm--windows-true-loaded-true-cachePath-true-cacheDest-true-/cache/_logs/{DATE}-debug-0.log", ], diff --git a/tap-snapshots/test/lib/utils/exit-handler.js.test.cjs b/tap-snapshots/test/lib/utils/exit-handler.js.test.cjs index 0aaf235fd..edb7edaa5 100644 --- a/tap-snapshots/test/lib/utils/exit-handler.js.test.cjs +++ b/tap-snapshots/test/lib/utils/exit-handler.js.test.cjs @@ -9,44 +9,54 @@ exports[`test/lib/utils/exit-handler.js TAP handles unknown error with logs and 0 timing npm:load:whichnode Completed in {TIME}ms 15 timing config:load Completed in {TIME}ms 16 timing npm:load:configload Completed in {TIME}ms -17 timing npm:load:setTitle Completed in {TIME}ms -19 timing npm:load:display Completed in {TIME}ms -20 verbose logfile {CWD}/test/lib/utils/tap-testdir-exit-handler-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-debug-0.log -21 timing npm:load:logFile Completed in {TIME}ms -22 timing npm:load:timers Completed in {TIME}ms -23 timing npm:load:configScope Completed in {TIME}ms -24 timing npm:load Completed in {TIME}ms -25 verbose stack Error: Unknown error -26 verbose cwd {CWD} -27 verbose Foo 1.0.0 -28 verbose argv "/node" "{CWD}/test/lib/utils/exit-handler.js" -29 verbose node v1.0.0 -30 verbose npm v1.0.0 -31 error code ECODE -32 error ERR SUMMARY Unknown error -33 error ERR DETAIL Unknown error -34 verbose exit 1 -36 timing npm Completed in {TIME}ms -37 verbose code 1 -38 error A complete log of this run can be found in: -38 error {CWD}/test/lib/utils/tap-testdir-exit-handler-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-debug-0.log +17 timing npm:load:mkdirpcache Completed in {TIME}ms +18 timing npm:load:mkdirplogs Completed in {TIME}ms +19 verbose title npm +20 verbose argv +21 timing npm:load:setTitle Completed in {TIME}ms +23 timing npm:load:display Completed in {TIME}ms +24 verbose logfile logs-max:10 dir:{CWD}/test/lib/utils/tap-testdir-exit-handler-handles-unknown-error-with-logs-and-debug-file/cache/_logs +25 verbose logfile {CWD}/test/lib/utils/tap-testdir-exit-handler-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-debug-0.log +26 timing npm:load:logFile Completed in {TIME}ms +27 timing npm:load:timers Completed in {TIME}ms +28 timing npm:load:configScope Completed in {TIME}ms +29 timing npm:load Completed in {TIME}ms +30 silly logfile done cleaning log files +31 verbose stack Error: Unknown error +32 verbose cwd {CWD} +33 verbose Foo 1.0.0 +34 verbose node v1.0.0 +35 verbose npm v1.0.0 +36 error code ECODE +37 error ERR SUMMARY Unknown error +38 error ERR DETAIL Unknown error +39 verbose exit 1 +41 timing npm Completed in {TIME}ms +42 verbose code 1 +43 error A complete log of this run can be found in: +43 error {CWD}/test/lib/utils/tap-testdir-exit-handler-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-debug-0.log ` exports[`test/lib/utils/exit-handler.js TAP handles unknown error with logs and debug file > logs 1`] = ` timing npm:load:whichnode Completed in {TIME}ms timing config:load Completed in {TIME}ms timing npm:load:configload Completed in {TIME}ms +timing npm:load:mkdirpcache Completed in {TIME}ms +timing npm:load:mkdirplogs Completed in {TIME}ms +verbose title npm +verbose argv timing npm:load:setTitle Completed in {TIME}ms timing npm:load:display Completed in {TIME}ms +verbose logfile logs-max:10 dir:{CWD}/test/lib/utils/tap-testdir-exit-handler-handles-unknown-error-with-logs-and-debug-file/cache/_logs verbose logfile {CWD}/test/lib/utils/tap-testdir-exit-handler-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-debug-0.log timing npm:load:logFile Completed in {TIME}ms timing npm:load:timers Completed in {TIME}ms timing npm:load:configScope Completed in {TIME}ms timing npm:load Completed in {TIME}ms +silly logfile done cleaning log files verbose stack Error: Unknown error verbose cwd {CWD} verbose Foo 1.0.0 -verbose argv "/node" "{CWD}/test/lib/utils/exit-handler.js" verbose node v1.0.0 verbose npm v1.0.0 error code ECODE diff --git a/tap-snapshots/test/lib/utils/log-file.js.test.cjs b/tap-snapshots/test/lib/utils/log-file.js.test.cjs index ecce9eafc..7a3918493 100644 --- a/tap-snapshots/test/lib/utils/log-file.js.test.cjs +++ b/tap-snapshots/test/lib/utils/log-file.js.test.cjs @@ -6,63 +6,65 @@ */ 'use strict' exports[`test/lib/utils/log-file.js TAP snapshot > must match snapshot 1`] = ` -0 error no prefix -1 error prefix with prefix -2 error prefix 1 2 3 -3 verbose { obj: { with: { many: [Object] } } } -4 verbose {"obj":{"with":{"many":{"props":1}}}} -5 verbose { -5 verbose "obj": { -5 verbose "with": { -5 verbose "many": { -5 verbose "props": 1 -5 verbose } -5 verbose } -5 verbose } -5 verbose } -6 verbose [ 'test', 'with', 'an', 'array' ] -7 verbose ["test","with","an","array"] -8 verbose [ -8 verbose "test", -8 verbose "with", -8 verbose "an", -8 verbose "array" -8 verbose ] -9 verbose [ 'test', [ 'with', [ 'an', [Array] ] ] ] -10 verbose ["test",["with",["an",["array"]]]] -11 verbose [ -11 verbose "test", -11 verbose [ -11 verbose "with", -11 verbose [ -11 verbose "an", -11 verbose [ -11 verbose "array" -11 verbose ] -11 verbose ] -11 verbose ] -11 verbose ] -12 error pre has many errors Error: message -12 error pre at stack trace line 0 -12 error pre at stack trace line 1 -12 error pre at stack trace line 2 -12 error pre at stack trace line 3 -12 error pre at stack trace line 4 -12 error pre at stack trace line 5 -12 error pre at stack trace line 6 -12 error pre at stack trace line 7 -12 error pre at stack trace line 8 -12 error pre at stack trace line 9 Error: message2 -12 error pre at stack trace line 0 -12 error pre at stack trace line 1 -12 error pre at stack trace line 2 -12 error pre at stack trace line 3 -12 error pre at stack trace line 4 -12 error pre at stack trace line 5 -12 error pre at stack trace line 6 -12 error pre at stack trace line 7 -12 error pre at stack trace line 8 -12 error pre at stack trace line 9 -13 error nostack [Error: message] +0 verbose logfile logs-max:10 dir:{CWD}/test/lib/utils/tap-testdir-log-file-snapshot +1 silly logfile done cleaning log files +2 error no prefix +3 error prefix with prefix +4 error prefix 1 2 3 +5 verbose { obj: { with: { many: [Object] } } } +6 verbose {"obj":{"with":{"many":{"props":1}}}} +7 verbose { +7 verbose "obj": { +7 verbose "with": { +7 verbose "many": { +7 verbose "props": 1 +7 verbose } +7 verbose } +7 verbose } +7 verbose } +8 verbose [ 'test', 'with', 'an', 'array' ] +9 verbose ["test","with","an","array"] +10 verbose [ +10 verbose "test", +10 verbose "with", +10 verbose "an", +10 verbose "array" +10 verbose ] +11 verbose [ 'test', [ 'with', [ 'an', [Array] ] ] ] +12 verbose ["test",["with",["an",["array"]]]] +13 verbose [ +13 verbose "test", +13 verbose [ +13 verbose "with", +13 verbose [ +13 verbose "an", +13 verbose [ +13 verbose "array" +13 verbose ] +13 verbose ] +13 verbose ] +13 verbose ] +14 error pre has many errors Error: message +14 error pre at stack trace line 0 +14 error pre at stack trace line 1 +14 error pre at stack trace line 2 +14 error pre at stack trace line 3 +14 error pre at stack trace line 4 +14 error pre at stack trace line 5 +14 error pre at stack trace line 6 +14 error pre at stack trace line 7 +14 error pre at stack trace line 8 +14 error pre at stack trace line 9 Error: message2 +14 error pre at stack trace line 0 +14 error pre at stack trace line 1 +14 error pre at stack trace line 2 +14 error pre at stack trace line 3 +14 error pre at stack trace line 4 +14 error pre at stack trace line 5 +14 error pre at stack trace line 6 +14 error pre at stack trace line 7 +14 error pre at stack trace line 8 +14 error pre at stack trace line 9 +15 error nostack [Error: message] ` |