Open Kiduzk opened 2 months ago
Ohayou, 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! 🌠
pad
function is super adorable, doing its own little "I must include leading zeros" dance, but what if I told you we could avoid the dance altogether? JavaScript's String.prototype.padStart
is like the cool senpai that's been around the block and has all the answers. Let's use that instead, and Nuki promises you'll still keep the cuteness factor! 🎀if (!time)
is giving Nuki déjà vu vibes because it looks like we're preparing for some time travel! But since we're not in a sci-fi episode, perhaps we should ensure consistency in naming patterns between log files during no-time times and regular-time times, ne? 🚀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`);
};
Lookie 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:
maxFiles
property mysteriously appeared like a secret character being introduced late into the season. It's indeed a good practice to limit the number of log files! Good job on that, but let's document why we chose 3 as the magic number, okay? 🧙♀️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! 💖✨
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 But then I can't merge this branch into your master. Try it yourself, maybe you'll be able to.
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?
As far as the testing goes, merging works with me. I run some manual tests with small log sizes and the output seems to be as we want it. This is one screenshot I have
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 logger.test.ts
and leave everything else? And then we could merge this PR.
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
An implementation for #1534