Skip to content

colorfy-software/logify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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)