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
Is your feature request related to a problem? Please describe.
Sometimes while logging, you want to use logger.debug, but you end up formatting a message even if the message won't be logged. Would be nice to make the formatting of the message content itself lazy.
Describe the solution you'd like
Use something like:
functiontemplate(strings, ...keys){return(...values)=>{constdict=values[values.length-1]||{};constresult=[strings[0]];keys.forEach((key,i)=>{constvalue=Number.isInteger(key) ? values[key] : dict[key];result.push(value,strings[i+1]);});returnresult.join("");};}constt1Closure=template`${0}${1}${0}!`;// const t1Closure = template(["","","","!"],0,1,0);t1Closure("Y","A");// "YAY!"constt2Closure=template`${0}${"foo"}!`;// const t2Closure = template([""," ","!"],0,"foo");t2Closure("Hello",{foo: "World"});// "Hello World!"constt3Closure=template`I'm ${"name"}. I'm almost ${"age"} years old.`;// const t3Closure = template(["I'm ", ". I'm almost ", " years old."], "name", "age");t3Closure("foo",{name: "MDN",age: 30});// "I'm MDN. I'm almost 30 years old."t3Closure({name: "MDN",age: 30});// "I'm MDN. I'm almost 30 years old."
Describe alternatives you've considered
Could also do logger.debug(() => ''), just a plain old function. But the templating idea seems pretty useful, at the end of the day it does in fact return a function too. So if you're going to template something, returning a function to be called might be faster if there are lots of logger.debug calls going around.
Should benchmark if this really improves performance, but it also provides some usability... we might be more free to sprinkle logger.debug calls if they don't slow things down (except a function call).
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Sometimes while logging, you want to use
logger.debug
, but you end up formatting a message even if the message won't be logged. Would be nice to make the formatting of the message content itself lazy.Describe the solution you'd like
Use something like:
Describe alternatives you've considered
Could also do
logger.debug(() => '')
, just a plain old function. But the templating idea seems pretty useful, at the end of the day it does in fact return a function too. So if you're going to template something, returning a function to be called might be faster if there are lots oflogger.debug
calls going around.Additional context
Should benchmark if this really improves performance, but it also provides some usability... we might be more free to sprinkle
logger.debug
calls if they don't slow things down (except a function call).The text was updated successfully, but these errors were encountered: