-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Rotating log file for #1534 #1596
Conversation
Lines 6-15Ohayou, esteemed developer-san! Nuki has detected your intentions to improve logging, and while the effort is commendable, there are a few nuances that could make this even better! Let's tighten up those logs like we're prepping for the grand anime convention! 🌠
Here's a little code magic from Nuki to help out: const logNameGenerator = (time, index) => {
if (!time) return path.join(app.getPath('userData'), 'logs', 'nuclear-error.log');
const month = time.getFullYear().toString() + (time.getMonth() + 1).toString().padStart(2, '0');
const day = time.getDate().toString().padStart(2, '0');
const hour = time.getHours().toString().padStart(2, '0');
const minute = time.getMinutes().toString().padStart(2, '0');
return path.join(app.getPath('userData'), 'logs', `${month}/${month}${day}-${hour}${minute}-${index}-nuclear-error.log`);
}; Lines 16-25Lookie here! We're getting all fancy with rotating log files! 📜 But, there's always room for a little more polish, isn't there? Here are some hints from your code-review kouhai:
Remember, following Nuki's advice is like reading manga -- it's not required but it often leads to enlightenment, and occasionally, a good laugh. 😜 Also, Nuki might make a mistake sometimes, because even bots powered by the latest AI technologies can have bugs (but don't tell anyone, okay?). 🙊 Now, go forth and make these logs spectacular! Ganbatte, developer-chan! 💖✨ |
const hour = pad(time.getHours()); | ||
const minute = pad(time.getMinutes()); | ||
|
||
return path.join(app.getPath('userData'), 'logs', `${month}/${month}${day}-${hour}${minute}-${index}-nuclear-error.log`); |
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.
If you use a filename dependent on the current day and time, will this overwrite earlier existing files? My suspicion is that these files will stay there indefinitely, because they will all have different names and the logger won't know which files to overwrite. Do you think you could test that?
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.
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.
Also, looks like the module creates a separate file to hold the current log. Not quite sure if we would want that or not
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, that behavior looks good. Could you write a test to make sure it stays this way? You could mock fs
and assert how the files are created.
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.
I have come to realize that what you said about the file names using date and time is correct. That approach does not work as intended. My apologies, I did not understand properly.
Good thing is I think that we can just add one line argument rotate
which seems to do the job. I have committed this change, and tested it manually. How does it sound? Also, if this change sounds good, may I ask guidance on the location to put the testing file? I was thinking to put in same folder with the index file of the logger and write a logger.test.ts
there. Thank you for your time and patience!
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.
Nice, then I propose that I could try testing this manually this evening, and then if everything works as expected I could write the tests for it. I also want to replace electron-timber
so I might do it at the same time.
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.
Sounds good!
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.
I'm struggling to test and debug this library, it's very hard to mock its fs
calls correctly. While I have a reasonable test setup, I need to study its internal behavior, and I can't step into its classical
function, if I set it up so that there is already a saved log file to check how it rotates, the function doesn't progress through the rest of its rotation logic. I'm aware this is testing a dependency, but I want to be sure that the way it's initialized in Nuclear's logging service is ok and works as expected, and I can't do that.
Thanks for contributing. Let's discuss a couple of details in the comments |
Because you force-pushed to your branch, I can't push to your branch anymore, because the history is messed up and it's no longer continuous. Not sure how to add the tests I wrote to this PR. |
Hey @nukeop I apologize for the hassle I created with the force push. Is there a way we can fix it? Please let me know if you need me to do anything regarding the force push issue or the testing, I am more than willing to help. I would really appreciate your guidance if possible, I am kind of new to opensource stuff |
I tried to do several things and I have no idea how to fix this. I tried pushing to a parallel branch: https://github.com/nukeop/nuclear/tree/Kiduzk-temp In general you should never force push, especially to a branch others might be working on, it destroys git history. It's only allowable in cases where you commit important secrets that can't be rotated (even in those cases it's too late to protect these secrets anyway). |
Btw, the test on that branch is unfinished, and I'm not convinced it's going to be necessary. Maybe I could just merge this PR? |
Also, I was able to merge your branch with my master branch locally. Would you suggest that I push these changes to my GitHub fork associated with this PR? |
Yep, push them to this branch. If you do, I'll be able to add further commits |
Sounds good, I have pushed them |
Now that I pulled this locally, it seems to be fixed. Thanks. |
For some reason I still can't push to your branch. Could you please remove the last test in |
Sure, no problem. I have removed the last test, let me know if that works |
Can you remove the last test in that file? You only deleted some mocks. I wanted to do it myself but I still can't push to your branch. |
Yea, no problem. How about now |
I guess I learnt lesson to not force push for future, thanks or bearing with me. I can get started on copying to new branch |
An implementation for #1534