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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@movibe/logger

v1.3.1

Published

A flexible and type-safe logging system for JavaScript/TypeScript applications

Readme

@movibe/logger

Tests & Coverage codecov Coverage Statements Coverage Functions Coverage Lines

A TypeScript-based universal logging solution that provides consistent logging across different platforms and environments.

Features

  • 🌟 Universal Compatibility - Works across Node.js, browsers, and other JavaScript runtimes
  • 🔒 Type Safety - Built with TypeScript for robust type checking
  • 📦 Multiple Transports - Support for console, file, and custom transport layers
  • 🎯 Configurable Levels - Flexible log level configuration
  • 🚀 Performance Optimized - Minimal overhead for production environments
  • 🔍 Context Support - Rich contextual logging capabilities
  • 📊 Structured Logging - JSON-based log format for better parsing

Table of Contents

Installation

npm install @movibe/logger
# or
yarn add @movibe/logger
# or
bun add @movibe/logger

Type Definitions

Define your custom types for type-safe logging:

// Log tags for different types of logs
type CustomLogTags = "custom_start" | "custom_end";

// Network tags for API and GraphQL operations
type CustomNetworkTags =
  | "GraphqlQuery_error_graphql"
  | "RestApi_error"
  | "api_call"
  | "websocket";

// User properties interface
interface CustomUser {
  id: string;
  role: string;
  email?: string;
  name?: string;
  phone?: string;
  status?: string;
}

// E-commerce checkout interface
interface CustomCheckout {
  currency?: string;
  value?: number;
  customField: string;
}

// Purchase information interface
interface CustomPurchase {
  type: "credit_card";
  customStatus: string;
  affiliation?: string;
  coupon?: string;
  currency?: string;
}

// Custom events with their respective payloads
type CustomEvent = {
  "app-open": Record<string, never>;
  "user-login": { method: string };
  "user-register": { method: string };
  "add-to-cart": { product_id: string; quantity: number };
  "remove-from-cart": { product_id: string; quantity: number };
};

Basic Usage

Creating a Custom Logger

Primeiro, crie sua classe customizada implementando a interface LoggerStrategyType:

import { LoggerStrategyType } from "@movibe/logger";

const TAG = "DEBUG";

// Define your custom types
type CustomLogTags = "custom_start" | "custom_end";
type CustomNetworkTags =
  | "GraphqlQuery_error_graphql"
  | "RestApi_error"
  | "api_call"
  | "websocket";
interface CustomUser {
  id: string;
  role: string;
  email?: string;
  name?: string;
  phone?: string;
  status?: string;
}
interface CustomCheckout {
  currency?: string;
  value?: number;
  customField: string;
}
interface CustomPurchase {
  type: "credit_card";
  customStatus: string;
  affiliation?: string;
  coupon?: string;
  currency?: string;
}

type CustomEvent = {
  "app-open": Record<string, never>;
  "user-login": { method: string };
  "user-register": { method: string };
  "add-to-cart": { product_id: string; quantity: number };
  "remove-from-cart": { product_id: string; quantity: number };
};

// Implement your custom logger
export class DebugLogger
  implements
    LoggerStrategyType<
      CustomLogTags,
      CustomNetworkTags,
      CustomUser,
      CustomCheckout,
      CustomPurchase,
      CustomEvent
    >
{
  init(): void {
    console.log(`${TAG}.init`);
  }

  info(feature: string, name: string, properties?: any): void {
    console.log(`${TAG}.info: `, feature, name, properties);
  }

  error(
    feature: string,
    name: string,
    critical = false,
    error: Error,
    extra: Record<string, unknown> = {}
  ): void {
    console.error(`${TAG}.error: `, { critical, error, extra, feature, name });
  }

  event(name: string, properties?: Record<string, any>): void {
    if (properties) {
      console.log(`${TAG}.event: `, name, properties);
    } else {
      console.log(`${TAG}.event: `, name);
    }
  }

  network(name: CustomNetworkTags, properties?: Record<string, any>): void {
    if (properties) {
      console.log(
        `${TAG}.network: ${properties.operationName} | `,
        name,
        properties
      );
    } else {
      console.log(`${TAG}.network:`, name);
    }
  }

  logScreen(screenName: string, properties?: Record<string, any>): void {
    console.log(`${TAG}.logScreen: `, { screenName, ...properties });
  }

  setUser(user: CustomUser): void {
    const userProperties = {
      email: user.email ?? "",
      id: user.id,
      name: user.name ?? "",
      phone: user.phone,
      status: user.status,
    };

    console.log(`${TAG}.setUser: `, userProperties);
    this.setUserId(user.id);
  }

  setUserId(userId: string): void {
    console.log(`${TAG}.setUserId: `, userId);
  }

  setUserProperty(name: string, value: any): void {
    console.log(`${TAG}.setUserProperty: `, name, value);
  }

  setUserProperties(properties: CustomUser): void {
    console.log(`${TAG}.setUserProperties: `, properties);
  }

  logBeginCheckout(checkoutId: string, properties: CustomCheckout): void {
    console.log(`${TAG}.logBeginCheckout: `, checkoutId, properties);
  }

  logPaymentSuccess(checkoutId: string, properties: CustomPurchase): void {
    console.log(`${TAG}.logPaymentSuccess: `, checkoutId, properties);
  }

  reset(): void {
    console.log(`${TAG}.reset`);
  }

  flush(): void {
    console.log(`${TAG}.flush`);
  }

  getId(): string {
    return "DebugLogger";
  }
}

Using the Custom Logger

Depois de criar sua classe customizada, você pode usá-la em qualquer parte da aplicação:

import { LoggerStrategy } from "@movibe/logger";
import { DebugLogger } from "./debug-logger";

// Initialize with custom logger
const logger = new LoggerStrategy<
  CustomLogTags,
  CustomNetworkTags,
  CustomUser,
  CustomCheckout,
  CustomPurchase,
  CustomEvent
>([
  {
    class: new DebugLogger(),
    enabled: true,
  },
]);

// Initialize logger
logger.init();

// Log events with type safety
logger.event("app-open");

// User tracking with custom fields
logger.setUser({
  id: "123",
  role: "user",
  name: "John Doe",
  email: "[email protected]",
  phone: "+1234567890",
  status: "active",
});

// Screen tracking with custom properties
logger.logScreen("HomeScreen", {
  referrer: "DeepLink",
  customData: "test",
});

// Error tracking with context
try {
  throw new Error("Test error");
} catch (error) {
  logger.error("Authentication", "login-failed", true, error as Error, {
    userId: "123",
  });
}

// E-commerce tracking with custom fields
logger.logBeginCheckout("checkout-123", {
  currency: "USD",
  value: 99.99,
  customField: "test-checkout",
});

logger.logPaymentSuccess("checkout-123", {
  type: "credit_card",
  customStatus: "completed",
  currency: "USD",
  affiliation: "web-store",
  coupon: "DISCOUNT10",
});

// Reset and flush
logger.reset();
logger.flush();

Advanced Features

User Tracking

Track user information and properties:

// Set complete user object
logger.setUser({
  id: "123",
  role: "user",
  name: "John Doe",
  email: "[email protected]",
});

// Set individual user property
logger.setUserProperty("plan", "premium");

// Set user ID only
logger.setUserId("123");

Screen Tracking

Track screen views and navigation:

// Basic screen view
logger.logScreen("HomeScreen");

// Screen view with context
logger.logScreen("ProductScreen", {
  referrer: "HomeScreen",
  productId: "123",
});

Error Handling

Comprehensive error tracking:

try {
  throw new Error("API Request Failed");
} catch (error) {
  logger.error(
    "API", // Feature/component
    "request-failed", // Error type
    true, // Is critical error
    error as Error, // Error object
    {
      // Additional context
      endpoint: "/users",
      method: "GET",
      statusCode: 500,
    }
  );
}

E-commerce Tracking

Track e-commerce events and transactions:

// Begin checkout process
logger.logBeginCheckout("checkout-123", {
  currency: "USD",
  value: 99.99,
  customField: "premium-plan",
});

// Track successful payment
logger.logPaymentSuccess("checkout-123", {
  type: "credit_card",
  customStatus: "completed",
  currency: "USD",
  affiliation: "web-store",
});

Custom Events

Track custom events with type safety:

// Track login event
logger.event("user-login", {
  method: "email",
});

// Track cart action
logger.event("add-to-cart", {
  product_id: "prod_123",
  quantity: 1,
});

API Reference

Core Methods

  • init() - Initialize the logger
  • event(name, properties?) - Log custom events
  • error(feature, name, critical, error, extra?) - Log errors
  • logScreen(name, properties?) - Track screen views
  • setUser(user) - Set user information
  • reset() - Reset all user data
  • flush() - Flush pending logs

User Methods

  • setUserId(id) - Set user ID
  • setUserProperty(name, value) - Set single user property
  • setUserProperties(properties) - Set multiple user properties

E-commerce Methods

  • logBeginCheckout(checkoutId, properties) - Track checkout initiation
  • logPaymentSuccess(checkoutId, properties) - Track successful payments

For more detailed documentation, please visit our docs directory.

Contributing

Contributions are welcome! Please read our Contributing Guide for details.

License

This project is licensed under the MIT License - see the LICENSE file for details.