npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tgtone/logger

v1.0.3

Published

Debug logger utility for TGT One projects

Readme

@tgtone/logger

Debug logger utility for TGT One projects with environment-based control

Features

  • Environment-aware: Respects DEBUG and NODE_ENV variables
  • Browser & Node.js compatible: Works in both environments without polyfills
  • Multiple log levels: debug, info, warn, error
  • Namespace support: Organize logs by module/service
  • Production-safe: Auto-disables debug logs in production
  • Zero dependencies: Lightweight and fast
  • TypeScript: Fully typed
  • Vite-ready: No define config needed

Installation

npm install @tgtone/logger

Quick Start

Basic Usage

import { debug, info, warn, error } from '@tgtone/logger';

debug('🔍 Debug information');           // Only shows if DEBUG=true
info('ℹ️ Important information');        // Always shows
warn('⚠️ Warning message');              // Always shows
error('❌ Error occurred');              // Always shows

With Namespace

import { Logger } from '@tgtone/logger';

const logger = new Logger({ namespace: 'AuthService' });

logger.debug('Token validation started');
// 🔍 [AuthService] Token validation started

logger.info('User logged in:', user.email);
// ℹ️ [AuthService] User logged in: [email protected]

Child Loggers

const authLogger = new Logger({ namespace: 'Auth' });
const jwtLogger = authLogger.child('JWT');

jwtLogger.debug('Verifying token');
// 🔍 [Auth:JWT] Verifying token

Configuration

Browser Usage (React/Vue/Svelte with Vite)

IMPORTANT: In browser environments, you MUST pass debug explicitly:

import { Logger } from '@tgtone/logger';

// ✅ Correct - pass debug explicitly
const logger = new Logger({
  namespace: 'MyApp',
  debug: import.meta.env.DEV, // Vite variable for development mode
});

// ❌ Wrong - will default to false in browser
const logger = new Logger({ namespace: 'MyApp' });

Why? Browsers don't have access to process.env, so the logger detects the browser environment and requires explicit debug configuration.

Node.js Usage (Backend/NestJS/Express)

In Node.js, environment variables work automatically:

import { Logger } from '@tgtone/logger';

// ✅ Auto-detects DEBUG=true or NODE_ENV=development
const logger = new Logger({ namespace: 'AuthService' });

Environment Variables

  • DEBUG=true - Enable debug logs (Node.js only)
  • NODE_ENV=development - Auto-enable debug logs in development (Node.js only)

Programmatic Config

const logger = new Logger({
  debug: true,              // Force enable debug
  namespace: 'MyService',   // Add namespace prefix
  emojis: true,            // Enable emojis (default: true)
  minLevel: LogLevel.INFO, // Minimum log level to show
});

Log Levels

import { LogLevel } from '@tgtone/logger';

LogLevel.DEBUG  // 🔍 Debug information (only if DEBUG=true)
LogLevel.INFO   // ℹ️ General information
LogLevel.WARN   // ⚠️ Warnings
LogLevel.ERROR  // ❌ Errors

Use Cases

NestJS Services

import { Logger } from '@tgtone/logger';

export class AuthService {
  private logger = new Logger({ namespace: 'AuthService' });

  async login(email: string, password: string) {
    this.logger.debug('Login attempt:', email);
    
    // ... authentication logic
    
    this.logger.info('User logged in:', email);
  }
}

JWT Strategy

import { Logger } from '@tgtone/logger';

const logger = new Logger({ namespace: 'JWTStrategy' });

const jwtExtractor = (req: Request): string | null => {
  const token = ExtractJwt.fromAuthHeaderAsBearerToken()(req);
  
  if (token) {
    logger.debug('Token found, length:', token.length);
    logger.debug('Token expires:', decodedToken.exp);
  } else {
    logger.debug('No token in request');
  }
  
  return token;
};

API Module Initialization

import { Logger } from '@tgtone/logger';

const logger = new Logger({ namespace: 'JwtModule' });

JwtModule.registerAsync({
  useFactory: (configService: ConfigService) => {
    const secret = configService.get('JWT_SECRET');
    
    logger.debug('Initializing with secret length:', secret.length);
    logger.debug('Expiration:', configService.get('JWT_EXPIRATION'));
    
    return { secret, signOptions: { expiresIn: '7d' } };
  },
});

Migration from console.log

Before:

if (process.env.DEBUG === 'true') {
  console.log('🔍 Token found:', token);
  console.log('📋 Payload:', payload);
}

After:

import { debug } from '@tgtone/logger';

debug('🔍 Token found:', token);
debug('📋 Payload:', payload);

Production Behavior

In production (NODE_ENV=production and no DEBUG=true):

  • info(), warn(), error() → shown
  • debug() → suppressed

Development Behavior

In development (NODE_ENV=development or DEBUG=true):

  • ✅ All log levels shown

License

MIT

Author

TGT Technology