1.1.3 โ€ข Published 8 months ago

safe-logger v1.1.3

Weekly downloads
3
License
MIT
Repository
-
Last release
8 months ago

๐Ÿš€ safe-logger

npm version License: MIT

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

1.1.1

8 months ago

1.1.0

8 months ago

1.1.3

8 months ago

1.1.2

8 months ago

1.0.0

5 years ago