-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: exposed rotating-file log for json logging #948
Conversation
*/ | ||
class VerdaccioRotatingFileStream extends Logger.RotatingFileStream { // We depend on mv so that this is there | ||
write(obj) { | ||
const msg = fillInMsgTemplate(obj.msg, obj, false); |
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.
Where is the definition of fillInMsgTemplate
?
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.
Line 187 in ef02b2a
function fillInMsgTemplate(msg, obj, colors) { |
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.
Sorry, I forgot to update my master branch.
src/lib/logger.js
Outdated
|
||
let dest; | ||
let destIsTTY = false; | ||
const prettyPrint = (obj) => print(obj.level, obj.msg, obj, destIsTTY) + '\n'; |
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.
Can be defined at top as utils ... Please use template literals https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Syntax
src/lib/logger.js
Outdated
let destIsTTY = false; | ||
const prettyPrint = (obj) => print(obj.level, obj.msg, obj, destIsTTY) + '\n'; | ||
const prettyTimestampedPrint = (obj) => obj.time.toISOString() + print(obj.level, obj.msg, obj, destIsTTY) + '\n'; | ||
const jsonPrint = (obj) => { |
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.
Same as above.
src/lib/logger.js
Outdated
let destIsTTY = false; | ||
const prettyPrint = (obj) => print(obj.level, obj.msg, obj, destIsTTY) + '\n'; | ||
const prettyTimestampedPrint = (obj) => obj.time.toISOString() + print(obj.level, obj.msg, obj, destIsTTY) + '\n'; | ||
const jsonPrint = (obj) => { |
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.
Same as above.
package.json
Outdated
@@ -44,6 +44,7 @@ | |||
"mime": "2.3.1", | |||
"minimatch": "3.0.4", | |||
"mkdirp": "0.5.1", | |||
"mv": "^2.1.1", |
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.
Should it not already installed by Logger ? https://github.com/trentm/node-bunyan/blob/fe31b83e42d9c7f784e83fdcc528a7c76e0dacae/package.json#L27
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.
It's optional and this forces it to be there. Their code does if(mv): https://github.com/trentm/node-bunyan/blob/master/lib/bunyan.js#L96
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.
Remove the ^
please
/** | ||
* A RotatingFileStream that modifes the message first | ||
*/ | ||
class VerdaccioRotatingFileStream extends Logger.RotatingFileStream { // We depend on mv so that this is there |
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.
@juanpicado I am sure about extending the Logger.RotatingFileStream
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.
What do you suggest instead? Reimplementing it is a lot of work and this is public interface so a breaking change would be declarative
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.
make sense.
src/lib/logger.js
Outdated
}); | ||
} else if (target.type === 'stdout' || target.type === 'stderr') { | ||
dest = target.type === 'stdout' ? process.stdout : process.stderr; | ||
destIsTTY = dest.isTTY; |
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.
destIsTTY
it is not used further. ??
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.
It is used above, which is why those functions are in this scope. It's basically binding them all to the variables in this block scope
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.
You can pass destIsTTY
in pretty prettyTimestampedPrint
, jsonPrint
explicitily. Currently it is not readable.
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.
Ok, I'll refactor this class. Was trying to avoid that, but it is now unreadable, its time to refactor :)
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.
Thanks @mlucool feel free to refactor the whole logger.js
if you wish
src/lib/logger.js
Outdated
stream.writable = true; | ||
|
||
let dest; | ||
let destIsTTY = false; |
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.
it can be a constant.
src/lib/logger.js
Outdated
|
||
if (target.type === 'file') { |
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.
define dest
here. I'll suggest using full name instead of short forms. destination
src/lib/logger.js
Outdated
@@ -46,42 +57,79 @@ function setup(logs) { | |||
return JSON.stringify({...obj, msg}, Logger.safeCycles()) + '\n'; | |||
}; | |||
|
|||
if (target.type === 'file') { |
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.
From line 53 to 58, the following code is duplicated below and not being unused.
const prettyPrint = (obj) => print(obj.level, obj.msg, obj, destIsTTY) + '\n';
const prettyTimestampedPrint = (obj) => obj.time.toISOString() + print(obj.level, obj.msg, obj, destIsTTY) + '\n';
const jsonPrint = (obj) => {
const msg = fillInMsgTemplate(obj.msg, obj, destIsTTY);
return JSON.stringify({...obj, msg}, Logger.safeCycles()) + '\n';
};
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.
Meh, bad rebase on my part. Will fix
|
https://github.com/trentm/node-bunyan#stream-type-rotating-file @mlucool that deserves to be in the docs as well. As a reference at the bottom below the table |
It seems does not work, it fills files partially and then are emtpy.
|
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.
🔧
@juanpicado @ashishsurana Thanks for the comments, I'll look at this next week.
Good catch. Want me to also throw on this via checking isWorker?
That is expected. It is a time based rotate only and will rotate even if there is no new data. In your example, you have it rotating every 1s. Try navigating the website or installing something every second and you'll see that logs continue to have data. |
This both allows for logger type 'rotating-file' and passing of other options from the config "option" example: {type: rotating-file, format: json, path: /path/to/log.jsonl, level: http, options: {period: 1d}}
If there are no changes on |
ef02b2a
to
3caa015
Compare
@juanpicado @ayusharma please re-review. |
@mlucool I was on it but .... sadly my ISP decided I have to change my router 😢 ... I'll be offline rest of the week until fix that. |
@@ -6647,7 +6647,7 @@ mute-stream@0.0.7: | |||
version "0.0.7" | |||
resolved "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab" | |||
|
|||
mv@~2: | |||
mv@^2.1.1, mv@~2: |
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.
mv@^2.1.1, mv@~2:
<-- the ^
remains in lock file
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.
👍
Thanks @mlucool ! great job |
Thanks! |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This both allows for logger type 'rotating-file' and
passing of other options from the config "option" example:
Resolves: #388
Refers: #427