A lightweight and zero dependency logging package for React and Next.js.
npm install logpack
# or
yarn add logpack
# or
pnpm add logpack
import Logpack from 'logpack';
// Log information
Logpack.info('Application started');
// Log warnings
Logpack.warn('This feature is deprecated');
// Log errors
Logpack.error('Failed to connect to the database');
// Log objects
Logpack.info({ user: 'John', role: 'admin' });
// Conditionally log (useful for environment-specific logging)
const isProduction = process.env.NODE_ENV === 'production';
Logpack.info('Debug message', { display: !isProduction });
// Configure global settings
Logpack.configure({
locale: 'tr-TR',
displayDate: true,
displayLevel: true,
displayColor: true,
});
interface Config {
locale?: string; // Locale for timestamp formatting (default: 'en-US')
dateFormat?: Record<string, string>; // Date formatting options
display?: boolean; // Whether to display logs (default: true)
displayColor?: boolean; // Enable colored logs (default: true)
displayDate?: boolean; // Show timestamps in logs (default: true)
displayLevel?: boolean; // Show log level (INFO, WARN, ERROR) (default: true)
}
You can provide configuration options:
- Globally using
Logpack.configure()
- Per log statement as a second parameter:
Logpack.info('message', config)
- Formatted timestamps with customizable locale and format
- Different log levels (info, warn, error)
- Automatic pretty-printing of objects on the server
- Conditional logging for environment-specific output
- Global configuration with per-log overrides
- TypeScript support
- Zero dependencies
MIT