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

@nxtwebmasters/nxt-smart-logger

v2.0.0

Published

A configurable smart logger for web apps that supports server and Google Tag Manager (GTM) logging with user/session context.

Readme

🚀 NXT Smart Logger | Advanced Console Interceptor

npm license downloads

A sophisticated console interceptor that supercharges your logging capabilities with server integration, GTM support, context/meta injection, custom log levels, and reusable structured logs for modern applications.

✨ Features

  • 🔀 Batched Log Transmission - Optimize network calls with configurable batching
  • 📊 GTM Integration - Seamless integration with Google Tag Manager
  • 👤 Contextual Logging - Attach user/session context automatically
  • ⚡ Multiple Destinations - Send logs to server, GTM, or both simultaneously
  • 🛡️ Error Resilient - Automatic retries for failed transmissions
  • 🔄 Framework Agnostic - Works with Angular, React, Vue, or vanilla JS
  • 🧹 Custom Logging - Define your own log types and structured events
  • ✨ Extendable API - Inject tags, meta, or override per log call

📦 Installation

npm install @nxtwebmasters/nxt-smart-logger
# or
yarn add @nxtwebmasters/nxt-smart-logger

🚀 Quick Start

import { ConsoleInterceptor } from "@nxtwebmasters/nxt-smart-logger";

const interceptor = new ConsoleInterceptor({
  batchSize: 10,
  flushInterval: 5000,
  contextProvider: () => ({
    userId: "USER123",
    sessionId: "SESSION456",
    appVersion: "1.0.0",
  }),
  serverLogger: async (logs) => {
    await fetch("https://yourserver.com/api/logs", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(logs),
    });
  },
});

const logger = interceptor.getLogger();
logger.info("User logged in");
logger.withTags(["auth"]).warn("Login attempt");
logger.withContext({ feature: "search" }).error("Search failed");
logger.withMeta({ region: "us-east-1" }).debug("Region-specific check");
logger.withAll({
  tags: ["api"],
  context: { feature: "checkout" },
  meta: { version: "2.1.0" },
}).error("API timeout");

interceptor.setContext({ userId: "ADMIN" });

⚙️ Configuration Options

| Option | Type | Default | Description | | ----------------- | ------------------------- | ------------ | ------------------------------------- | | batchSize | number | 5 | Max logs per batch | | flushInterval | number | 5000 | Max wait time (ms) between flushes | | contextProvider | () => object | () => ({}) | Provides dynamic context | | serverLogger | (logs) => Promise<void> | null | Function to POST logs to your backend | | customLevels | string[] | [] | Custom log levels (e.g. audit, track) | | filterLevels | string[] | all levels | Log levels to capture from console | | generateTraceId | () => string | uuidv4 | Custom trace ID generator |

🧩 Structured Log Format

{
  "level": "warn",
  "timestamp": "2025-05-31T12:34:56.789Z",
  "message": "Login failed {\"code\":401}",
  "tags": ["auth"],
  "context": {
    "userId": "USER123",
    "sessionId": "SESSION456",
    "feature": "login"
  },
  "meta": {
    "url": "https://nxtwebmasters.com/app",
    "userAgent": "Mozilla/5.0...",
    "traceId": "uuid-123",
    "sessionId": "SESSION456"
  },
  "data": {
    "code": 401
  }
}

🔌 Integration Examples — NXT Smart Logger

Here’s how to plug @nxtwebmasters/nxt-smart-logger into various environments:


⚛️ React Setup

// logger.ts
import { ConsoleInterceptor } from '@nxtwebmasters/nxt-smart-logger';

export const interceptor = new ConsoleInterceptor({
  contextProvider: () => ({
    userId: localStorage.getItem('userId'),
    sessionId: sessionStorage.getItem('sessId')
  }),
  serverLogger: async (logs) => {
    await fetch('/api/logs', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(logs),
    });
  }
});

export const logger = interceptor.getLogger();
// App.tsx
import { logger } from './logger';

function App() {
  useEffect(() => {
    logger.info('App mounted');
  }, []);
  return <h1>Welcome</h1>;
}

🧩 Vue Setup

// logger.ts
import { ConsoleInterceptor } from '@nxtwebmasters/nxt-smart-logger';

const interceptor = new ConsoleInterceptor({
  contextProvider: () => ({ userId: 'vue-user', role: 'admin' })
});

export const logger = interceptor.getLogger();
<script setup>
import { onMounted } from 'vue';
import { logger } from './logger';

onMounted(() => {
  logger.info('Vue component mounted');
});
</script>

🖥️ Node.js Setup (e.g., CLI apps or SSR)

import { ConsoleInterceptor } from '@nxtwebmasters/nxt-smart-logger';

const interceptor = new ConsoleInterceptor({
  enableGTM: false,
  enableServer: true,
  contextProvider: () => ({ env: 'node', pid: process.pid }),
  serverLogger: async (logs) => {
    console.log('Sending logs to API:', logs);
  }
});

const logger = interceptor.getLogger();
logger.info('CLI started');

Use the logger the same way across all frameworks:

logger.error('Something went wrong', { details: '...' })
logger.withTags(['startup']).info('App ready')

🌍 Works Anywhere

  • React (hooks, SSR, client)
  • Vue 2/3 (setup API or options API)
  • Vanilla JS / CDN
  • Node.js (CLI, workers, Express)

🌐 Browser Support

| Chrome | Edge | Firefox | Safari | | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ |

🤝 Contributing

We welcome contributions! Please see our Contribution Guidelines.

📜 License

MIT © NXT WebMasters