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.
- π 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
npm install react-native-logkit
# o
yarn add react-native-logkitIf you want to use additional integrations:
# For Sentry
npm install @sentry/react-native
# For Crashlytics (Firebase)
npm install @react-native-firebase/crashlyticsimport { 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');import { initSentryLogger } from 'react-native-logkit/integrations';
initSentryLogger();- Logs at
ERRORlevel will be sent to Sentry - Logs at
DEBUG,INFO, andWARNwill be added as breadcrumbs
import { initCrashlyticsLogger } from 'react-native-logkit/integrations';
initCrashlyticsLogger();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>;
};import { Perf } from 'react-native-logkit';
Perf.start('fetchData');
// Your logic...
Perf.end('fetchData');import { useLogger } from 'react-native-logkit';
const MyComponent = () => {
const log = useLogger('MyComponent');
useEffect(() => {
log.info('Mounted');
}, []);
return <Text>...</Text>;
};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[]): voidLogger.setLevel(LogLevel.INFO);
Logger.getLevel(); // returns current level
Logger.reset(); // resets to defaultYou 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.
| 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 |
Logger.reset(); // Clears adapters and resets configMIT Β© IsPriamo