1.1.0 • Published 9 months ago

@goldenhippo/gh-service-utils v1.1.0

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
9 months ago

Golden Hippo Service Utilities

A collection of general utilities designed to streamline logging, event tracking, and other common operations across multiple services at Golden Hippo. This package is intended to be flexible, reusable, and easily integrated into various applications.

Features

  • General Logger: A simple logger for outputting unstructured text messages.
  • Event Logger: A structured logger for tracking events with customizable options like brand, action, status, request ID, etc.

Installation

npm install @goldenhippo/gh-service-utils // UPDATE

Usage

General Logger

The generalLog function creates a basic logger for printing messages to the console.

import { generalLog } from '@goldenhippo/gh-service-utils'; // UPDATE

const logger = generalLog();
logger('This is a general log message.');

Event Logger

The eventLog function creates a structured logger with options to track events like brand, action, status, and more.

import { eventLog } from '@goldenhippo/gh-service-utils'; // UPDATE

const logger = eventLog({
    filePath: __filename,
    brand: 'ActivatedYou',
    action: 'Retrieving orders',
    status: 'In progress',
    requestId: '12345',
    level: 'info',
});

logger({
    details: 'Retrieved 100 orders successfully.',
});

API Reference

generalLog()

Description: Creates a logger for simple, unstructured messages.

generalLog(): (message: string) => void

eventLog(options: Partial<EventLogOptions>)

Description: Creates a structured event logger.

OptionTypeDefaultDescription
filePathstring'N/A'Path to the file where the logger is used (for namespace).
brandstring'N/A'The brand for which the log is being generated.
actionstring'N/A'Specific action being logged (e.g., "Retrieving orders").
statusstring'N/A'Status of the action (e.g., "In progress").
detailsstring'N/A'Additional details about the log entry.
requestIdstring'N/A'Custom request ID or auto-generated by cls-rtracer.
levelstring'info'Log level (info, error, etc.).
1.1.0

9 months ago

1.0.0

9 months ago