Skip to content
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

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

Closed
wants to merge 1 commit into from
Closed

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

wants to merge 1 commit into from

Conversation

JungMinu
Copy link
Member

Fixes issue: #3789
add '(node:pid)' prefix message for stdout logging

@martfors
Copy link
Contributor

If there aren't any reason template string can't be used in these files maybe this would be a good time to do that switch for these lines?

@thefourtheye
Copy link
Contributor

I would recommend moving this to function in internal/util and use template strings as suggested by @martfors

@thefourtheye thefourtheye added the lib / src Issues and PRs related to general changes in the lib or src directory. label Nov 15, 2015
@JungMinu
Copy link
Member Author

@thefourtheye will do :)

@bnoordhuis
Copy link
Member

The square brackets don't really add anything useful. I would format it as (node:1234), it's shorter.

@JungMinu
Copy link
Member Author

@bnoordhuis Thanks :)

@JungMinu JungMinu changed the title lib: Ensure '(node) [pid]' prefix for stdout logging lib: Ensure '(node:pid)' prefix for stdout logging Nov 15, 2015
@@ -1641,7 +1643,7 @@ Interface.prototype.trySpawn = function(cb) {
process._debugProcess(pid);
} catch (e) {
if (e.code === 'ESRCH') {
console.error(`Target process: ${pid} doesn't exist.`);
console.error(prefix + pid + `Target process: ${pid} doesn't exist.`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Careful here, pid is defined in this inner scope, overshadowing your top-scope definition. Won't be an issue when you use a function, though :)

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 Yup, I will use a function :)

@JungMinu
Copy link
Member Author

@thefourtheye Thanks, updated :)

@@ -232,7 +233,7 @@ 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 ' +
iutil.printStdoutError('warning: possible EventEmitter memory ' +
'leak detected. %d %s listeners added. ' +
Copy link
Contributor

Choose a reason for hiding this comment

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

The string should align with the previous line's string.

@jwueller
Copy link
Contributor

@bnoordhuis (node) [pid] would be grepable. (node:pid) is as well, but not as easily. I find that to be very useful.

@bnoordhuis
Copy link
Member

I would think that (node:pid) is easier to grep for, or at least more precisely. With a naive grep '(node) [1234]', the [1234] gets interpreted as (1|2|3|4).

@jwueller
Copy link
Contributor

Yes, the [] are probably a poor choice, but if I am not mistaken, there is more than once place in node where the (node) prefix is used. Making that consistent sounds like the right thing to do. Additionally providing the PID is a good thing, but it feels like that should not interfere with the existing pattern.

@jwueller
Copy link
Contributor

Oh wait, are we changing the prefix for everything? In that case, I am good with (node:pid) everywhere! Sorry about the confusion.

@JungMinu
Copy link
Member Author

@silverwind @bnoordhuis @thefourtheye Thanks, updated 😄

@@ -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. " +
Copy link
Contributor

Choose a reason for hiding this comment

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

We normally use ' for string literals, but in this case it is okay, I guess.

Copy link
Member Author

Choose a reason for hiding this comment

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

@thefourtheye Because of ' in Node's , we can't use ' for string literals in this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer we just escape the apostrophe like so:

'There was an internal error in Node\'s debugger. '

Copy link
Contributor

Choose a reason for hiding this comment

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

Or alternatively, just use a template string.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Fishrock123 Thanks :)

@thefourtheye
Copy link
Contributor

Overall change LGTM

@JungMinu
Copy link
Member Author

@thefourtheye updated :)

@evanlucas
Copy link
Contributor

Can you run make test on this? This change seems to make all tests fail

internal/util.js:3
const prefix = `(node:${process.pid}) `;
                        ^

ReferenceError: process is not defined

@@ -205,7 +205,7 @@ static void ares_sockstate_cb(void* data,
} else {
/* read == 0 and write == 0 this is c-ares's way of notifying us that */
/* the socket is now closed. We must free the data associated with */
/* socket. */
/* the socket. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really necessary as part of this PR?

@JungMinu
Copy link
Member Author

@jasnell @thefourtheye finished and rebased, Thanks :)

@@ -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 :)

@silverwind
Copy link
Contributor

LGTM. What happened to the C++ ambitions?

@silverwind
Copy link
Contributor

@JungMinu
Copy link
Member Author

@silverwind I found that the problem was not from C++,but there was a mistake in test script for new functions. I fixed it in my previous PR :)
Is there any error from c++ that I missed?

@silverwind
Copy link
Contributor

Searching for printf in src reveals quite a few cases, like here. I suppose C++ could be done in another PR, and these prints should be handled on a per-case basis. I suggest not adding the prefix when the process terminates after the error.

@JungMinu
Copy link
Member Author

JungMinu commented Dec 3, 2015

I've added more C++ files in src, please review again :)

@JungMinu JungMinu changed the title lib: Ensure '(node:pid)' prefix for stdout logging lib,src: Ensure '(node:pid)' prefix for stdout logging Dec 3, 2015
@@ -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 (/^[\s\S]*fs\.readFileSync/.test(stderr))
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest you just remove the ^ here, so the regex is /WARNING[\s\S]*fs\.readFileSync/.

@JungMinu
Copy link
Member Author

JungMinu commented Dec 3, 2015

@silverwind Thanks, fixed :)

@@ -813,7 +813,7 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo<Value>& args) {
return env->ThrowError("DH parameter is less than 1024 bits");
} else if (size < 2048) {
args.GetReturnValue().Set(FIXED_ONE_BYTE_STRING(
env->isolate(), "WARNING: DH parameter is less than 2048 bits"));
env->isolate(), "(node) WARNING: DH parameter is less than 2048 bits"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get a PID here too?

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 this gets logged in here, which is already handled in js code :)

@JungMinu
Copy link
Member Author

JungMinu commented Dec 3, 2015

updated and finished :)

env->isolate(), "WARNING: DH parameter is less than 2048 bits"));
}
env->isolate(), "WARNING: DH parameter is less than 2048 bits"));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the added spaces here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I am doing that :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Btw, git reset origin/master src/node_crypto.cc could help in resetting just that file :)

@JungMinu
Copy link
Member Author

JungMinu commented Dec 3, 2015

@silverwind fixed, thanks :)

add '(node:pid)' prefix message for stdout logging
@silverwind
Copy link
Contributor

@silverwind
Copy link
Contributor

Failures are unrelated, LGTM

@jasnell
Copy link
Member

jasnell commented Dec 3, 2015

LGTM

jasnell pushed a commit that referenced this pull request Dec 3, 2015
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]>
@jasnell
Copy link
Member

jasnell commented Dec 3, 2015

Landed in 94b9948

@jasnell jasnell closed this Dec 3, 2015
@rvagg
Copy link
Member

rvagg commented Dec 5, 2015

marking as semver-major so it doesn't get caught up in v5.x, I think that's appropriate, please correct me if I'm wrong.

@rvagg rvagg added the semver-major PRs that contain breaking changes and should be released in the next major version. label Dec 5, 2015
@silverwind
Copy link
Contributor

@rvagg well, it could certainly break things that parse our stdout, so I guess it's fine to conservatibely label it as major.

@jasnell jasnell mentioned this pull request Mar 17, 2016
scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
Add '(node:pid)' prefix message for stdout logging

PR-URL: nodejs#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib / src Issues and PRs related to general changes in the lib or src directory. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants