A package that acts as a receiver for smartlog-destination-receiver, utilizing plugins for functionality.
Go to file
2024-05-29 14:14:27 +02:00
.vscode fix(core): update 2022-03-07 22:08:32 +01:00
test BREAKING CHANGE(core): switch to esm 2022-07-27 12:34:41 +02:00
ts BREAKING CHANGE(core): switch to esm 2022-07-27 12:34:41 +02:00
.gitignore fix(core): update 2020-06-07 12:41:25 +00:00
.gitlab-ci.yml BREAKING CHANGE(core): switch to esm 2022-07-27 12:34:41 +02:00
license fix(core): initial 2018-10-31 17:42:18 +01:00
npmextra.json update tsconfig 2024-04-14 17:54:11 +02:00
package-lock.json 2.0.0 2022-07-27 12:34:42 +02:00
package.json update description 2024-05-29 14:14:27 +02:00
pnpm-lock.yaml switch to new org scheme 2023-07-11 01:05:39 +02:00
readme.hints.md update tsconfig 2024-04-14 17:54:11 +02:00
readme.md update tsconfig 2024-04-14 17:54:11 +02:00
tsconfig.json update npmextra.json: githost 2024-04-01 21:36:18 +02:00

@push.rocks/smartlog-receiver

a receiver for smartlog-destination-receiver

Install

To install @push.rocks/smartlog-receiver, use the following command with npm:

npm install @push.rocks/smartlog-receiver --save

or with yarn:

yarn add @push.rocks/smartlog-receiver

Ensure that you have TypeScript and Node.js installed in your development environment as this module leverages TypeScript for type definitions.

Usage

The @push.rocks/smartlog-receiver module is designed to receive log messages sent from applications using the smartlog logging system. It allows for centralized logging by receiving, validating, and processing log messages in a secure and controlled manner. Below, we'll go through how to set up and use smartlog-receiver in your project.

Setting up SmartlogReceiver

First, make sure to import SmartlogReceiver from the package, along with the types it depends on if necessary.

import { SmartlogReceiver, ISmartlogReceiverOptions } from '@push.rocks/smartlog-receiver';
import { Smartlog } from '@pushrocks/smartlog';

SmartlogReceiver requires an instance of Smartlog for logging internal messages and potentially logging the received log messages. Ensure you initialize Smartlog first:

const smartlogInstance = new Smartlog({
  logContext: {
    company: 'YourCompany',
    companyunit: 'YourUnit',
    environment: 'production',
    runtime: 'node',
    version: '1.0.0'
  },
  minimumLogLevel: 'info',
});
smartlogInstance.enableConsole(); // Enabling console output for demonstration purposes

Now, instantiate the SmartlogReceiver with the necessary options. You need to provide a passphrase for authentication and a validator function that decides whether to accept or reject incoming messages based on your criteria.

const smartlogReceiver = new SmartlogReceiver({
  smartlogInstance: smartlogInstance,
  passphrase: 'yourSecretPassphrase',
  validatorFunction: async (logPackage) => {
    // Example validation: accept only if message contains 'accepted'
    return logPackage.message.includes('accepted');
  },
});

Handling Log Messages

To handle authenticated log messages, you'd typically have an endpoint in your application that receives log packages. Here, we'll simulate receiving a log package.

import { ILogPackageAuthenticated } from '@pushrocks/smartlog-interfaces';
import * as smarthash from '@pushrocks/smarthash';

// Simulated received log message
const receivedLogPackage: ILogPackageAuthenticated = {
  auth: smarthash.sha256FromStringSync('yourSecretPassphrase'), // Generate hash of your passphrase for authentication
  logPackage: {
    timestamp: Date.now(),
    context: {
      company: 'YourCompany',
      companyunit: 'YourUnit',
      environment: 'production',
      runtime: 'node',
      version: '1.0.0'
    },
    level: 'info',
    type: 'log',
    message: 'This is an accepted log message',
    correlation: {
      id: 'unique-correlation-id',
      type: 'transaction'
    }
  }
};

// Handler function to process received log packages
async function handleReceivedLog(logPackage: ILogPackageAuthenticated) {
  const result = await smartlogReceiver.handleAuthenticatedLog(logPackage);
  console.log(result); // Should output { status: 'ok' } for successfully processed messages
}

handleReceivedLog(receivedLogPackage);

Ensure your validation and handling logic fits the security and architectural needs of your application.

Advanced Usage

  • Batch Processing: SmartlogReceiver also supports processing batches of logs efficiently through the method handleManyAuthenticatedLogs, facilitating bulk log management.

  • Customizing Smartlog: Since SmartlogReceiver uses Smartlog for its operations, you can harness the full power of Smartlog for detailed customization, such as setting up different log destinations, filtering log levels, and more.

By setting up @push.rocks/smartlog-receiver, you're enabling a robust and flexible system to manage your application's logging infrastructure, making it easier to monitor and debug with centralized logs.

This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.