Skip to content

Latest commit

 

History

History
62 lines (47 loc) · 1.51 KB

README.md

File metadata and controls

62 lines (47 loc) · 1.51 KB

@colorfy-software/logify

This is a simple wrapper for sending logs

NPM JavaScript Style Guide

Installation

$ yarn add @colorfy-software/logify

Usage

Creating a logger

// core/logging-core.ts

import Logify from '@colorfy-software/logify'

interface CustomErrorType {
  message: string
  code: number
}

const logger = new Logify<CustomErrorType>({
  endpoint: 'http://some-endpoint.com',
  // Can be an object or a function, get's added to each log
  defaultParams?: {
    userId: getUserId()
    source: 'app'
  },
  // Error here has CustomErrorType | DefaultErrorType(from lib), can parse error to be something useful
  parseError?: (error) => {
    // do stuff with error
    return parsedErrorMessage
  },
  // Condition if logs should be sent to server. Can be a function. Defaults to true
  shouldSendLogsIf?: !__DEV__,
  // Condition if logs should be shown in console. Can be a function. Defaults to true
  shouldLogToConsoleIf?: true,
  // Possibility to edit colors that are printed to console
  printColors?: {
    debug?: string,
    info?: string,
    warn?: string,
    error?: string,
    fatal?: string,
  }
})

export default logger

Using the logger

// any-file.ts

import core from '../core'

core.logger.error('userRegistrationError', gigyaError)