@xraylog/javascript-sdk
Version:
XRay Logger JavaScript SDK for real-time logging and debugging
76 lines (51 loc) • 2.17 kB
Markdown
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.
<p align="center">
<a href="https://github.com/XRay-Log/javascript-sdk/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/XRay-Log/javascript-sdk/test.yml?label=tests" alt="Build Status"></a>
<a href="https://www.npmjs.com/package/@xraylog/javascript-sdk"><img src="https://img.shields.io/npm/dt/@xraylog/javascript-sdk" alt="Total Downloads"></a>
<a href="https://www.npmjs.com/package/@xraylog/javascript-sdk"><img src="https://img.shields.io/npm/v/@xraylog/javascript-sdk" alt="Latest Stable Version"></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/npm/l/@xraylog/javascript-sdk" alt="License"></a>
</p>
You can install the package via npm:
```bash
npm install --save-dev @xraylog/javascript-sdk
```
```javascript
import { XRayLogger } from '@xraylog/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' });
```
```javascript
import { xray, setDefaultOptions } from '@xraylog/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 });
```
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:
```javascript
const logger = new XRayLogger('docker-project', {
hostType: XRayLogger.HOST_TYPES.DOCKER
});
```
```bash
npm test
```
The XRay Log JavaScript SDK is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).