charmbracelet / log

A minimal, colorful Go logging library 🪵
MIT License
2.4k stars 67 forks source link

fix: lazy init default logger #111

Closed caarlos0 closed 8 months ago

caarlos0 commented 8 months ago

The default logger will try to query background et al on startup, which might conflict with other libs trying to query it too.

It's easily reproducible with some of our tools that use the log package, e.g., VHS:

faketty vhs --help

It slows down the program quite a bit, and print some ansi escape sequences as well.

This patch changes it so it only inits the default logger when/if the default logger is used.

Per my testing, it seems to fix the original issue.

caarlos0 commented 8 months ago

PS: this is not a faketty-only thing, it's producible if you create a PTY (with creak/pty for example) and run the same command - it's how I initially noticed the issue.