Skip to content

edwardloopez/react-native-logkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

๐Ÿ“ React Native LogKit

npm version license

A flexible, modular, and extensible logging system for React Native apps โ€” with built-in support for performance monitoring, visual error overlays, and integrations like Sentry and Crashlytics.


โœจ Features

  • ๐Ÿ“Š Multiple log levels: DEBUG, INFO, WARN, ERROR, PERF, MID
  • ๐ŸŽจ Color-coded logs in the console
  • โš™๏ธ Configurable output and behavior
  • ๐Ÿงฉ Optional integrations: Sentry, Firebase Crashlytics, custom remotes
  • ๐Ÿงต Tag-based logging for better categorization
  • ๐Ÿงช Performance tracking with hooks and utility methods
  • โšก Lightweight core, with modular opt-in extensions

๐Ÿ“ฆ Installation

npm install react-native-logkit
# o
yarn add react-native-logkit

๐Ÿ“ฆ Optional dependencies

If you want to use additional integrations:

# For Sentry
npm install @sentry/react-native

# For Crashlytics (Firebase)
npm install @react-native-firebase/crashlytics

๐Ÿ”ฐ Basic Usage

import { Logger } from 'react-native-logkit';

Logger.debug('Auth', 'Login started');
Logger.info('User', 'User logged in', { id: '123' });
Logger.warn('API', 'Slow response time');
Logger.error('Network', 'Connection failed');

๐Ÿ”Œ Integrations

โœ… Enable Sentry

import { initSentryLogger } from 'react-native-logkit/integrations';

initSentryLogger();
  • Logs at ERROR level will be sent to Sentry
  • Logs at DEBUG, INFO, and WARN will be added as breadcrumbs

โœ… Enable Crashlytics

import { initCrashlyticsLogger } from 'react-native-logkit/integrations';

initCrashlyticsLogger();

โฑ๏ธ Performance Tracking

With React Components

import { usePerformance } from 'react-native-logkit';

const MyComponent = () => {
  const perf = usePerformance('MyComponent');

  useEffect(() => {
    perf.start('fetchData');

    fetchData().then(() => {
      perf.end('fetchData');
    });
  }, []);

  return <Text>Hello</Text>;
};

As a Utility (non-component)

import { Perf } from 'react-native-logkit';

Perf.start('fetchData');

// Your logic...

Perf.end('fetchData');

๐Ÿช useLogger (React Hook)

import { useLogger } from 'react-native-logkit';

const MyComponent = () => {
  const log = useLogger('MyComponent');

  useEffect(() => {
    log.info('Mounted');
  }, []);

  return <Text>...</Text>;
};

๐Ÿ“š API Reference

Logger Methods

Logger.debug(tag: string, ...args: any[]): void
Logger.info(tag: string, ...args: any[]): void
Logger.warn(tag: string, ...args: any[]): void
Logger.error(tag: string, ...args: any[]): void

Configuration

Logger.setLevel(LogLevel.INFO);
Logger.getLevel(); // returns current level
Logger.reset(); // resets to default

๐Ÿ”Œ Custom Adapters

You can register adapters to handle logs in custom ways:

Logger.registerAdapter({
  key: 'customAdapter',
  log: (level, tag, message) => {
    console.log('๐Ÿ”„ Forwarded log:', level, tag, message);
  },
});

To avoid duplicates, adapters must have a unique key.


๐Ÿงช Log Levels

Level Description
DEBUG Detailed debug info
INFO Informational messages
WARN Warning conditions
ERROR Error conditions
SILENT Disable all logging
PERF Performance tracking
MID Middleware logging

๐Ÿงผ Reset / Clean Logs

Logger.reset(); // Clears adapters and resets config

๐Ÿ“„ License

MIT ยฉ IsPriamo


About

A flexible and powerful logging toolkit for React Native apps

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

โšก