[Feature] Allow logging of arbitrary object without message
See original GitHub issueTo more closely mimic the console.log
api, it could be nice to allow the following:
const logger = diary("myScope");
const myCoolObject = { foo: "bar" };
logger.log(myCoolObject);
This technically works, but is not allowed by the types. But more importantly, this logs the toString representation of the object, rather than passing it to the default console.log
formatter.
I can see the benefit of restricting the api such that there should always be a message, so I would understand if you don’t want to go for it. After all, when you are logging anything serious, providing no context is bad practice. But for the sake of uniformity, I like to use the same library for quick debug-logging which I will remove later as for “real logging” which will remain in the production app. It’s purely a design decision and is not blocking at all, just thought I’d open the discussion.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top GitHub Comments
I see what you mean, but I’d disagree. Simple usecase for example is logging method calls. I use a decorator to make this easy to add to interesting methods. It prints:
Calling ${methodName} with args:
and then the args as objects. It’s very useful to print them as objects since this is the browser and the browser console has some really powerful built-in logging formatters (especially for things like DOM nodes).So I appreciate the current capability of allowing you to mix “text logs” and “object logs”
Hi @abeforgit sorry for the delay here 😅
We no longer restrict what you want to log, be it
info('bob')
,info()
, orinfo({ foo: 'bar' })
. We will respect this.message[0]
will still format, if it’s a string.