Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
modulelog
Advanced tools
Changelog
0.2.2 ###
setClass
and setLevel
static methodsReadme
A library that allows easy userland swapping of different logging libraries.
By default it uses the built-in util.debuglog
but any npm module can be
required and used, provided it has at least some of warn
, info
, error
,
debug
methods that it exposes on its exports. console
can also be used,
except that no debug
methods will be logged.
var log = require('modulelog')('mymodulename');
log.setClass('console');
function cb(err) {
log.error("An error occured", {error: err});
}
A common use case would be to use flags
and allow the user to pass the class name via --logger
:
var log = require('modulelog')('mymodulename'),
flags = require('flags');
flags.defineString('logger', 'debug', 'Your name');
flags.parse();
log.setClass(flags.get('logger'));
Note: you must pass your module/app name to the result of
require('modulelog')
in order to get an instance to log with. The actual
class and level is globally controlled across modules but each module
must have a name for the debuglog
prefix.
Change the default logging library to be name
. Built-in values are default
,
debuglog
, console
. If an empty string is passed in, all logs will be
discarded. Any non-built-in values will be passed to require
.
Calls setLevel
on the backing library. If the library doesn't support
different levels (like debuglog
or console
) then this does nothing.
Calls the corresponding method on the backing library. It is recommended that you call with message and an object of extra data, however any number of arguments are accepted and passed on.
Calls the corresponding method on the backing library. If the library has no
fatal
method, then error
is called instead. After logging, process.exit
is invoked.
If you're trying to set the level or class in a static fashion setLevel
and
setClass
are both exposed statically on the exports for the module.
FAQs
Library to allow easy userland-changeable logging for node modules/applications
The npm package modulelog receives a total of 5 weekly downloads. As such, modulelog popularity was classified as not popular.
We found that modulelog demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.