1.1.0 • Published 1 year ago

@colorfy-software/logify v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@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 { MMKV } from 'react-native-mmkv'
import Logify from '@colorfy-software/logify'

interface CustomErrorType {
  message: string
  code: number
}

export const logsStorage = new MMKV({ id: 'logs' })

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: '#FFFFFF',
    info: '#ADD8E6',
    warn: '#FFA500',
    error: '#FF0000',
    fatal: '#FF0000',
  },
  // Storage configuration
  storage: {
    key: 'logs',
    getItem: (key: string): string | null => logsStorage.getString(key) ?? null,
    setItem: (key: string, value: string) => logsStorage.set(key, value),
  }
})

export default logger

Using the logger

// any-file.ts

import core from '../core'

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

1 year ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago