logstyx-js-core is a core SDK for logging in JavaScript applications. It provides a simple and efficient way to send logs to the Logstyx logging platform, allowing developers to manage log levels and contexts effectively.
Note: This is the core SDK used by framework-specific packages. Unless you're building a custom integration, you probably want one of these instead:
- React: logstyx-js-react
- React Native: logstyx-js-react-native
- Node.js: logstyx-js-node
- Browser: logstyx-js-browser
- Express: logstyx-js-express
These packages provide framework-specific features and better developer experience.
Logstyx can be self-hosted! Check out the logstyx backend repository to deploy your own instance.
When using a self-hosted instance, make sure to set the endpoint option to your deployment URL:
const logger = useLogstyx({
projectId: 'your_project_id',
endpoint: 'https://your-domain.com/api/v1/logs', // Your self-hosted instance
});- Send structured logs at different levels (info, warning, error, critical).
- Contextual logging with the ability to set and clear contexts.
- Payload sanitization to ensure valid log entries.
To install the latest version of the SDK, run:
npm install github:devatlogstyx/logstyx-js-core#releaseHere's a basic example of how to use the logstyx-js-core in your project:
const { useLogstyx } = require('logstyx-js-core');
const logger = useLogstyx({
projectId: 'your_project_id',
});
// Send an info log
logger.info({ message: "This is an info log!" });
// Send a warning log
logger.warning({ message: "This is a warning log!" });
// Send an error log
logger.error({ message: "This is an error log!" });Initializes the logger instance.
options: An object containing the following properties:projectId: The unique identifier for your project (required).apiKey: Your API key for authentication (required for server).appid: Application ID, required for mobile apps (required for mobile apps).endpoint: API endpoint to send logs to. Use your deployed instance URL (e.g.,https://your-domain.com/api/v1/logs).device: Identifier for the device sending the logs (optional).signatureFunc: A function to provide a signature for secure logging (required for server).
info(data): Sends an information log.warning(data): Sends a warning log.error(data): Sends an error log.critical(data): Sends a critical log.send(level, data): Send a log with the specified level and data.setContext(ctx): Set additional context for logging.clearContext(keys): Clear specified context keys or all context.
Contributions are welcome! Please create a pull request or raise an issue if you find a bug or have a feature request.