简体   繁体   中英

console.log to a custom category

I have a requirement to display all the logs with a tag (say TelemetryLogs) to a group, so that I can see all the network calls flow in a single view.

The requirement is to see the Network Calls in a grouped view - say a table with key-name, key-type and log-object.

The immediate suggestion that we gave to business is that we would log to console with a prefix and allow them to filter using a filter-expression. Eg: console.log(``Telemetry %s %s %o``, "name", "type", { someobject: 'someval' })

But they want the group to appear as a sub-group under one-of the categories in chrome (pic below). Apparently, they plan to roll out similar groups and dont want to remember a list of expression, to filter out what they want.

I then realized stackoverflow is the right place to check if this is possible, if not possible, what other grouped display options would help us achieve a similar expectation.

Note: Background of the use-case is that during our pair-programming, sometimes we end up business analyst sitting next to us. One of them realized if they had a consolidated-running-view of the telemetry data during development, it would help him/her catch early issues...

在此处输入图像描述

there is no way to create sub groups in the console current API standard that appear in the developer tools panel - there are group related functions that can group multiple log statements under one statement but thats not what you want, anyway here are two options that came to my mind

  • structure you log messages in a way that they can be easily filtered using the built in filter for logs maybe something of the following nature (groupId - logType - message) (Anyway it is always better to have a structure for logs)

  • The developer tools are part of the page, and they can have custom extended functionalities, you can create an extension that adds subgroups to that panel, along with the functionality you need, or you can add a tab of your own to filter that logs (its easier that what it looks)

Anyway one important thing to note, is that if logs are important to you then they should be sent to an external service that ensures no data is lost, and enables advanced load and extract functionalities on the logs. And anyway logs on the client side in the console are only useful for development, so is it worth it?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM