This custom logger provides a breathable and consistent way to log messages with different levels of severity (info, success, warn, error) and includes timestamps for each log entry. It is a very light weight library designed specifically for React Native and Expo projects Javascript but it also can be used in TypeScript and CommonJS.
If you have something to contribute please visit our GitHub repository. If you consider this package helpful also you can consider support on the Buy Me a Coffee shield.
First, ensure you have the @renanmalato/logger-plus
package in your project by installing it via npm:
npm install @renanmalato/logger-plus
For React Native Import using Expo:
import Logger from '@renanmalato/logger-plus';
For Common Javascript (CommonJS):
const Logger = require('@renanmalato/logger-plus');
The Logger provides several methods for logging messages:
• 1st Case: Message and Screen name
Logger.log('Message goes here', 'Screen or Function Name');
• 2nd Case: Message, Screen name and Variable
Logger.info('Message goes here', 'Screen or Function Name', variable);
• 3rd Case: Logs only Message
Logger.info('Message goes here');
• 4th Case: Log Success with Object
Logger.success('Message goes here', 'Screen or Function Name', object);
• 5th Case: Log Box
Logger.box('Debug here', 'Screen or Function Name');
More cases...
Logger.log(message, screenOrFunction, ...messages)
Logger.success(message, screenOrFunction, ...messages)
Logger.info(message, screenOrFunction, ...messages)
Logger.warning(message, screenOrFunction, ...messages)
Logger.error(message, screenOrFunction, ...messages)
Logger.line(message, ...messages)
Logger.box(message, ...messages)
(knowing issue - Logger.line in some screens warn no formatText variable found. Working on it. Use Logger.log for more simple logging instead or console.log)
.
message (string)
: The primary log message.screenOrFunction (string, optional)
: The source of the log message, such as the screen or function name. If omitted, defaults to (not called).variable (values / objects)
: Log variable values.
import Logger from '@renanmalato/logger-plus';
const variable = "string variable";
// Basic log
Logger.log('This is a simple log message');
// Info log with source
Logger.info('Fetching data:', 'DataScreen');
// Success log
Logger.success('Data fetched successfully:', 'DataScreen', variable);
// Warn log
Logger.warn('Data fetch took too long:', 'DataScreen');
// Error log
Logger.error('Failed to fetch data:', 'DataScreen', variable);
// Line log (without source)
Logger.line('This is a simple line log');
// Line box
Logger.box('This is a box log');
import React from 'react';
import { View, Text } from 'react-native';
import Logger from '@renanmalato/logger-plus';
const ExampleComponent = () => {
const variable = "string variable";
const object = {
name: 'Renan',
age: 23,
};
useEffect(() => {
Logger.info('Message:', 'App.js');
Logger.info('Message:', 'App.js', variable);
Logger.info('Object:', 'App.js', object);
Logger.info(variable);
Logger.success('Successfully updated cart count to', 'CartScreen', variable);
Logger.warning('Warning: Cart count is getting high', 'CartScreen', object);
Logger.error('Error: Something went wrong with cart count', 'CartScreen', variable);
Logger.log('Logging a simple message');
Logger.line('This is a simple line log');
Logger.box('Debug Here');
}, []);
return (
<View>
<Text>Hello, world!</Text>
</View>
);
};
export default ExampleComponent;
If you encounter any issues or have suggestions for improvements, feel free to open an issue or submit a pull request on GitHub.
Created by renanmalato This project is licensed under the MIT License.