Skip to content

Commit 94b9948

Browse files
JungMinujasnell
authored andcommitted
lib,src: ensure '(node:pid)' prefix for stdout logging
Add '(node:pid)' prefix message for stdout logging PR-URL: #3833 Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Evan Lucas <[email protected]>
1 parent ff4f16b commit 94b9948

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

lib/_debugger.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const internalUtil = require('internal/util');
34
const util = require('util');
45
const path = require('path');
56
const net = require('net');
@@ -31,8 +32,8 @@ exports.start = function(argv, stdin, stdout) {
3132
stdin.resume();
3233

3334
process.on('uncaughtException', function(e) {
34-
console.error("There was an internal error in Node's debugger. " +
35-
'Please report this bug.');
35+
internalUtil.error('There was an internal error in Node\'s debugger. ' +
36+
'Please report this bug.');
3637
console.error(e.message);
3738
console.error(e.stack);
3839
if (interface_.child) interface_.child.kill();
@@ -520,7 +521,7 @@ Client.prototype.mirrorObject = function(handle, depth, cb) {
520521
cb = cb || function() {};
521522
this.reqLookup(propertyRefs, function(err, res) {
522523
if (err) {
523-
console.error('problem with reqLookup');
524+
internalUtil.error('problem with reqLookup');
524525
cb(null, handle);
525526
return;
526527
}
@@ -1668,7 +1669,7 @@ Interface.prototype.trySpawn = function(cb) {
16681669
process._debugProcess(pid);
16691670
} catch (e) {
16701671
if (e.code === 'ESRCH') {
1671-
console.error(`Target process: ${pid} doesn't exist.`);
1672+
internalUtil.error(`Target process: ${pid} doesn't exist.`);
16721673
process.exit(1);
16731674
}
16741675
throw e;
@@ -1737,7 +1738,7 @@ Interface.prototype.trySpawn = function(cb) {
17371738
function connectError() {
17381739
// If it's failed to connect 10 times then print failed message
17391740
if (connectionAttempts >= 10) {
1740-
console.error(' failed, please retry');
1741+
internalUtil.error(' failed to connect, please retry');
17411742
process.exit(1);
17421743
}
17431744
setTimeout(attemptConnect, 500);

lib/_tls_common.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const internalUtil = require('internal/util');
34
const constants = require('constants');
45
const tls = require('tls');
56

@@ -102,7 +103,7 @@ exports.createSecureContext = function createSecureContext(options, context) {
102103
if (options.dhparam) {
103104
var warning = c.context.setDHParam(options.dhparam);
104105
if (warning)
105-
console.trace(warning);
106+
internalUtil.trace(warning);
106107
}
107108

108109
if (options.crl) {

lib/events.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var internalUtil;
34
var domain;
45

56
function EventEmitter() {
@@ -232,10 +233,13 @@ EventEmitter.prototype.addListener = function addListener(type, listener) {
232233
m = $getMaxListeners(this);
233234
if (m && m > 0 && existing.length > m) {
234235
existing.warned = true;
235-
console.error('(node) warning: possible EventEmitter memory ' +
236-
'leak detected. %d %s listeners added. ' +
237-
'Use emitter.setMaxListeners() to increase limit.',
238-
existing.length, type);
236+
if (!internalUtil)
237+
internalUtil = require('internal/util');
238+
239+
internalUtil.error('warning: possible EventEmitter memory ' +
240+
'leak detected. %d %s listeners added. ' +
241+
'Use emitter.setMaxListeners() to increase limit.',
242+
existing.length, type);
239243
console.trace();
240244
}
241245
}

lib/internal/util.js

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ exports.printDeprecationMessage = function(msg, warned) {
1717
return exports._printDeprecationMessage(`${prefix}${msg}`, warned);
1818
};
1919

20+
exports.error = function(msg) {
21+
console.error(`${prefix}${msg}`);
22+
};
23+
24+
exports.trace = function(msg) {
25+
console.trace(`${prefix}${msg}`);
26+
};
27+
2028
exports._printDeprecationMessage = function(msg, warned) {
2129
if (process.noDeprecation)
2230
return true;

src/env.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "env.h"
22
#include "env-inl.h"
33
#include "v8.h"
4+
#include "unistd.h"
45
#include <stdio.h>
56

67
namespace node {
@@ -20,7 +21,7 @@ void Environment::PrintSyncTrace() const {
2021
Local<v8::StackTrace> stack =
2122
StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed);
2223

23-
fprintf(stderr, "WARNING: Detected use of sync API\n");
24+
fprintf(stderr, "(node:%d) WARNING: Detected use of sync API\n", getpid());
2425

2526
for (int i = 0; i < stack->GetFrameCount() - 1; i++) {
2627
Local<StackFrame> stack_frame = stack->GetFrame(i);

test/parallel/test-sync-io-option.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if (process.argv[2] === 'child') {
2020
execFile(process.execPath, args, function(err, stdout, stderr) {
2121
assert.equal(err, null);
2222
assert.equal(stdout, '');
23-
if (/^WARNING[\s\S]*fs\.readFileSync/.test(stderr))
23+
if (/WARNING[\s\S]*fs\.readFileSync/.test(stderr))
2424
cntr++;
2525
if (args[0] === '--trace-sync-io') {
2626
assert.equal(cntr, 1);

0 commit comments

Comments
 (0)