cinstance-logger
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

Error Logger

A simple error logging package for sending errors to a centralized error management system.

Installation

To install the package, run:

npm install cinstance-logger

or

yarn add cinstance-logger

Usage

Here's an example of how to use the cinstance-logger in your application:

// Import the logger
import CInstanceLogger from 'cinstance-logger';

// Initialize the logger with your app ID
const logger = new CInstanceLogger(appId, secretKey);

// Log an error with medium severity
logger.info({
  message: 'An error occurred',
  stack: 'Error stack trace',
  type: IErrorTypeEnum.TypeError,
  platform: IPlatform.Mobile,
  environment: IEnvironment.Production,
});

Or Using a Custom Logger

// Define a custom logger
const customLogger = createLogger({
  level: 'debug', // Default log level
  format: format.combine(
    format.timestamp(), // Add timestamp to logs
    format.json() // Format logs as JSON
  ),
  transports: [
    new transports.Console(), // Log to console
    new transports.File({ filename: 'logs/app.log' }) // Log to a file
  ],
});

// Instantiate the CInstanceLogger with the custom logger
const logger = new CInstanceLogger(appId, secretKey, customLogger);

API Reference

CInstanceErrorLogger(appId, secretKey)

  • appId: Your App ID for authentication.
  • secretKey: Your secretKey for authentication.
  • customLogger(optional): Your custom logger instance.

Logger Methods Overview

Method Description Parameters Returns
logger.info(errorData) Logs an error with info severity. errorData: IError Promise<void>
logger.fatal(errorData) Logs an error with fatal severity. errorData: IError Promise<void>
logger.debug(errorData) Logs an error with debug severity. errorData: IError Promise<void>
logger.error(errorData) Logs an error with error severity. errorData: IError Promise<void>

Logs an error with medium severity.

Error Data Object

The errorData 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

License

This project is licensed under the MIT License.

Package Sidebar

Install

npm i cinstance-logger

Weekly Downloads

2

Version

1.0.9

License

MIT

Unpacked Size

60.8 kB

Total Files

13

Last publish

Collaborators

  • innotex