react-native-beautiful-logs
Version:
A beautiful, feature-rich logging library for React Native applications with colored output and file persistence
55 lines (54 loc) • 2.48 kB
TypeScript
/**
* @fileoverview Contains the core `log` function responsible for processing
* log messages, formatting them for console and file output, and handling filtering.
* @category Core
*/
/**
* Logs messages to the development console (with colors and formatting)
* and appends a plain text version to a persistent log file.
*
* Supports different log levels (`debug`, `info`, `warn`, `error`).
* Handles various data types (strings, numbers, objects, Errors).
* Allows filtering logs based on substrings defined in `LOG_FILTERS`.
* Initializes the file logging session automatically on the first call if needed.
*
* @param levelOrMessage - The log level (`'debug'`, `'info'`, `'warn'`, `'error'`) OR the first part of the message if the level is omitted (defaults to `'info'`).
* @param args - Additional parts of the log message. Can be strings, numbers, objects, Errors, etc. Objects and Errors will be formatted appropriately for console and file output. Arguments are processed in order.
*
* @example Basic Usage
* ```typescript
* import { log } from 'react-native-beautiful-logs';
*
* log('info', 'User logged in:', { userId: 123 });
* log('warn', 'Configuration value missing, using default.');
* log('error', 'Failed to load data', new Error('Network Error'));
* log('debug', 'API Response:', { status: 200, data: { /* ... *\/ } });
* ```
*
* @example Omitting Log Level (Defaults to 'info')
* ```typescript
* log('Application started.'); // Logs as 'info'
* log('User details:', { name: 'Jane Doe' }); // Logs as 'info'
* ```
*
* @example Using Module Names (Recommended)
* ```typescript
* // Include a module identifier like "[ModuleName]" as the first string argument
* // after the level (or as the first argument if level is omitted).
* log('info', '[AuthService]', 'Login attempt failed:', { reason: 'Invalid credentials' });
* log('[Network]', 'Request sent to /api/users'); // Defaults to 'info' level
* log('debug', '[DataProcessing]', 'Processing item:', item);
* ```
*
* @example Filtering
* ```typescript
* // Assuming LOG_FILTERS = ['[Network]', 'Sensitive'] in constants.ts
* log('[Network]', 'Sensitive network data...'); // This log will be skipped
* log('info', '[UserProfile]', 'User updated profile.'); // This log will be shown
* log('warn', 'Token contains Sensitive info'); // This log will be skipped
* ```
*
* @category Core
* @returns {void}
*/
export declare const log: (...args: unknown[]) => void;