@dyxbenjamin/react-log-simplified
v1.1.3
Published
A simplified logging library for web applications
Readme
@dyxbenjamin/react-log-simplified
A simplified logging library for web applications.
Installation
npm install @dyxbenjamin/react-log-simplifiedbun add @dyxbenjamin/react-log-simplifiedUsage
Simple Logs
import { log } from '@dyxbenjamin/react-log-simplified';
log.info('This is an information message.');
log.warn('This is a warning message.');
log.error('This is an error message.');Structured Logs
For more detailed and organized logs, you can use structured logging. This is useful for passing more context about the log entry.
import { log } from '@dyxbenjamin/react-log-simplified';
log.info({
title: 'User Logged In',
description: 'User successfully authenticated and session created.',
data: {
userId: '12345',
username: 'testuser'
},
toast: true, // Show a toast notification
persist: true, // Persist the log in localStorage
prod: false, // Log only in development
disabled: false // Disable this specific log
});Structured Log Parameters
title(string, required): The main title of the log entry.description(string, optional): A more detailed description.data(any, optional): Any additional data to be logged.toast(boolean, optional): Whether to show a toast notification. Defaults totrue.persist(boolean, optional): Whether to persist the log inlocalStorage. Defaults totrue.prod(boolean, optional): Iftrue, the log will also be shown in production environments. Defaults tofalse.disabled(boolean, optional): Iftrue, the log will be completely disabled. Defaults tofalse.
Configuration
The library can be configured using environment variables.
LOGS_TOASTS(boolean): Set totrueto enable toast notifications for all logs by default.LOGS_PERSISTENCE(boolean): Set totrueto enable log persistence inlocalStoragefor all logs by default.LOGS_MAX_ENTRIES(number): The maximum number of log entries to store inlocalStorage. Defaults to200.
License
This project is licensed under the MIT License. See the LICENSE file for details.
