-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Format timestamp and meta independently of log function and allow timestamp to be passed into to log function #634
Conversation
We can't change the method signature to |
That being said your changes to |
That makes sense about so many down-streams having agreed to the contract. I just added a new commit to check the transport.log definition and either include timestamp in the call or not based on transport's defintion. |
Correct errors in common.formatMeta meta vs. options.meta logical errors in type checking logger was forcing meta to always be an object when not defined
A different perspective here: I think instead of going down the path of changing method signatures, it might be better to keep this timestamp coordination functionality out of the logging internals, and instead, use the If the timestamp function implementation closes over the logger, and subscribes to events for var logger = // winston stuff
// LTC: "locally coordinated time"
var LTC = {
"ts": [],
"getTimestamp": function getTimestamp() { return LTC.ts[0]; },
"log": function log() {
LTC.ts.push(new Date()); // this is the timestamp to log
logger.prototype.log.apply(logger, arguments); // log stuff...
}
};
logger.on("logging", function() { LTC.ts.shift(); }); // discard the timestamp
// configure transports:
logger.add(SomeTransport, { "timestamp": LTC.getTimestamp, ... }); |
@@ -116,16 +116,24 @@ Logger.prototype.extend = function (target) { | |||
// #### @callback {function} Continuation to respond to when complete. | |||
// Core logging method exposed to Winston. Metadata is optional. | |||
// | |||
Logger.prototype.log = function (level) { | |||
Logger.prototype.log = function (timestamp, level) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot change this method signature.
Just following up here. We really can't change method signatures. If you'd like to update your implementation please let us know. Your internal changes to |
I changed the implementation so the function signature hasn't changed. Optional timestamp would still be passed as first parameter. |
timestamp, | ||
args; | ||
|
||
if (new Date(level).toString() !== 'Invalid Date') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too much of a performance hit. I've been working on a number of benchmarks for comparing [email protected]
to [email protected]
and this will be a big hit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JiCiT Could you compare new Date(level).toString()
to doing isNaN(Date.parse('asd'))
? I think the second option could be cheaper.
Howdy! Thank you for your contribution. This PR is against the This is no longer an issue in
|
I had a need to be able to format both timestamp and meta without making a call to common.log, so I separated those into separate functions.
The bigger issue is that I'm doing some logging directly within a database and also feeding the logging info back to node for console, etc. logging. I want the timestamp to be consistent across both the database and other logging, so I want to be able to feed the timestamp directly into the call to log.
I made an effort to ensure that if the timestamp is not passed into the call to log, then existing functionality remains the same.