
Research
NPM targeted by malware campaign mimicking familiar library names
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
auto-console-group
Advanced tools
Tame the JS console by automagically grouping console messages.
A more readable console output in a couple of minutes.
Above created by example.ts.
Install auto-console-group via npm.
npm install auto-console-group
Or download auto-console-group.js
The createAutoConsoleGroup()
creates a console object with all the same methods as the regular console
object,
plus a few additional methods to control how a group is displayed.
import createAutoConsoleGroup from 'auto-console-group'
const consoleGroup = createAutoConsoleGroup({ label: 'autoConsoleGroup' })
// All console methods are reflected on consoleGroup
consoleGroup.log('Log message')
consoleGroup.table(['foo', 'bar'])
consoleGroup.count('Counter')
// Set the Event in the group heading
consoleGroup.event('myEvent')
The heading for each group is made up of three parts: Label, Event and Time.
The first part of the heading is the label
, and is for showing your library or application name.
The label is set via the options when you create a consoleGroup.
The second part, shown in bold, is the Event
. This is for indicating the trigger for the current event loop.
The event heading for the current loop is set via the .event()
method for the current event loop. After which it
will automatically reset to the defaultEvent
which is set in the options.
const consoleGroup = createAutoConsoleGroup({ options })
consoleGroup.event('myEvent')
Optionally the group heading can included the time of the first logged message.
To disable this function set the showTime
option to false.
The following options can be passed to createAutoConsoleGroup
.
{
label: 'Label', // First part of the group heading
expand: true, // Show groups expanded or collapsed
defaultEvent: 'Event', // Second part of the group heading, shown in bold
showTime: true, // Display time in the group headings
}
When the collapsed
option is set to true, the group will automatically open if a warning or error is
included in the group.
In addition to the full Console API, the following methods are also available.
Force the current group to output to the browser console. Any logs created after this call will appear in a new group.
Create an error boundary around a function. This allows auto-console-group to display runtime errors within the console group.
Set the event type part of the group heading for just the current event loop iteration.
Remove all messages in the current output queue.
To assist with colouring console messages, the package also contains two consts that will return the current hex codes for highlighting log message.
The default console highlight colour, based on dark/light mode.
The current console foreground colour, based on dark/light mode.
This library works by storing console messages in an array and outputting the collected list of messages via a Microtask that runs directly after the main Event Loop task completes. Whilst this will continue to work even in the event of a runtime error, as the Microtask runs after the main task has terminated, the current log group will be displayed after the error, rather than in front of it.
To overcome this limitation, you can create an Error Boundary, which will catch runtime errors and included them in the current console group.
const consoleGroup = createAutoConsoleGroup({ label: 'Error boundary example' })
consoleGroup.errorBoundary(() => {
consoleGroup.log('Message before error')
throw new Error('Runtime error')
})
FAQs
Automagically group console messages
The npm package auto-console-group receives a total of 14,621 weekly downloads. As such, auto-console-group popularity was classified as popular.
We found that auto-console-group demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
Research
Socket's research uncovers three dangerous Go modules that contain obfuscated disk-wiping malware, threatening complete data loss.
Research
Socket uncovers malicious packages on PyPI using Gmail's SMTP protocol for command and control (C2) to exfiltrate data and execute commands.