Coder Social home page Coder Social logo

nest-rabbitmq-appender's Introduction

NestJS RabbitMQ Logger Appender

NPM Github Workflow Status Codecov Semantic-Release

Provide a rabbitmq logger appender like logback options style.

Inspired by spring-amqp project

Warning: In Beta

Usage

Installation

yarn add nest-rabbitmq-appender

Register Module

You should pass an AMQP connection option as register RabbitmqAppenderModule options at least with url and queue.

export type RabbitmqAppenderOptions = {
  url: string; // rabbitmq connection url
  queue: string; // rabbitmq logging queue
} & Partial<Options.Connect>;
import { Module } from '@nestjs/common';
import { RabbitmqAppenderModule } from 'nest-rabbitmq-appender';
import { ConfigService } from '@/config/config.service';
import { RemoteLogger } from '@/remote.logger';

@Module({
  imports: [
    ConfigModule,
    RabbitmqAppenderModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (config: ConfigService) => config.loggingAppenderOptions // config.loggingAppenderOptions suppose be type of `RabbitmqAppenderOptions`
    })
  ]
})
export class AppModule {}

Use RemoteLogger extending NestJS Bundled logger

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { RemoteLogger } from 'nest-rabbitmq-appender';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: false
  });
  app.useLogger(app.get(RemoteLogger));

  await app.listen(3000);
}
bootstrap();

Advanced Usage: Add Customize Data as HookFunction

RemoteLogger provided a public function: setHookFunction(hookFn) for advanced usage.

Mostly you want to add additional data when sending log data to remote message queue.

Like environment variables set from kubernetes (POD_ID,POD_UID...), or NODE_ENV in node.js application, or some dynamic value base on runtime status.

You should use an hookFunction to create additional properties when send to rabbitmq.

function hookFunction(message?:string, context?string){
  return {
    // calculate and return data according to your business logic
  }
}
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { RemoteLogger } from 'nest-rabbitmq-appender';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: false
  });
  
  const remoteLogger = app.get(RemoteLogger);
  const hookFn = () => {
    return {
      NODE_ENV: process.env.NODE_ENV,
      NODE_IP: process.env.NODE_IP,
      // or any other data in context, it will merge with origin message
    }    
  };

  remoteLogger.setHookFunction(hookFn);
  app.useLogger(remoteLogger);

  await app.listen(3000);
}
bootstrap();

nest-rabbitmq-appender's People

Contributors

aquariuslt avatar dependabot[bot] avatar renovate-bot avatar renovate[bot] avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nest-rabbitmq-appender's Issues

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

  • chore(deps): update dependency @nestjs/core to v9 [security]
  • chore(deps): update all dependencies (@nestjs/common, @nestjs/core, @nestjs/platform-express, @nestjs/testing, @types/amqplib, @types/jest, @types/lodash, @types/node, @types/supertest, @typescript-eslint/eslint-plugin, @typescript-eslint/parser, actions/checkout, actions/setup-node, codecov/codecov-action, date-fns, eslint, eslint-config-prettier, eslint-plugin-prettier, jest, prettier, reflect-metadata, rimraf, rxjs, semantic-release, supertest, ts-jest, typescript)

Detected dependencies

docker-compose
docker-compose.test.yml
  • rabbitmq 3-management
github-actions
.github/workflows/ci.yml
  • actions/checkout v3
  • codecov/codecov-action v2
  • rabbitmq 3-management
.github/workflows/publish.yml
  • actions/checkout v3
  • actions/setup-node v3
npm
package.json
  • date-fns 2.29.3
  • debug 4.3.4
  • lodash 4.17.21
  • @nestjs/common 7.6.18
  • @nestjs/core 7.6.18
  • @nestjs/platform-express 7.6.18
  • @nestjs/testing 7.6.18
  • @semantic-release/changelog 6.0.3
  • @semantic-release/git 10.0.1
  • @types/amqplib 0.10.1
  • @types/jest 29.5.1
  • @types/lodash 4.14.194
  • @types/node 18.15.13
  • @types/supertest 2.0.12
  • @typescript-eslint/eslint-plugin 5.59.0
  • @typescript-eslint/parser 5.59.0
  • amqplib 0.10.3
  • eslint 8.39.0
  • eslint-config-prettier 8.8.0
  • eslint-plugin-prettier 4.2.1
  • jest 29.5.0
  • prettier 2.8.7
  • reflect-metadata 0.1.13
  • rimraf 5.0.0
  • rxjs 7.8.0
  • rxjs-compat 6.6.7
  • semantic-release 21.0.1
  • supertest 6.3.3
  • ts-jest 29.1.0
  • typescript 5.0.4
  • @nestjs/common ^6.0.0 || ^7.0.0
  • @nestjs/core ^6.0.0 || ^7.0.0
  • amqplib ^0.5.5 || ^0.6.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0
  • reflect-metadata ^0.1.12
  • rxjs ^6.0.0 || ^7.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.