diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index f289d8e8fd8134..93df2fb43c0bf9 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -1376,6 +1376,9 @@ The `util.isUndefined()` API has been removed. Please use -Type: Runtime +Type: End-of-Life -The [`util.log()`][] API has been deprecated because it's an unmaintained +The `util.log()` API has been removed because it's an unmaintained legacy API that was exposed to user land by accident. Instead, consider the following alternatives based on your specific needs: diff --git a/doc/api/util.md b/doc/api/util.md index cf4ae74dcb2f04..776b54a5a2f51d 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -2950,26 +2950,6 @@ util.isArray({}); // Returns: false ``` -### `util.log(string)` - - - -> Stability: 0 - Deprecated: Use a third party module instead. - -* `string` {string} - -The `util.log()` method prints the given `string` to `stdout` with an included -timestamp. - -```js -const util = require('node:util'); - -util.log('Timestamped message.'); -``` - [Common System Errors]: errors.md#common-system-errors [Custom inspection functions on objects]: #custom-inspection-functions-on-objects [Custom promisified functions]: #custom-promisified-functions diff --git a/lib/util.js b/lib/util.js index d9187f38baeb23..2c63152eb8bd2b 100644 --- a/lib/util.js +++ b/lib/util.js @@ -23,14 +23,7 @@ const { ArrayIsArray, - ArrayPrototypeJoin, ArrayPrototypePop, - Date, - DatePrototypeGetDate, - DatePrototypeGetHours, - DatePrototypeGetMinutes, - DatePrototypeGetMonth, - DatePrototypeGetSeconds, Error, ErrorCaptureStackTrace, FunctionPrototypeBind, @@ -42,7 +35,6 @@ const { ObjectSetPrototypeOf, ObjectValues, ReflectApply, - StringPrototypePadStart, StringPrototypeToWellFormed, } = primordials; @@ -89,14 +81,6 @@ function lazyAbortController() { let internalDeepEqual; -/** - * @param {number} n - * @returns {string} - */ -function pad(n) { - return StringPrototypePadStart(n.toString(), 2, '0'); -} - /** * @param {string} code * @returns {string} @@ -134,35 +118,6 @@ function styleText(format, text) { return `${escapeStyleCode(formatCodes[0])}${text}${escapeStyleCode(formatCodes[1])}`; } -const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', - 'Oct', 'Nov', 'Dec']; - -/** - * @returns {string} 26 Feb 16:19:34 - */ -function timestamp() { - const d = new Date(); - const t = ArrayPrototypeJoin([ - pad(DatePrototypeGetHours(d)), - pad(DatePrototypeGetMinutes(d)), - pad(DatePrototypeGetSeconds(d)), - ], ':'); - return `${DatePrototypeGetDate(d)} ${months[DatePrototypeGetMonth(d)]} ${t}`; -} - -let console; -/** - * Log is just a thin wrapper to console.log that prepends a timestamp - * @deprecated since v6.0.0 - * @type {(...args: any[]) => void} - */ -function log(...args) { - if (!console) { - console = require('internal/console/global'); - } - console.log('%s - %s', timestamp(), format(...args)); -} - /** * Inherit the prototype methods from one constructor into another. * @@ -325,10 +280,6 @@ module.exports = { } return internalDeepEqual(a, b); }, - log: deprecate(log, - 'The `util.log API is deprecated. ' + - 'Please use console.log() with a custom formatter or a third-party logger instead.', - 'DEP0059'), promisify, stripVTControlCharacters, toUSVString(input) { diff --git a/test/parallel/test-fs-write-file-buffer.js b/test/parallel/test-fs-write-file-buffer.js index ec6c60e1a46971..23dc48081a7bf0 100644 --- a/test/parallel/test-fs-write-file-buffer.js +++ b/test/parallel/test-fs-write-file-buffer.js @@ -21,7 +21,6 @@ 'use strict'; require('../common'); -const util = require('util'); const fs = require('fs'); let data = [ @@ -50,5 +49,3 @@ tmpdir.refresh(); const buf = Buffer.from(data, 'base64'); fs.writeFileSync(tmpdir.resolve('test.jpg'), buf); - -util.log('Done!'); diff --git a/test/parallel/test-util-log.js b/test/parallel/test-util-log.js deleted file mode 100644 index 838828e50f32b0..00000000000000 --- a/test/parallel/test-util-log.js +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const { - hijackStdout, - hijackStderr, - restoreStdout, - restoreStderr, -} = require('../common/hijackstdio'); -const assert = require('assert'); -const util = require('util'); - -assert.ok(process.stdout.writable); -assert.ok(process.stderr.writable); - -const strings = []; -hijackStdout(function(data) { - strings.push(data); -}); -hijackStderr(common.mustNotCall('stderr.write must not be called')); - -const tests = [ - { input: 'foo', output: 'foo' }, - { input: undefined, output: 'undefined' }, - { input: null, output: 'null' }, - { input: false, output: 'false' }, - { input: 42, output: '42' }, - { input: function() {}, output: '[Function: input]' }, - { input: parseInt('not a number', 10), output: 'NaN' }, - { input: { answer: 42 }, output: '{ answer: 42 }' }, - { input: [1, 2, 3], output: '[ 1, 2, 3 ]' }, -]; - -// test util.log() -const re = /[0-9]{1,2} [A-Z][a-z]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} - (.+)$/; -for (const test of tests) { - util.log(test.input); - const result = strings.shift().trim(); - const match = re.exec(result); - assert.ok(match); - assert.strictEqual(match[1], test.output); -} - -assert.strictEqual(process.stdout.writeTimes, tests.length); - -restoreStdout(); -restoreStderr();