console-steroids
v1.0.0
Published
Enables you to assign `console.log` statements to groups, which you can then enable or disable using environmental variables.
Readme
Console Steroids
Enables you to assign console.log statements to groups, which you can then enable or disable using environmental variables.
installation
npm i console-steroids
how to use
Import the package:
import console from "console-steroids"
Afterwards, you can mostly use the console object almost exactly as you are used to. The only exception is that you can now pass the group name as the second argument. For example: console.log("testing", "testing-group"). If no group name is passed, then it is assigned to the default group, called "default".
Next, you can enable and disable specific groups. To do so, create a file with your environmental variables (e.g. .env.local, env.development, env.production). You can add any of two environmental variables: NEXT_PUBLIC_ENABLED_LOG_GROUPS and NEXT_PUBLIC_DISABLED_LOG_GROUPS. Each of these can contain any of the follow values: none, all or a list of group names separated by commas. The functionality of all these values should be pretty self-explanatory. Keep in mind that the disabled group has precedence of the enabled group. So if a group is added to both the enabled and the disabled groups, then it will be considered disabled.
example
index.js: \
import console from "console-steroids"
console.log("test 1", "test1")
console.error("test 2", "test2")
console.warn("test 3", "test3")
console.log("test 4", "test4").env.local
NEXT_PUBLIC_ENABLED_LOG_GROUPS=test1,test2,test3
NEXT_PUBLIC_DISBALED_LOG_GROUPS=test2will output:
test 2
test 3