question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] Allow logging of arbitrary object without message

See original GitHub issue

To 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
abeforgitcommented, Jun 30, 2021

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”

0reactions
maraisrcommented, Oct 10, 2022

Hi @abeforgit sorry for the delay here 😅

We no longer restrict what you want to log, be it info('bob'), info(), or info({ foo: 'bar' }). We will respect this.

message[0] will still format, if it’s a string.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Logging HOWTO — Python 3.11.1 documentation
Logger objects have a threefold job. First, they expose several methods to application code so that applications can log messages at runtime. Second,...
Read more >
Logging - .NET - Microsoft Learn
To create logs, use an ILogger<TCategoryName> object from DI. The following example: Creates a logger, ILogger<Worker> , which uses a log ...
Read more >
NLog: logging an object serialized to JSON - Stack Overflow
It works fine with simple text messages. Now, I need to log a number of arbitrary objects already serialized to JSON. When I...
Read more >
Logger (Java Platform SE 7 ) - Oracle Help Center
A Logger object is used to log messages for a specific system or application component. Loggers are normally named, using a hierarchical dot-separated ......
Read more >
15.6. logging — Logging facility for Python - Rose-Hulman
Logger objects have a threefold job. First, they expose several methods to application code so that applications can log messages at runtime. Second,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found