Skip to content

Commit

Permalink
util: move util.log to eol
Browse files Browse the repository at this point in the history
PR-URL: #52744
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
marco-ippolito authored and nodejs-github-bot committed May 6, 2024
1 parent 1d817dc commit 982f6ad
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 141 deletions.
7 changes: 5 additions & 2 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,9 @@ The `util.isUndefined()` API has been removed. Please use

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/52744
description: End-of-Life deprecation.
- version: v22.0.0
pr-url: https://github.com/nodejs/node/pull/50488
description: Runtime deprecation.
Expand All @@ -1387,9 +1390,9 @@ changes:
description: Documentation-only deprecation.
-->

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:

Expand Down
20 changes: 0 additions & 20 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -2950,26 +2950,6 @@ util.isArray({});
// Returns: false
```
### `util.log(string)`
<!-- YAML
added: v0.3.0
deprecated: v6.0.0
-->
> 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
Expand Down
49 changes: 0 additions & 49 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,7 @@

const {
ArrayIsArray,
ArrayPrototypeJoin,
ArrayPrototypePop,
Date,
DatePrototypeGetDate,
DatePrototypeGetHours,
DatePrototypeGetMinutes,
DatePrototypeGetMonth,
DatePrototypeGetSeconds,
Error,
ErrorCaptureStackTrace,
FunctionPrototypeBind,
Expand All @@ -42,7 +35,6 @@ const {
ObjectSetPrototypeOf,
ObjectValues,
ReflectApply,
StringPrototypePadStart,
StringPrototypeToWellFormed,
} = primordials;

Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions test/parallel/test-fs-write-file-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

'use strict';
require('../common');
const util = require('util');
const fs = require('fs');

let data = [
Expand Down Expand Up @@ -50,5 +49,3 @@ tmpdir.refresh();

const buf = Buffer.from(data, 'base64');
fs.writeFileSync(tmpdir.resolve('test.jpg'), buf);

util.log('Done!');
67 changes: 0 additions & 67 deletions test/parallel/test-util-log.js

This file was deleted.

0 comments on commit 982f6ad

Please sign in to comment.