safe-logger
v1.1.3
Published
A lightweight, type-safe console logging utility for JavaScript and TypeScript applications.
Downloads
50
Maintainers
Readme
🚀 safe-logger
A lightweight, type-safe console logging utility for JavaScript and TypeScript applications. Designed for developers who need reliable, formatted console logging with production safety controls.
✨ Features
- 🛡️ TypeScript support with full type definitions
- 🎨 Colored and formatted console outputs
- 🔄 Production/Development mode switching
- 🌐 Browser and Node.js compatible
- 🎯 Zero dependencies
- 📦 Tiny bundle size
- 🔒 Production-safe logging
📦 Installation
npm install safe-logger
# or
yarn add safe-logger🚀 Quick Start
import log from 'safe-logger';
// Info logging
log.i('User Service', 'User logged in successfully')();
// Warning logging
log.w('Database', 'Connection pool running high')();
// Error logging
log.e('API Error', 'Failed to fetch data', errorObject)();🔧 Advanced Usage
Initialize with Development Mode
import { LoggerClass } from 'safe-logger';
// true enables logging, false disables it
const logger = LoggerClass.init(true);Toggle Logging State
// Disable all logs
log.goSilent();
// Enable all logs
log.goLoud();🎨 Log Types
log.i()- Info logs (blue background)log.w()- Warning logs (yellow background)log.e()- Error logs (red background)
Each logging method accepts:
- Region/category string (optional)
- Multiple arguments of any type
- Requires function execution
()
🔒 Production Safety
Logs are automatically disabled in production when initialized with dev: false:
const logger = LoggerClass.init(process.env.NODE_ENV !== 'production');🧪 Testing
npm run test📚 API Reference
LoggerClass
class LoggerClass {
constructor(dev: boolean = true)
static init(dev: boolean = true): LoggerClass
goSilent(): void
goLoud(): void
i(region?: string, ...args: any[]): Function
w(region?: string, ...args: any[]): Function
e(region?: string, ...args: any[]): Function
}🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📝 License
MIT © Seif Sgayer
🔍 Keywords
console, logger, debugging, typescript, javascript, development, console-log, logging-library, debug-tools, browser-logging, node-logging, production-safe, development-tools
