npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

movitext-app-logger

v1.0.19

Published

Registro de eventos de servidor

Downloads

1,176

Readme

NPM Package: Server Event Logger

The Server Event Logger NPM package provides an efficient solution to create, log, and track server events. With this package, you can manage event severity levels, add contextual information, and send events to a centralized monitoring system, MonitorHub.

Features

  • Create and register server events with detailed context.
  • Track events with varying severity levels (info, warning, error, critical).
  • Seamless integration with MonitorHub for centralized event management.
  • Configurable for different environments (development, staging, production).

Installation

To install the package, use the following command:

npm install movitext-app-logger

Configuration

To configure the connection to MonitorHub, import the necessary tools and set up the credentials:

import { MonitorTools } from "movitext-app-logger";

MonitorTools.setConfig({
  connection: {
    apiKey: "xxxxxxx.xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // Your API key
    url: "http://monitor-address", // MonitorHub URL
  },
  serverEvent: {
    defaultValues: {
      environment: "development", // Environment setting (development, production, etc.)
    },
    appKey: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // App-specific key for event logging
  },
});

Make sure to replace the placeholders (apiKey, url, and appKey) with your actual credentials.

Usage

  1. Create a event

Once configured, you can effortlessly log server events. Below is an example demonstrating how to create and register an event:

import { AppEvent } from "movitext-app-logger";

const event = new AppEvent({
  event: "my-event-name",
  description: "This is my event description",
  type: "info",
  severityLevel: "medium",
  context: {
    metadata1: 1,
    metadata2: {
      submetadata1: "500",
    },
    metadata3: [1, 2, 3],
  },
});
  1. Updating Event Data

You can add or modify the values of the event instance fields. This is particularly useful when the event context is updated during its execution.

event.update({
  track: "error-id",
  description: "Descripción asignada al evento",
});
  1. Updating Context

You can also directly update the context field of the event. This will merge the current values with the provided ones.

event.updateContext = {
  newMetada1: {
    newSubmetadata1: 5,
  },
};
  1. Changing Event Type

At any point, you can change the event type if your process has evolved. You can provide context as metadata that will be stored in the event's result field.


// * Update event to <warn>
event.warn({
  warningMessage: "Warning message",
  warningDetails: "Warning details",
});

// * Update event to <error>
event.error({
  errorMessage: "Error message",
  errorDetails: "Error details",
});

// * Update event to <critical>
event.critical({
  criticalMessage: "Critical message",
  criticalDetails: "Critical details",
  criticalImpact: "Critical impact",
});
  1. Registering and Saving the Event

Once the event has all the necessary information, you can register it in MonitorHub as follows:

event.register();
  1. Chaining Actions

If you wish to perform multiple actions at once, you can chain each of these actions on your event:

event
  .warn({
    data: "warning data",
  })
  .error({
    data: "warning data",
  })
  .critical({
    data: "warning data",
  })
  .update({
    track: "Process-ID",
    description: "Prueba de guardado de evento",
  })
  .register();

Event Fields

The following options are available for constructing a context for each event:

  /**
   * The event name in kebab-case format.
   * Example: 'user-login', 'data-update'
   */
  event: string;

  /**
   * The type of event being logged.
   * Example: 'critical', 'error', 'warn', 'info' default is 'info'
   */
  type?: ServerEventType;

  /**
   * The severity level of the event.
   * Indicates the importance or urgency of the event.
   * Example: 'low', 'medium', 'high', 'critical' default is 'medium'
   */
  severityLevel: ServerEventSeverityLevel;

  /**
   * Initial additional context or metadata related to the event.
   * This can be any structure that provides more detail about the event.
   */
  context: any;

  /**
   * A brief description of the event.
   * Optional field to provide additional details about what occurred. max length is 160 characters.
   */
  description?: string;

  /**
   * A tracking identifier that references the server event, request, ID, etc.
   * Optional field used to correlate this event with others.
   */
  track?: string;

  /**
   * An array of tags associated with the event.
   * Tags can help with filtering and categorizing events.
   */
  tags?: string[];

  /**
   * The environment where the event took place.
   * Example: 'development', 'production', 'staging', 'testing'
   */
  environment: Environment;

  /**
   * The result or outcome of the event after processing.
   * Optional field that can hold any information relevant to the final state (before register).
   */
  result?: any;

  /**
   * The timestamp when the event occurred.
   * If not provided, the current date and time will be used.
   */
  timestamp?: Date;

  /**
   * The IP address from which the event originated.
   * This is the source of the event in terms of network location.
   */
  sourceIp: string;

  /* The `notificationChannels: NotificationChannnel[];` in the `ServerEventParams` type is defining a
    property named `notificationChannels` which is an array of `NotificationChannnel` elements. This
    property is used to specify the notification channels through which notifications related to the
    server event should be sent.
  */
  notificationChannels?: NotificationChannnel[];