react-native-autologcapture
v1.2.0
Published
Automatic log capture for React Native - captures logcat, console logs, crashes, and syncs to OpenObserve or custom logging platforms
Maintainers
Readme
AutoLogCapture
Automatic log interception library for Android and React Native applications. Captures logs from multiple sources and syncs them to your logging platform without requiring custom logging code.
Repository: https://github.com/eben-flow/android-remote-logger
Features
- Automatic Log Capture: Intercepts Android logcat and JavaScript console logs
- Direct Log Capture: Use
AutoLogAPI to bypass logcat's 4096 character truncation limit - Crash & ANR Detection: Automatically reports crashes and Application Not Responding events
- Pluggable Sync Providers: Send logs to OpenObserve, Elasticsearch, Splunk, custom HTTP endpoints, or local files
- React Native Support: Captures JavaScript console logs via bridge module
- Tag Filtering: Include/exclude specific log tags with whitelist/blacklist support
- Batch Upload: Efficient batching and GZIP compression for network efficiency
- File-based Storage: Persistent storage with automatic cleanup after successful sync
Installation
For React Native Projects (Recommended)
Step 1: Install the Package
npm install react-native-autologcapture
# or
yarn add react-native-autologcaptureStep 2: Android Native Setup
2.1. Add to android/app/build.gradle:
dependencies {
// ... other dependencies
implementation project(':react-native-autologcapture')
}2.2. Initialize in android/app/src/main/java/.../MainApplication.java:
import com.autologcapture.AutoLogCapture;
import com.autologcapture.providers.OpenObserveProvider;
import com.autologcapture.models.LogLevel;
public class MainApplication extends Application implements ReactApplication {
@Override
public void onCreate() {
super.onCreate();
// Configure OpenObserve provider
OpenObserveProvider provider = new OpenObserveProvider(
"https://api.openobserve.ai", // Your OpenObserve URL
"your-username", // Your username
"your-password", // Your password
"default", // Organization name
"android-logs" // Stream name
);
// Initialize AutoLogCapture (only initializes once)
AutoLogCapture.setSyncProvider(provider);
AutoLogCapture.init(this);
// Optional: Configure behavior
AutoLogCapture.setSyncInterval(30); // Sync every 30 seconds
AutoLogCapture.setLogLevel(LogLevel.INFO); // Only INFO and above
AutoLogCapture.setStorageLimits(
10 * 1024 * 1024, // 10 MB per file
100 * 1024 * 1024 // 100 MB total
);
// Delete logs older than 7 days
AutoLogCapture.deleteLogsOlderThan(7);
// Rest of your initialization...
}
}Step 3: Enable JavaScript Console Capture
Add to your index.js (at the very top, before anything else):
import { AppRegistry } from 'react-native';
import { initializeConsoleCapture } from 'react-native-autologcapture';
import App from './App';
import { name as appName } from './app.json';
// Initialize console capture - must be called before any console.log statements
initializeConsoleCapture();
AppRegistry.registerComponent(appName, () => App);Advanced Usage
Direct Logging API (No Truncation)
AutoLogCapture provides two ways to capture logs:
- Automatic logcat capture - Intercepts existing
Log.d/i/w/ecalls (limited to 4096 chars) - Direct capture via
AutoLog- Bypasses logcat, captures full untruncated logs
Using AutoLog for Untruncated Android Logs
Replace android.util.Log with AutoLog to capture full messages without the 4096 character limit:
import com.autologcapture.AutoLog;
// Before (truncated at 4096 chars):
Log.d("MyTag", veryLongMessage);
// After (no truncation):
AutoLog.d("MyTag", veryLongMessage);Include-Only Mode (Whitelist)
Only capture logs with specific tags:
AutoLogCapture.setIncludeOnlyMode(true);
AutoLogCapture.addIncludeTag("JSConsole"); // Capture JS console logs
AutoLogCapture.addIncludeTag("MyApp"); // Capture your app logs
AutoLogCapture.addIncludeTag("NetworkAPI"); // Capture network logs
// Or set multiple at once
AutoLogCapture.setIncludeTags("JSConsole", "MyApp", "NetworkAPI");
// Remove tags from include list
AutoLogCapture.removeIncludeTag("NetworkAPI");
// Clear all included tags
AutoLogCapture.clearIncludeTags();Block Mode (Blacklist)
Block specific tags from being captured:
// Block noisy Android system tags
AutoLogCapture.blockTag("Choreographer");
AutoLogCapture.blockTag("OpenGLRenderer");
AutoLogCapture.blockTag("GC");
// Block multiple at once
AutoLogCapture.blockTags("Choreographer", "OpenGLRenderer", "GC");
// Supports prefix matching - block all tags starting with "BF/"
AutoLogCapture.blockTag("BF/");
// Remove from blocked list
AutoLogCapture.removeBlockedTag("GC");Note: Blocked tags are filtered in both default mode and include-only mode.
Configuration Options
Sync Settings
// Sync interval (10-3600 seconds, default: 20 seconds)
AutoLogCapture.setSyncInterval(60); // Every minute
// Manual sync
AutoLogCapture.forceSync();Storage Settings
Default Storage - 5MB per file, 50MB total
Minimum storage required - 10KB per file, 5MB total
AutoLogCapture.setStorageLimits(
10 * 1024 * 1024, // 10 MB per file
100 * 1024 * 1024 // 100 MB total
);
// Configure sync batch limits to prevent oversized payloads (default: 500 entries per batch, 5MB max payload)
AutoLogCapture.setSyncBatchLimits(
1000, // Max 1000 entries per batch
10 * 1024 * 1024 // Max 10 MB per sync payload
);
// Get current batch limits
long[] limits = AutoLogCapture.getSyncBatchLimits();
int maxBatchSize = (int) limits[0]; // 1000 entries
long maxPayloadSize = limits[1]; // 10485760 bytes (10MB)File Cleanup:
- Successfully synced files are automatically deleted after upload
- Emergency cleanup triggers when storage exceeds 2x the limit
- File rotation happens when individual files exceed max size
- Old files cleaned up on app startup
Log Levels
// Minimum log level (default: DEBUG)
AutoLogCapture.setLogLevel(LogLevel.WARN); // Only WARN, ERROR, FATALCrash & ANR Settings
// Enable/disable features (default: both enabled)
AutoLogCapture.enableCrashReporting(true);
AutoLogCapture.enableANRDetection(true);
// Add crash metadata
AutoLogCapture.addCrashMetadata("userId", "12345");
AutoLogCapture.addCrashMetadata("environment", "production");Sync Providers
Generic HTTP
Send logs to any HTTP endpoint with custom headers and formatters.
import com.autologcapture.providers.GenericHttpProvider;
GenericHttpProvider provider = new GenericHttpProvider.Builder()
.endpoint("https://api.example.com/logs")
.header("Authorization", "Bearer YOUR_TOKEN")
.header("X-App-Version", "1.0.0")
.header("X-Device-Id", "device-123")
.compression(true) // Enable GZIP compression
.build();
AutoLogCapture.setSyncProvider(provider);Local File
Store logs to local files for offline scenarios.
import com.autologcapture.providers.FileProvider;
FileProvider provider = new FileProvider(context, "my-app-logs");
AutoLogCapture.setSyncProvider(provider);
// Access log files later
File[] logFiles = provider.getLogFiles();
File[] crashFiles = provider.getCrashFiles();How It Works
Sync & Upload Flow
- Log Capture → Logs captured from logcat, crashes, ANRs, and JS console
- Tag Filtering → ProcessFilter applies include/exclude rules
- File Storage → Each log saved as individual JSON file (5MB max per file, 50MB total)
- Scheduled Sync → AutoSyncScheduler runs every 20 seconds (configurable)
- Incremental Upload → Only unsynced logs uploaded (SyncState tracking)
- Auto Cleanup → Successfully uploaded files deleted automatically
File Management
Storage Limits:
- Default: 5MB per file, 50MB total
- Configurable via
setStorageLimits() - File rotation when limits exceeded
- Emergency cleanup at 2x limit threshold
Cleanup Schedule:
- On app startup: Clean old files
- After successful sync: Delete uploaded files immediately
- On storage limit change: Immediate cleanup if new limit is lower
- User-triggered:
deleteLogsOlderThan(Date)for retention policies
Crash File Handling:
- Stored separately in
/files/logs/crashes/ - Kept 7 extra days beyond regular log retention
- High-priority immediate upload
- Never auto-deleted before successful sync
Configuration
Enabling/Disabling Log Capture
By default, AutoLogCapture automatically starts capturing:
- Logcat output (disabled by default)
- Crashes and ANRs (always enabled)
- JavaScript console logs (requires manual initialization)
You can control what gets captured:
Enable Logcat Capture (Optional)
Logcat is disabled by default to save resources. Enable it if you need to capture third-party library logs:
// In MainApplication.java - before init()
AutoLogCapture.setSyncProvider(provider);
AutoLogCapture.setEnableLogcatCapture(true); // Enable logcat (uses 2 threads)
AutoLogCapture.init(this);When to enable logcat:
- You need to capture third-party library logs (they use
android.util.Log) - You have existing
Log.d/i/w/ecalls and don't want to change them - You want automatic capture without code changes
When to keep it disabled (default):
- You're only using
AutoLogAPI for direct logging - You only care about crashes/ANRs/console logs
- You want to reduce resource usage (saves 2 background threads)
- Logcat is blocked on your target devices (Knox, restricted ROMs)
Architecture
┌─────────────────────────────────────────────────────────────┐
│ AutoLogCapture API │
│ (Public static methods) │
└─────────────────┬───────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ LoggerManager │
│ (Coordinates capture, storage, sync + implements listeners)│
└──────┬──────────────────┬──────────────────┬────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────┐ ┌──────────────┐ ┌──────────────┐
│ LogcatReader│ │ CrashHandler │ │ ANRWatchdog │
│ │ │ │ │ │
│ (logcat -v │ │ (Uncaught │ │ (Main thread │
│ time) │ │ exceptions) │ │ blocking) │
└─────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ │ │
└─────────┬───────┴──────────────────┘
▼
┌─────────────────────────────────────────────────────────────┐
│ ProcessFilter │
│ (Tag filtering: include/exclude/block lists) │
└─────────────────────────┬───────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────────┐
│ FileStorage │
│ (Direct file storage with configurable limits) │
│ Default: 5MB/file, 50MB total │
└───────┬─────────────────────────────────────────────────────┘
│
├─→ SyncState (tracks synced/pending entries)
│
▼
┌─────────────────────────────────────────────────────────────┐
│ AutoSyncScheduler │
│ (20s scheduled sync + exponential backoff on failure) │
└─────────────────────────┬───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ LogSyncProvider │
│ (OpenObserve / GenericHTTP / FileProvider / Custom) │
└─────────────────────────────────────────────────────────────┘Requirements
- Android SDK 21+ (Android 5.0 Lollipop)
- React Native 0.60+ (for React Native integration)
Support
- GitHub Issues: https://github.com/eben-flow/android-remote-logger/issues
- Documentation: See CLAUDE.md and TAG_FILTERING_GUIDE.md
