Skip to content

lib,src: Ensure '(node:pid)' prefix for stdout logging #3833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/_debugger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const internalUtil = require('internal/util');
const util = require('util');
const path = require('path');
const net = require('net');
Expand Down Expand Up @@ -31,8 +32,8 @@ exports.start = function(argv, stdin, stdout) {
stdin.resume();

process.on('uncaughtException', function(e) {
console.error("There was an internal error in Node's debugger. " +
'Please report this bug.');
internalUtil.error('There was an internal error in Node\'s debugger. ' +
'Please report this bug.');
console.error(e.message);
console.error(e.stack);
if (interface_.child) interface_.child.kill();
Expand Down Expand Up @@ -520,7 +521,7 @@ Client.prototype.mirrorObject = function(handle, depth, cb) {
cb = cb || function() {};
this.reqLookup(propertyRefs, function(err, res) {
if (err) {
console.error('problem with reqLookup');
internalUtil.error('problem with reqLookup');
cb(null, handle);
return;
}
Expand Down Expand Up @@ -1668,7 +1669,7 @@ Interface.prototype.trySpawn = function(cb) {
process._debugProcess(pid);
} catch (e) {
if (e.code === 'ESRCH') {
console.error(`Target process: ${pid} doesn't exist.`);
internalUtil.error(`Target process: ${pid} doesn't exist.`);
process.exit(1);
}
throw e;
Expand Down Expand Up @@ -1737,7 +1738,7 @@ Interface.prototype.trySpawn = function(cb) {
function connectError() {
// If it's failed to connect 10 times then print failed message
if (connectionAttempts >= 10) {
console.error(' failed, please retry');
internalUtil.error(' failed to connect, please retry');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the context of this error, but the message change seems unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@silverwind Editing this error message is suggested by @thefourtheye

I think this error message could be more descriptive. If you like to do it, you can do it now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, alright. Guess it's ok then :)

process.exit(1);
}
setTimeout(attemptConnect, 500);
Expand Down
3 changes: 2 additions & 1 deletion lib/_tls_common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const internalUtil = require('internal/util');
const constants = require('constants');
const tls = require('tls');

Expand Down Expand Up @@ -102,7 +103,7 @@ exports.createSecureContext = function createSecureContext(options, context) {
if (options.dhparam) {
var warning = c.context.setDHParam(options.dhparam);
if (warning)
console.trace(warning);
internalUtil.trace(warning);
}

if (options.crl) {
Expand Down
12 changes: 8 additions & 4 deletions lib/events.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var internalUtil;
var domain;

function EventEmitter() {
Expand Down Expand Up @@ -232,10 +233,13 @@ EventEmitter.prototype.addListener = function addListener(type, listener) {
m = $getMaxListeners(this);
if (m && m > 0 && existing.length > m) {
existing.warned = true;
console.error('(node) warning: possible EventEmitter memory ' +
'leak detected. %d %s listeners added. ' +
'Use emitter.setMaxListeners() to increase limit.',
existing.length, type);
if (!internalUtil)
internalUtil = require('internal/util');

internalUtil.error('warning: possible EventEmitter memory ' +
'leak detected. %d %s listeners added. ' +
'Use emitter.setMaxListeners() to increase limit.',
existing.length, type);
console.trace();
}
}
Expand Down
8 changes: 8 additions & 0 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ exports.printDeprecationMessage = function(msg, warned) {
return exports._printDeprecationMessage(`${prefix}${msg}`, warned);
};

exports.error = function(msg) {
console.error(`${prefix}${msg}`);
};

exports.trace = function(msg) {
console.trace(`${prefix}${msg}`);
};

exports._printDeprecationMessage = function(msg, warned) {
if (process.noDeprecation)
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/env.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "env.h"
#include "env-inl.h"
#include "v8.h"
#include "unistd.h"
#include <stdio.h>

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

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

for (int i = 0; i < stack->GetFrameCount() - 1; i++) {
Local<StackFrame> stack_frame = stack->GetFrame(i);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-sync-io-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if (process.argv[2] === 'child') {
execFile(process.execPath, args, function(err, stdout, stderr) {
assert.equal(err, null);
assert.equal(stdout, '');
if (/^WARNING[\s\S]*fs\.readFileSync/.test(stderr))
if (/WARNING[\s\S]*fs\.readFileSync/.test(stderr))
cntr++;
if (args[0] === '--trace-sync-io') {
assert.equal(cntr, 1);
Expand Down