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.
lbx-persistence-logger
Advanced tools
This packages aims to take care of most of your logging concerns, including:
This library was built with customization in mind, so most things can easily be modified.
The minimum required code changes to use the library to its full extend is simply registering it in the application.ts
:
import { LbxPersistenceLoggerComponent, LogRepository } from 'lbx-persistence-logger';
export class MyApplication extends BootMixin(ServiceMixin(RepositoryMixin(RestApplication))) {
constructor(options: ApplicationConfig = {}) {
// ...
this.component(LbxPersistenceLoggerComponent);
this.repository(LogRepository);
// ...
}
}
If you don't want to use the predefined repositories you can create your own and bind them to the corresponding key in LbxPersistenceLoggerComponentBindings
.
Everything above comes from the library out of the box.
When your application has a fatal error, you will most likely want to be notified.
For this the library provides the LbxPersistenceLoggerComponentBindings.LoggerNotificationService
Binding, where you can provide a service for that.
import { BindingScope, bind } from '@loopback/core';
import { Log, LoggerNotificationService } from 'lbx-persistence-logger';
@bind({ scope: BindingScope.TRANSIENT })
export class EmailService implements LoggerNotificationService {
async notify(log: Log): Promise<void> {
console.log('Do something with the log')
}
}
In the application.ts constructor:
this.bind(LbxPersistenceLoggerComponentBindings.LOGGER_NOTIFICATION_SERVICE).toClass(EmailService);
If you want to use this library just as easy as console.log you can provide a global object. That way you don't need to inject the service all the time:
import { LbxPersistenceLoggerComponentBindings, LoggerService } from 'lbx-persistence-logger';
export let logger: LoggerService;
export async function main(options: ApplicationConfig = {}): Promise<ShowcaseApplication> {
const app: ShowcaseApplication = new ShowcaseApplication(options);
await app.boot();
await app.migrateSchema();
await app.start();
// ...
logger = await app.get(LbxPersistenceLoggerComponentBindings.LOGGER_SERVICE);
// ...
const url: string | undefined = app.restServer.url;
logger.info(`Server is running at ${url}`, `Try ${url}/ping`);
return app;
}
That's it, now you can use the logger inside your code.
This library does not provide a controller out of the box, because you will probably need to implenent auth and other things.
An example controller could be created like the following:
import { repository } from "@loopback/repository";
import { del, get, getModelSchemaRef, param, post, requestBody } from "@loopback/rest";
import { SecurityBindings, securityId } from '@loopback/security';
import { Log, LogRepository, LogWithRelations } from "lbx-persistence-logger";
import { logger } from "../index";
// ...
export class LogController {
constructor(
@repository(LogRepository)
private readonly logRepository: LogRepository,
) { }
@post('/logs', {
responses: {
'200': {
content: {
'application/json': {
schema: getModelSchemaRef(Log)
}
}
}
}
})
async create(
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Log, {
exclude: ['id', 'createdAt', 'lifetime', 'userId']
})
}
}
})
log: Omit<Log, 'id' | 'createdAt' | 'lifetime' | 'userId'>,
@inject(SecurityBindings.USER)
userProfile: UserProfile
): Promise<LogWithRelations> {
return logger.createLogAndNotify(new Date(), log.application, userProfile[securityId], log.level, log.error, log.data)
}
@get('/logs', {
responses: {
'200': {
content: {
'application/json': {
schema: {
type: 'array',
items: getModelSchemaRef(Log)
}
}
}
}
}
})
async find(): Promise<Log[]> {
return this.logRepository.find();
}
@del('/logs/{id}')
async deleteById(
@param.path.string('id')
id: string
): Promise<void> {
await this.logRepository.deleteById(id);
}
}
If you want to log all errors that occur, you can use the provided ErrorInterceptorProvider:
// application.ts
import { ErrorInterceptorProvider } from 'lbx-persistence-logger';
constructor() {
//...
this.interceptor(ErrorInterceptorProvider, { global: true, group: 'error-handling' });
//...
}
WARNING:
The interceptor will NOT rethrow the error. If you use global interceptors on >your own, you need to make sure that the error interceptor is called last (see loopback order of invocation for interceptors).
This is because loopback would otherwise log the error internally => you would have 2 logs for the same error.
The library is highly customizable through the usage of Bindings:
import { LbxInvoiceBindings } from 'lbx-persistence-logger';
// ...
Binding.bind(LbxPersistenceLoggerComponentBindings.LOGGER_SERVICE).toClass(MyCustomLoggerService),
// ...
All bindings can be accessed under LbxPersistenceLoggerComponentBindings
.
FAQs
Open Source
The npm package lbx-persistence-logger receives a total of 0 weekly downloads. As such, lbx-persistence-logger popularity was classified as not popular.
We found that lbx-persistence-logger demonstrated a healthy version release cadence and project activity because the last version was released less than 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.