I don't know how expensive tty.isatty() is, but I imagine someone as it's a system call. It should be moved outside of this hot function. It can even be at the very outer level of logger.js as its value won't change after startup.