You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was able to hack a severity level so that a message only prints if its severity is above the min severity level. This is useful when for example you run the program in a verbose vs non-verbose mode.
Here is what worked for me:
constbullet=require("string.bullet");const{ cyan, yellow, red, dim, blue }=require("ansicolor");varlog=require("ololog").configure({locate: false,infoSeverity: 5,tag: (lines,{
level ="",
minSeverity=10,
severity =11,
levelColor ={info: cyan,warn: yellow,error: red.bright.inverse,debug: blue}})=>{constlevelStr=level&&(levelColor[level]||(s=>s))(level.toUpperCase());if(severity>=minSeverity){returnbullet(levelStr.padStart(6)+" ",lines);}elsereturn[];}});log("This prints!");log.configure({tag:{severity:12}}).info("This will print, severity 12!");log.configure({tag:{severity:1}}).info("This will print, severity 1!");log.configure({tag:{severity:15}}).info("This will print, severity 15!");log=log.configure({tag:{minSeverity:1000}});// change severitylog.configure({tag:{severity:12}}).info("This will not print, severity 12!");log.configure({tag:{severity:1}}).info("This will not print, severity 1!");log.configure({tag:{severity:15}}).info("This will not print, severity 15!");
However, this is ugly. Ideally, it should be like this:
varlog=require("ololog").configure({locate: false,infoMinSeverity: 5,warnMinSeverity: 6,debugMinSeverity: 8,errorMinSeverity: 10,minSeverity: 15,//without tag});log.severity(5).info('This is my message');log.configure({infoMinSeverity:0}).info('This is my message');
The text was updated successfully, but these errors were encountered:
I was able to hack a severity level so that a message only prints if its severity is above the min severity level. This is useful when for example you run the program in a verbose vs non-verbose mode.
Here is what worked for me:
However, this is ugly. Ideally, it should be like this:
The text was updated successfully, but these errors were encountered: