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
{{ message }}
Repository navigation
Feature suggestion: default replacer to better handle Error objects passed as meta #31
I can use log.options.replacer to get a much better serialization of the Error object (using the error-to-json package here):
constlog=require('lambda-log')consterrorToJson=require('error-to-json').defaultlog.options.replacer=(key,value)=>{if(valueinstanceofError)returnerrorToJson(value)returnvalue}consterror=newError('foo')log.warn('Heads up!',{error})// {"_logLevel":"warn","msg":"Heads up!","error":{"name":"Error","message":"foo","stack":"Error: foo\n at REPL9:1:15\n at Script.runInThisContext (vm.js:120:18)\n at REPLServer.defaultEval (repl.js:442:29)\n at bound (domain.js:427:14)\n at REPLServer.runBound [as eval] (domain.js:440:12)\n at REPLServer.onLine (repl.js:777:10)\n at REPLServer.emit (events.js:326:22)\n at REPLServer.EventEmitter.emit (domain.js:483:12)\n at REPLServer.Interface._onLine (readline.js:329:10)\n at REPLServer.Interface._line (readline.js:658:8)"},"_tags":["log","warn"]}
My suggestion is to consider making this the default behavior. Are there any use cases where serializing an Error to {} would be the better behavior?
@mfogel Right now, this package will handle Error objects correctly when passed in as the message versus within the meta. I can see the use cases where you may want to pass an error in the meta instead.
I'm trying to keep the number of dependencies within this package as minimal as possible so I think I would like to recreate the functionality of the error-to-json package inside of this one given it's a minimal amount of code.
I'll work on adding this in the next release. Thanks for the feature request!
@mfogel This has been implemented and published in v3.0.0. I'm still waiting on the site to go live with the updated documentation. Thanks for the feature suggestion!
Activity
KyleRoss commentedon Feb 15, 2021
@mfogel Right now, this package will handle
Errorobjects correctly when passed in as the message versus within themeta. I can see the use cases where you may want to pass an error in themetainstead.I'm trying to keep the number of dependencies within this package as minimal as possible so I think I would like to recreate the functionality of the
error-to-jsonpackage inside of this one given it's a minimal amount of code.I'll work on adding this in the next release. Thanks for the feature request!
feat: convert Errors in metadata to plain objects #31
feat: convert Errors in metadata to plain objects #31
chore(release): 3.0.0 [skip ci]
KyleRoss commentedon Apr 12, 2021
@mfogel This has been implemented and published in v3.0.0. I'm still waiting on the site to go live with the updated documentation. Thanks for the feature suggestion!
mfogel commentedon Apr 12, 2021
Thanks @KyleRoss ! Appreciate it very much!
KyleRoss commentedon Apr 15, 2021
@all-contributors please add @mfogel for ideas
allcontributors commentedon Apr 15, 2021
@KyleRoss
I've put up a pull request to add @mfogel! 🎉