@anishsharma/betterlogs
Version:
A lightweight yet powerful logging library that makes console output elegant, expressive, and customizable
151 lines (111 loc) โข 3.69 kB
Markdown
# @anish2dev/betterlogs ๐
A lightweight yet powerful logging library that makes console output elegant, expressive, and customizable for both Node.js and browsers.




## โจ Features
- ๐จ **Beautiful Themes** (dark, light, neon, minimal + custom)
- ๐ **Custom Labels & Levels**
- โฐ **Timestamps** (12h/24h format)
- ๐ **Emoji Support** (auto-toggle for unsupported terminals)
- ๐ **Browser & Node.js Support**
- ๐ **Table & JSON Logging**
- โก **TypeScript Ready**
- ๐ท๏ธ **Label-based Logging**
- โฑ๏ธ **Timer Utilities**
- ๐ **File Logging** (Node.js)
## ๐ฆ Installation
```bash
npm install @anishsharma/betterlogs
```
๐ Quick Start
```typescript
import log from '@anishsharma/betterlogs';
// Basic logging
log.info('Server starting...');
log.success('Database connected!');
log.warn('Memory usage high');
log.error('Failed to load config');
// Customization
log.config({
theme: 'neon',
showTimestamp: true,
showEmoji: true
});
// Labeled logging
log.label('API').info('Request sent');
log.label('Auth').error('Invalid token');
// Custom levels
log.addLevel('critical', { color: 'red', emoji: '๐ฅ' });
log.critical('System on fire!');
// Timer utilities
log.time('databaseQuery');
// ... some operation
log.timeEnd('databaseQuery'); // Logs: Timer 'databaseQuery': 150ms
```
๐จ Themes
```typescript
// Built-in themes
log.config({ theme: 'dark' }); // Default
log.config({ theme: 'light' });
log.config({ theme: 'neon' });
log.config({ theme: 'minimal' });
// Custom themes
log.addTheme('sunset', {
info: { color: '#FFA500', emoji: '๐
' },
success: { color: '#FF6B6B', emoji: '๐' },
// ... define all levels
});
```
๐ API Reference
Core Methods
- log.info(message, ...data)
- log.success(message, ...data)
- log.warn(message, ...data)
- log.error(message, ...data)
- log.debug(message, ...data)
Configuration
- log.config(options)
- log.setLevel(level)
- log.setMode('pretty' | 'json')
Advanced Features
- log.label(name) - Create labeled logger
- log.addLevel(name, config) - Add custom log level
- log.table(data) - Pretty-print tables
- log.time(label) / log.timeEnd(label) - Performance timing
- log.file(path) - File logging (Node.js only)
๐ Browser Usage
```html
<script type="module">
import log from 'https://esm.sh/@anishsharma/betterlogs';
log.info('Browser logging activated!');
log.success('Betterlogs works in browsers!');
</script>
```
๐ Configuration Options
```typescript
interface BetterLogsConfig {
showTimestamp?: boolean; // Default: true
showEmoji?: boolean; // Default: true
theme?: string | Theme; // Default: 'dark'
level?: LogLevel; // Default: 'info'
mode?: 'pretty' | 'json'; // Default: 'pretty'
timestampFormat?: '12h' | '24h'; // Default: '24h'
}
```
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
1. Fork the repository
2. Create your feature branch (git checkout -b feature/amazing-feature)
3. Commit your changes (git commit -m 'Add some amazing feature')
4. Push to the branch (git push origin feature/amazing-feature)
5. Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐จโ๐ป Author
Anish Sharma
ยท GitHub: @anishdevtech
ยท Email: anishdevtech@gmail.com
---
Made with โค๏ธ by Anish Sharma