0.1.0 • Published 8 months ago

@xraylog/javascript-sdk v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

XRay Log JavaScript SDK

XRay Log JavaScript SDK for logging and monitoring applications. This SDK provides a simple way to log various data types with type preservation in both Node.js and browser environments.

Installation

You can install the package via npm:

npm install --save-dev @xray-log/javascript-sdk

Usage

Using Logger Class

import { XRayLogger } from '@xray-log/javascript-sdk';

// Initialize logger
const logger = new XRayLogger('Your Project Name');

// Log messages
logger.info("User logged in");
logger.error("Something went wrong");
logger.debug({ userId: 1, status: 'active' });

Using Helper Function

import { xray, setDefaultOptions } from '@xray-log/javascript-sdk';

// Set project name (optional)
setDefaultOptions({ project: 'My Project' });

// Log with default INFO level
xray("Simple message");

// Log with specific level
xray('error', "Something went wrong");
xray('debug', { userId: 1 });

Host Types

The SDK supports different host types for various environments:

  • LOCAL (default): Uses localhost:44827
  • DOCKER: Uses host.docker.internal:44827

You can configure the host type using:

const logger = new XRayLogger('docker-project', {
    hostType: XRayLogger.HOST_TYPES.DOCKER
});

Testing

npm test

License

The XRay Log JavaScript SDK is open-sourced software licensed under the MIT license.

0.1.0

8 months ago