Skip to content

feat: log supports multiple colors #108

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

btea
Copy link
Contributor

@btea btea commented Apr 20, 2025

Add colors to distinguish different types of logs to facilitate quick access to information.

before after
image image

};
const color = colors[type as keyof typeof colors];
if (color) {
console.log(`${color}%s\x1b[0m`, `[tinyglobby ${new Date().toLocaleTimeString('es')}]${msg}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

hardcoding it to spanish?

Copy link
Owner

Choose a reason for hiding this comment

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

that one isn't changed on this pr and comes from main, it's for hardcoding time to be in the hh:mm:ss format, couldn't find a "international" locale that did this

Copy link
Contributor

@benmccann benmccann May 23, 2025

Choose a reason for hiding this comment

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

Ah, makes sense. Could be worth a comment

Copy link
Contributor

Choose a reason for hiding this comment

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

Swedish is quite often used for this kinda thing but that's a bit risky though, I've opened an issue in NodeJS a while ago for date string not respecting 2 digits with 0 padding in Node 22. Then a Node maintainer replied with this comment

Data changes constantly. Look at https://www.unicode.org/cldr/charts/44/delta/index.html and pick any locale. toLocaleString() is completely inappropriate as an API to expect a constant format. It should display what's correct for Swedish, which might change over time.

It's usually safer to use new Date(date).toISOString() even though it's UTC TZ

@SuperchupuDev
Copy link
Owner

i think this pr is probably a bit overkill, it would need more handling for systems that don't support colors and it would increase bundle size for something that is just meant to be a tiny debug function to share the output of if stuff breaks. could use util.styleText but sadly that is only supported on node 20 and up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants