Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
ts-composite-logger
Advanced tools
Logger written in typescript. Includes a console channel by default. Allows to add other log channels by extending ILogChannel interface.
Use this package in your applications for logging. Out of the box the package outputs logs to console. You can create more custom channels and send data to them as well, dynamically add and remove them. The advantage of this logger is that it's easy to extend it.
npm install -S ts-composite-logger
import {Logger, Console, LogLevel} from "ts-composite-logger";
const console = new Console();
console.setFormat("hh:mm:ss.SSS"); // this is default
global.logger = (new Logger())
.addChannel(console)
.setLevel(LogLevel.INFO);
global.logger.info("VM connected");
Available log levels:
By default debug log level is selected. Which means that every log reqest will be fullfilled.
Format string can be anything, but the following letters will be replaced (and leading zeroes added if necessary):
date.getDate()
date.getMonth() + 1
date.getFullYear().toString().substring(2, 4)
date.getFullYear()
date.getHours()
date.getMinutes()
date.getSeconds()
date.getMilliseconds()
The underlying package to format dates is date-format. You can find more details here
This example demonstrates how to create a MongoDB channel. The implementation can be found here.
Create a class that implements ILoggerChannel interface.
import assert from "assert";
import {MongoClient} from "mongodb";
import {ILoggerChannel} from "ts-composite-logger";
import {ILogMessage} from "ts-composite-logger";
export class MongoDB implements ILoggerChannel {
private readonly connectUrl: string;
private readonly dbName: string;
private readonly collectionName: string;
private client;
constructor(url: string, db: string, collection: string) {
this.connectUrl = url;
this.dbName = db;
this.collectionName = collection;
}
public async write(message: ILogMessage) {
if (!this.client) {
throw new Error("Channel not connected to DB");
}
const db = this.client.db(this.dbName);
const collection = db.collection(this.collectionName);
await this.insert(collection, message);
}
private insert(collection, message: ILogMessage) {
return new Promise((resolve, reject) => {
collection.insertOne(message, (error, result) => {
if (error) {
return reject(error);
}
return resolve();
});
});
}
public connect(): Promise<ILoggerChannel> {
return new Promise((resolve, reject) => {
MongoClient.connect(this.connectUrl, { useNewUrlParser: true }, (err, client) => {
try {
assert.strictEqual(null, err);
} catch (e) {
return reject(e);
}
this.client = client;
resolve(this);
});
});
}
}
Now you can add an instance of this class to the composite logger by calling addChannel method.
FAQs
Logger written in typescript. Includes a console channel by default. Allows to add other log channels by extending ILogChannel interface.
We found that ts-composite-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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.