Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
logger4node
Advanced tools
![build](https://github.com/yog27ray/logger4node/actions/workflows/node.js.yml/badge.svg?branch=master) [![codecov](https://codecov.io/gh/yog27ray/logger4node/branch/master/graph/badge.svg)](https://codecov.io/gh/yog27ray/logger4node)
logger4node
is a simple and flexible logging library for Node.js applications.
It allows you to log messages with different levels of severity, and you can set different severity levels for different project files
import { Logger4Node } from 'logger4node';
const applicationLogger = new Logger4Node('Application');
import { LogSeverity } from 'logger4node';
applicationLogger.setLogLevel(LogSeverity.ERROR);
applicationLogger.setLogPattern('Application:*');
const loggerInstance = applicationLogger.instance('Instance1');
loggerInstance.error('This is test log');
Output:
Error: Application:Instance1 This is test log
JSON Logs: JSON logging is recommended for production deployments as it provides more detailed information.
JSON logs include fields such as time
, source
, request
, extraData
, and stack
.
To enable JSON logging, use the following configuration:
applicationLogger.setJsonLogging(true);
.
.
.
loggerInstance.error('This is test log');
Output:
{
"level": "error",
"time": "2024-07-01T07:07:54.877Z",
"className": "Application:Instance1",
"source": {
"caller": "callerFunctionName",
"fileName": "fileName.ts",
"path": "file path",
"line": "13",
"column": "10"
},
"message": "This is a test log",
"request": {},
"extra": {},
"stack": ""
}
This format ensures that logs contain comprehensive information, making it easier to debug and monitor applications in production environments.
Github Link: This feature enhances the logging library by providing a direct GitHub link that redirects to the exact location in the code where the log is generated. This allows users to easily navigate the entire codebase from the logs.
const applicationLogger = new Logger4Node(
'Application',
{
github: {
org: 'yog27ray',
repo: 'logger4node',
commitHash: 'githubCommitHash',
basePath: 'project/root/path'
},
});
By configuring these parameters, the logger will generate links that point to the exact lines in the GitHub repository, simplifying code navigation and debugging.
Multiple Logging Patter: This feature allows you to set different log severities for different instances of the logger.
applicationLogger.setLogLevel(LogSeverity.ERROR);
applicationLogger.setLogPattern('Application:*');
applicationLogger.setLogSeverityPattern(LogSeverity.INFO, 'Application:Instance1,Application:Instance2');
applicationLogger.setLogSeverityPattern(LogSeverity.DEBUG, 'Application:Instance3');
In the example above:
This setup enables more granular control over logging by specifying different severity levels for specific logger instances.
Track Session Log: Often, it’s useful to track all logs that correspond to a single session to better understand the code flow. You can also pass additional information to be preserved throughout the session. Below is the configuration to enable this feature:
With Express Server:
app.use(Logger4Node.Trace.requestHandler((req: Request) => {
const sessionInformation = { user: 'userId' };
return sessionInformation;
}));
.
.
.
loggerInstance.error('This is test log');
After enabling this configuration, every log will include request.id
and sessionInformation
in the request object.
This helps track all logs generated by an HTTP call.
Example Output:
{
"level": "error",
"time": "2024-07-01T07:07:54.877Z",
"className": "Application:Instance1",
"source": {
"caller": "callerFunctionName",
"fileName": "fileName.ts",
"path": "file path",
"line": "13",
"column": "10"
},
"message": "This is a test log",
"request": {
"id": "a15e7fc5-46b2-417d-9523-37a7c4dd467e",
"user": "userId"
},
"extra": {},
"stack": ""
}
Without Express Server: You can also start a new session wherever you need it in your application.
Logger4Node.Trace.startNewRequest(() => {
// your application logic
}, { user: 'userId' });
FAQs
![build](https://github.com/yog27ray/logger4node/actions/workflows/node.js.yml/badge.svg?branch=master) [![codecov](https://codecov.io/gh/yog27ray/logger4node/branch/master/graph/badge.svg)](https://codecov.io/gh/yog27ray/logger4node)
The npm package logger4node receives a total of 158 weekly downloads. As such, logger4node popularity was classified as not popular.
We found that logger4node demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.