Error logger package for your app
A simple error logging package for sending errors to a centralized error management system.
To install the package, run:
``bash`
npm install c-instance-error-logger
or
`bash`
yarn add c-instance-error-logger
Here's an example of how to use the c-instance-error-logger in your application:
`javascript
// Import the logger
import CInstanceErrorLogger from 'c-instance-error-logger';
// Initialize the logger with your secret key
const logger = new CInstanceErrorLogger('your_secret_key');
// Log an error with medium severity
logger.info({
message: 'An error occurred',
stack: 'Error stack trace',
type: 'ypeError',
platform: 'web',
environment: 'production',
});
`
- secretKey: Your secret key for authentication.
| Method | Description | Parameters | Returns |
|---------------------------|----------------------------------------|-------------|------------------|
| logger.info(errorData) | Logs an error with info severity. | errorData: IError | Promise |logger.fatal(errorData)
| | Logs an error with fatal severity. | errorData: IError | Promise |logger.debug(errorData)
| | Logs an error with debug severity. | errorData: IError | Promise |
Logs an error with medium severity.
object should include the following fields:| Field | Type | Required | Description |
|------------------|-------------------|----------|---------------------------------------------------------------|
| message | string | Yes | Description of the error |
| stack | string | Yes | Stack trace of the error |
| type | IErrorTypeEnum | Yes | Type of error (e.g., TypeError, SyntaxError) |
| environment | IEnvironment | Yes | Environment (e.g., development, production) |
| platform | IPlatform | Yes | Platform where the error occurred (e.g., web, mobile) |
| severity | ISeverity | Yes | Severity level (low, medium, high) |
| appId | string | No | Application identifier (optional) |
| sdkVersion | string | No | Version of the SDK used (optional) |
| appVersion | string | No | Version of the application (optional) |
| operatingSystem | string | No | Operating system where the error occurred (optional) |
| device | string | No | Device type (if applicable) (optional) |
| ipAddress | string | No | IP address of the source (optional) |
Enums Overview
IErrorTypeEnum
| Error Type | Value |
|------------------|----------------|
| TypeError |
typeError |
| ReferenceError | referenceError|
| SyntaxError | syntaxError |
| CustomError | customError |
| Other | other |IEnvironment
| Environment | Value |
|------------------|----------------|
| Development |
development |
| Production | production |IPlatform
| Platform | Value |
|------------------|----------------|
| Web |
web |
| Mobile | mobile |
| Desktop | desktop |ISeverity
| Severity | Value |
|----------|---------|
| fatal |
fatal |
| debug | debug |
| info | info |
| error | error` |This project is licensed under the MIT License.