Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@jalik/logger
Advanced tools
A flexible logger to log messages to anything you want (console, file, database...), there's nothing more to say about it.
Logging is an important part of an application lifecycle, from development to production, we always need to log messages for debugging or tracing errors and warnings.
This library is tested with unit tests.
The first thing to do is to create a logger, it's deadly simple.
import Logger from "@jalik/logger";
const Logger = new Logger({
// Activate the logger
active: true,
// Display message of given types in the console
console: {
debug: true,
error: true,
info: true,
other: true,
warning: true
},
// Display context in the console
displayContext: false,
// Display logger name in the console
displayMessage: false,
// Give a name to this logger
name: 'main'
});
Note that options
are available on each Logger
instance via Logger.options
.
As you can imagine, there are different types of logging, this is useful to distinguish messages, so below are these types :
You can access predefined logging types by importing them in your code.
import Types from "@jalik/logger/dist/types";
Types.debug;
Types.error;
Types.info;
Types.warning;
When you log a message, you can also provide an optional context as extra information, you have a dedicated method for each type of logging.
import Logger from "@jalik/logger";
const Logger = new Logger();
// Logs a debug message
Logger.debug("user json", {name: "karl"});
// Logs an error message
Logger.error("Forbidden", {error: new Error("forbidden")});
Logger.error(new Error("forbidden"));
// Logs an info message
Logger.info("Application started", {date: new Date()});
// Logs a warning message
Logger.warn("Disk usage is above 90%", {diskUsage: 92.6});
// Logs a custom type message
Logger.log("Plop", "custom-type");
By default a logger is activated, but you can deactivate it anytime you want by using the setActive(Boolean)
method.
import Logger from "@jalik/logger";
const Logger = new Logger();
// Activate logger on production environment only
Logger.setActive(process.env.NODE_ENV === "PRODUCTION");
// And to check if the logger is active
Logger.isActive();
The logger is flexible enough in the way that you can execute callbacks when an event occurs (debug, error, info, warning), so you could save logs to a database, a file or whatever you want.
import Types from "@jalik/logger/dist/types";
import Logger from "@jalik/logger";
const Logger = new Logger();
// With this event listener, you can do something when an error happens
Logger.on(Types.error, (message, context) => {
// do whatever you want here...
// save error to database, send an email...
});
// This will trigger the listener defined above
Logger.error("Cannot contact DNS server", {ipAddress: "8.8.8.8"});
History of releases is in the changelog.
The code is released under the MIT License.
If you find this lib useful and would like to support my work, donations are welcome :)
v1.0.4 (2018-04-02)
displayName: Boolean
name: String
Logger.getName()
FAQs
A logging utility to log messages to anywhere.
The npm package @jalik/logger receives a total of 16 weekly downloads. As such, @jalik/logger popularity was classified as not popular.
We found that @jalik/logger 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.