We are using custom logger in most of our projects built on the top of Node.js. Logger logs locally as colored text and as JSON in production. The message is being output using
console.error(). The only problem we have in Meteor where each logline is being prefixed with time
I20200210-11:20:12.026(1)? and colored with a combination of blue and pink which breaks our coloring.
Is it possible to somehow disable this Meteor feature and have messages logged using
console.log() exactly as they are?
Hi @mtrunkat, welcome to to forums!
You can pass
--raw-logs to the meteor cli and it won’t print the timestamps or colors.
I use it for test scripts, as the default treatment totally ruins the nicely structured output of most testing frameworks
Meteor.isProduction() to prevent adding dupilcate timestamps, but thanks for the
--raw-logs tip @coagmano, I might try that instead!
If anyone’s is interested, I’ve just uploaded my own colorful console script to a pubilc gist: https://gist.github.com/wildhart/bf876b888fb6cb232078a055065af325
This basically intercepts
console.warn() (but not
console.error()) and adds timestamps and different colors depending on the first parameter.
With my script you can also mute certain topics - this is handy because I can remotely mute or unmute certain topics from my admin interface by calling a method which does
console.col.names[name].mute = false
When I’m developing a new feature I can add a new topic and see verbose logs, including in production. then after some testing I can mute them, but then unmute them if there is a problem later on.
This has been very handy to me over the years, but I never bothered to make it into a meteor or npm module. There are many other packages already available.
--raw-logs worked to get rid of date and Meteor coloring. But I had to add also
FORCE_COLOR=3 environment variable to force chalk package to support colors. Not sure why color support was not correctly recognized.