1.0.0 โข Published 6 years ago
safe-logger v1.0.0
๐ 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:
1. Region/category string (optional)
2. Multiple arguments of any type
3. 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