log-client-sdk
v1.0.0
Published
A JavaScript SDK for sending logs to a log server from Node.js, browsers, React, etc.
Readme
log-client-sdk (client-sdk)
A JavaScript SDK for sending logs to a log server from Node.js, browsers, React, etc.
Installation
As an npm package
npm install log-client-sdkFor local development
npm install /path/to/node-log-server/client-sdkUsage Example
import LogClient from 'log-client-sdk';
const logger = new LogClient({
serverUrl: 'http://localhost:3000',
token: 'YOUR_JWT_TOKEN'
});
logger.info('Info log');
logger.warn('Warning log');
logger.error('Error log');Options
serverUrl: Log server URL (required)token: JWT authentication token (required)
Environment Support
- Browser: uses window.fetch
- Node.js: uses fetch (Node 18+) or axios
- ESM (import/export) based
Return Value / Error Handling
- All methods return a Promise
- On success: returns server response (JSON)
- On failure: returns
{ success: false, error }and logs a warning to the console (does not affect app behavior)
Publishing/Updating
- Can be published to npm
- Good for versioning, collaboration, and reuse
Notes
- For more details on project structure/server integration, see the root README
Exception Handling
try {
await logger.error('Error occurred!');
} catch (e) {
// Handle network error, authentication failure, etc.
}Testing
Testing code can be found in client-sdk/tests/logClient.test.js
We welcome any questions or contributions!
