1.0.9 • Published 7 months ago

cinstance-logger v1.0.9

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
7 months ago

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

MethodDescriptionParametersReturns
logger.info(errorData)Logs an error with info severity.errorData: IErrorPromise<void>
logger.fatal(errorData)Logs an error with fatal severity.errorData: IErrorPromise<void>
logger.debug(errorData)Logs an error with debug severity.errorData: IErrorPromise<void>
logger.error(errorData)Logs an error with error severity.errorData: IErrorPromise<void>

Logs an error with medium severity.

Error Data Object

The errorData object should include the following fields:

FieldTypeRequiredDescription
messagestringYesDescription of the error
stackstringYesStack trace of the error
typeIErrorTypeEnumYesType of error (e.g., TypeError, SyntaxError)
environmentIEnvironmentYesEnvironment (e.g., development, production)
platformIPlatformYesPlatform where the error occurred (e.g., web, mobile)
severityISeverityYesSeverity level (low, medium, high)
appIdstringNoApplication identifier (optional)
sdkVersionstringNoVersion of the SDK used (optional)
appVersionstringNoVersion of the application (optional)
operatingSystemstringNoOperating system where the error occurred (optional)
devicestringNoDevice type (if applicable) (optional)
ipAddressstringNoIP address of the source (optional)

Enums Overview

IErrorTypeEnum

Error TypeValue
TypeErrortypeError
ReferenceErrorreferenceError
SyntaxErrorsyntaxError
CustomErrorcustomError
Otherother

IEnvironment

EnvironmentValue
Developmentdevelopment
Productionproduction

IPlatform

PlatformValue
Webweb
Mobilemobile
Desktopdesktop

ISeverity

SeverityValue
fatalfatal
debugdebug
infoinfo
errorerror

License

This project is licensed under the MIT License.

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago