@goldenhippo/gh-service-utils
v1.1.0
Published
A collection of various utilities used across Golden Hippo services.
Downloads
91
Maintainers
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-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.
| 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.). |