@goldenhippo/gh-service-utils
v1.9.12
Published
A collection of various utilities used across Golden Hippo services.
Keywords
Readme
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-utilsUsage
import { HippoLogger } from '@goldenhippo/gh-service-utils'
const log = new HippoLogger({
filePath = __filename,
brand = 'Gundry MD',
level = 'info',
requestId = 'ABC123'
})
// Unstructured Log
log.note('This is a general log message.'); // Logs: This is a general log message.
// Structured Log
log.event({
action: 'Sync Funnel Event',
status: 'In progress',
details: 'Retrieved 100 logs'
}) // Logs: [someFileName.ts] [ABC123] [master] - Brand: Gundry MD | Action: Sync Funnel Event | Status: In progress | Details: Retrieved 100 logsNote Log
The note function creates a basic logger for printing messages to the console.
Event Log
The event method creates a structured logger with options to track events like brand, action, status, and more.
HippoLogger Options
Description: Creates a structured event logger.
| Option | Type | Default | Description |
|--------------|----------|---------|------------------------------------------------------------|
| filePath | string | 'N/A' | Path to the file where the logger is used (for namespace). |
| brand | string | 'N/A' | The brand for which the log is being generated. |
| action | string | 'N/A' | Specific action being logged (e.g., "Retrieving orders"). |
| status | string | 'N/A' | Status of the action (e.g., "In progress"). |
| details | string | 'N/A' | Additional details about the log entry. |
| requestId | string | 'N/A' | Custom request ID or auto-generated by cls-rtracer. |
| level | string | 'info'| Log level (info, error, etc.). |
