Skip to content

Releases: onamfc/developer-log

v1.2.4 - Improve RN Compatibility

27 Jan 17:30

Choose a tag to compare

Add safe console method binding to prevent crashes in React Native environments where some console methods may be undefined.

v1.2.2 - Add RN Support

15 Nov 05:36

Choose a tag to compare

Add React Native support by using dev.configure() for filtering instead of file-based config

v1.2.1 - Add Tag-Based Log Filtering

15 Nov 04:57

Choose a tag to compare

Summary

This PR adds optional tag-based filtering functionality to @onamfc/developer-log, allowing developers to filter logs by category/feature during development. This feature helps reduce console noise and enables focused debugging without commenting out code.

Key Features

Tag-Based Filtering

  • Add optional tags to any log method using { tag: 'category' } as the last parameter
  • Filter which logs appear based on enabled tags
  • Untagged logs always show (maintains backward compatibility)

Flexible Configuration

  • Auto-load: Automatically loads config from project root (e.g., dev-log.config.json)
  • Programmatic: dev.configure({ enabledTags: ['database', 'api'] })
  • Explicit file loading: dev.loadConfig('./path/to/config.json')

Smart Filtering Logic

  • No config: All logs show (tagged and untagged)
  • With config: Only untagged logs + enabled tags show
  • Production: Everything suppressed (existing behavior preserved)

Usage Examples

Basic Usage

import { dev } from '@onamfc/developer-log';

// Tagged logs
dev.log('Database connected', { tag: 'database' });
dev.error('API request failed', error, { tag: 'api' });

// Untagged logs (always show)
dev.log('Application started');

Auto-Load Configuration (Recommended)

// 1. Create dev-log.config.json in your project root:
// {
//   "enabledTags": ["database", "auth"]
// }

// 2. Just import and use - config loads automatically!
import { dev } from '@onamfc/developer-log';

dev.log('Query executed', { tag: 'database' }); // Shows if enabled

Supported auto-load file names (checked in order):

  • dev-log.config.json
  • .devlogrc.json
  • .devlogrc

Manual Configuration

// Programmatic configuration
dev.configure({ enabledTags: ['database', 'auth'] });

// Or load from a specific path
dev.loadConfig('./config/dev-log.config.json');

Config File Format

{
  "enabledTags": ["database", "api", "auth"]
}

Where to place dev.configure() (if using programmatic config):

  • Main entry point: index.ts, app.ts, server.ts, main.ts
  • Before any code that uses tagged logs
  • Framework-specific locations:
    • Express/Node.js: Top of server file
    • Next.js: _app.tsx or layout.tsx
    • React: index.tsx or App.tsx
    • NestJS: main.ts before app.listen()

Real-World Scenarios

Debugging a specific feature:

dev.log('Fetching user profile', { tag: 'profile' });
dev.log('Loading dashboard', { tag: 'dashboard' });

// Focus on profile debugging
dev.configure({ enabledTags: ['profile'] });

Dynamic configuration via environment:

if (process.env.DEBUG_TAGS) {
  dev.configure({
    enabledTags: process.env.DEBUG_TAGS.split(',')
  });
}
// Run with: DEBUG_TAGS=database,api npm start

Technical Implementation

New Interfaces

interface LogOptions {
  tag?: string;
}

interface Config {
  enabledTags?: string[];
}

New Methods

  • dev.configure(config: Config): void - Programmatic configuration
  • dev.loadConfig(filePath: string): void - Load config from JSON file
  • autoLoadConfig() - Internal function that runs at module import (not exported)

Core Logic

  1. Auto-Load: At module import time, searches for config files in project root (dev-log.config.json, .devlogrc.json, .devlogrc)
  2. Tag Extraction: Checks if last argument is a plain object with tag property
  3. Tag Stripping: Removes options object before passing to console methods
  4. Filtering: Compares tag against enabled tags Set (O(1) lookup)
  5. Production Override: Production check always takes precedence

Files Changed

Modified

  • src/index.ts

    • Added imports for fs and path modules
    • Added LogOptions and Config interfaces
    • Implemented configuration state management
    • Created autoLoadConfig() function for automatic config detection and loading
    • Created extractTagFromArgs() helper function
    • Implemented createLogMethod() wrapper with filtering logic
    • Added configure() and loadConfig() methods
    • Call autoLoadConfig() at module initialization
    • Updated all console method bindings to use wrapper
  • README.md

    • Updated package description
    • Added tag examples to Usage section
    • Added comprehensive Tag-Based Filtering section
    • Added Practical Examples with 3 real-world scenarios
    • Updated "Why Use This?" section with new benefits
    • Enhanced Migration section with tag adoption guide

Breaking Changes

None. This is a fully backward-compatible change:

  • Existing code without tags works exactly as before
  • Default behavior unchanged (all logs show when no config is set)
  • Production behavior unchanged (all logs suppressed)

Migration Guide

No changes required for existing users

The package remains fully backward compatible. Existing code continues to work:

// This still works exactly as before
dev.log('Hello, world!');
dev.error('An error', error);

Optional: Adopt tag filtering

Users can progressively adopt tags where useful:

// Step 1: Keep existing logs as-is (they'll always show)
dev.log('App started'); // No tag - always shows

// Step 2: Add tags to logs you want to filter
dev.log('Query executed', result, { tag: 'database' });
dev.error('Request failed', error, { tag: 'api' });

// Step 3: Configure filtering as needed
dev.configure({ enabledTags: ['database'] });
// Now: 'App started' and database logs show, api logs hidden

v1.1.1 - Renamed Export

01 Oct 21:27

Choose a tag to compare

Renamed Export for Better Developer Experience

The main export has been renamed from developer to dev for improved ergonomics and shorter, cleaner code.

Why This Change?

  • Shorter and more intuitive: dev is quicker to type and reads more naturally in code
  • Common convention: Aligns with industry standards for development-only utilities
  • Better DX: Reduces verbosity while maintaining clarity

V1.1.0 - Renamed Export

01 Oct 21:19

Choose a tag to compare

Renamed Export for Better Developer Experience

The main export has been renamed from developer to dev for improved ergonomics and shorter, cleaner code.

Why This Change?

  • Shorter and more intuitive: dev is quicker to type and reads more naturally in code
  • Common convention: Aligns with industry standards for development-only utilities
  • Better DX: Reduces verbosity while maintaining clarity

v1.0.0 - Initial Release

30 Sep 20:59
f0d0351

Choose a tag to compare

Initial Release

I am excited to announce the first official release of @onamfc/developer-log - a lightweight, zero-dependency console wrapper that automatically suppresses debug output in production environments.


Features

Core Functionality

  • Automatic Production Suppression: All console output is automatically silenced when NODE_ENV=production, keeping your production logs clean
  • Drop-in Replacement: Use developer exactly like you would use console - no learning curve
  • Zero Dependencies: Lightweight package with no external dependencies
  • Full TypeScript Support: Built with TypeScript, includes type definitions out of the box

Supported Console Methods

All standard console methods are fully supported:

Basic Logging

  • log() - General logging
  • error() - Error messages
  • warn() - Warning messages
  • info() - Informational messages
  • debug() - Debug messages

Advanced Methods

  • trace() - Stack trace
  • table() - Tabular data display
  • dir() - Object inspection
  • dirxml() - XML/HTML element inspection

Grouping

  • group() - Create message groups
  • groupCollapsed() - Create collapsed message groups
  • groupEnd() - End message groups

Timing & Performance

  • time() - Start timers
  • timeEnd() - End timers
  • timeLog() - Log elapsed time at checkpoints

Utilities

  • count() - Count occurrences
  • countReset() - Reset counters
  • assert() - Assertion testing
  • clear() - Clear console

Why use this package?

  • Clean Production Builds: No need to manually remove or comment out debug statements
  • Performance: Zero overhead in production - all methods become no-ops
  • Type Safety: Full TypeScript support with proper type definitions
  • Simplicity: One import, works everywhere
  • Familiar API: If you know console, you already know developer