
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
nodejs-logsage
Advanced tools
Powerful logger module for NestJS, seamlessly integrating Pino and Winston for flexible logging with easy configuration.
nodejs-logsage
is an innovative logging solution designed specifically for Node.js applications. This pioneering logger package facilitates distributed logging within the Node.js ecosystem, built on top of both Winston and Pino. This unique combination offers unparalleled flexibility, allowing developers to seamlessly switch between Pino and Winston as the underlying logging mechanism, and customize logging behavior to suit their needs.
Inspired by Java's Mapped Diagnostic Context (MDC) pattern, nodejs-logsage
revolutionizes distributed tracing in Node.js applications. Similar to how the MDC pattern empowers Java developers with comprehensive logging capabilities, this logger package extends similar capabilities to the Node.js environment, enabling efficient management of contextual information across asynchronous operations.
Install the package via npm:
npm install nodejs-logsage
Initialize the logger service. You have two LoggerType
options: PINO
and WINSTON
.
// logger.ts
import { LoggerService, LoggerType } from 'nodejs-logsage';
const logger = new LoggerService({
type: LoggerType.PINO,
options: {
transport: {
targets: [
{
target: 'pino-pretty',
options: {
destination: 'api.log',
singleLine: true,
colorize: false,
levelFirst: false,
translateTime: 'dd-mm-yyyy hh:mm:ss TT',
},
},
{
target: 'pino-pretty',
options: {
singleLine: true,
colorize: true,
levelFirst: false,
translateTime: 'dd-mm-yyyy hh:mm:ss TT',
},
},
],
},
},
});
export default logger;
In your Express server, call logsageMiddleware
to inject the trace ID into logs and network requests.
// app.ts
import express from 'express';
import { logsageMiddleware } from 'nodejs-logsage';
import logger from './logger.ts';
const app = express();
logsageMiddleware(app);
const PORT = process.env.PORT ?? 1337;
app.listen(PORT, () => logger.info(`Listening on port: ${PORT}`));
Example output:
[30-05-2024 12:05:43 PM] INFO: Listening on port: 1337
# [time] [level]: [message]
You can also log the method name and execution time:
import express from 'express';
import {
logsageMiddleware,
EXECUTION_LOG_CALLER,
EXECUTION_LOG_START_TIME,
} from 'nodejs-logsage';
import logger from './logger.ts';
const app = express();
logsageMiddleware(app);
app.get('/', (req, res) => {
const newTime = new Date().getTime();
logger.info('Inside app route', { count: 1 });
setTimeout(() => {
logger.info('Inside app route after 5s', {
count: 1,
[EXECUTION_LOG_START_TIME]: newTime,
[EXECUTION_LOG_CALLER]: 'APP ROUTE',
});
}, 5000);
res.send('Hello World!');
});
const PORT = process.env.PORT ?? 1337;
app.listen(PORT, () => logger.info(`Listening on port: ${PORT}`));
Example output:
[30-05-2024 12:05:43 PM] INFO: [4bcbd8d9-793c-4618-858f-c509fe00cee9]:Inside app route {"count":1} {"x-trace-id":"4bcbd8d9-793c-4618-858f-c509fe00cee9"}
[30-05-2024 12:05:43 PM] INFO: [4bcbd8d9-793c-4618-858f-c509fe00cee9]:{"method":"GET","url":"/","headers":{"host":"localhost:1337","user-agent":"curl/8.4.0","accept":"*/*","x-trace-id":"4bcbd8d9-793c-4618-858f-c509fe00cee9"},"query":{}} {"x-trace-id":"4bcbd8d9-793c-4618-858f-c509fe00cee9"}
[30-05-2024 12:05:48 PM] INFO: [4bcbd8d9-793c-4618-858f-c509fe00cee9]:[APP ROUTE: 5001 ms]:Inside app route after 5s {"count":1,"EXECUTION_LOG_START_TIME":1717073323863,"EXECUTION_LOG_CALLER":"APP ROUTE"} {"x-trace-id":"4bcbd8d9-793c-4618-858f-c509fe00cee9"}
# [time] [level]: [traceId]:[methodName: execution time in ms]: message
If you have suggestions for improvements, bug reports, or other contributions, please feel free to open an issue or create a pull request.
This project is licensed under the MIT
License.
FAQs
Powerful logger module for NestJS, seamlessly integrating Pino and Winston for flexible logging with easy configuration.
We found that nodejs-logsage demonstrated a not healthy version release cadence and project activity because the last version was released 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
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.