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

dtducas-smart-log

v1.0.0

Published

A smart logging package with environment-aware log levels for Node.js applications

Readme

dtducas-smart-log

A smart logging package with environment-aware log levels for Node.js applications.

Features

  • Environment-aware logging (Development vs Production)
  • Multiple log levels: info, warn, error, debug
  • Automatic timestamp formatting
  • TypeScript support with full type definitions
  • Zero dependencies
  • Easy configuration
  • Singleton pattern with factory function support

Installation

npm install dtducas-smart-log

Quick Start

import smartLog from "dtducas-smart-log";

// Basic usage - replaces console.log
smartLog.info("Application started");
smartLog.warn("This is a warning");
smartLog.error("An error occurred");
smartLog.debug("Debug information");

Environment Behavior

Development Environment (NODE_ENV=development)

All log levels are enabled:

  • smartLog.info() - Logged
  • smartLog.warn() - Logged
  • smartLog.error() - Logged
  • smartLog.debug() - Logged

Production Environment (NODE_ENV=production)

Only error logs are enabled:

  • smartLog.info() - Not logged
  • smartLog.warn() - Not logged
  • smartLog.error() - Logged
  • smartLog.debug() - Not logged

Log Format

All logs are formatted with timestamp and log level:

[2025-11-02T10:30:45.123Z] [INFO] Your log message here
[2025-11-02T10:30:45.456Z] [ERROR] Error message here

API Documentation

Default Import (Singleton)

import smartLog from "dtducas-smart-log";

smartLog.info("message", optionalArgs);
smartLog.warn("message", optionalArgs);
smartLog.error("message", optionalArgs);
smartLog.debug("message", optionalArgs);

Methods

info(message: string, ...args: any[]): void

Log informational messages. Only works in development environment.

smartLog.info("User logged in", { userId: 123 });

warn(message: string, ...args: any[]): void

Log warning messages. Only works in development environment.

smartLog.warn("API rate limit approaching", { remaining: 10 });

error(message: string, ...args: any[]): void

Log error messages. Works in both development and production environments.

smartLog.error("Database connection failed", error);

debug(message: string, ...args: any[]): void

Log debug messages. Only works in development environment.

smartLog.debug("Processing request", { data: payload });

Configuration

configure(config: SmartLogConfig): void

Update logger configuration at runtime.

smartLog.configure({
  environment: "production",
  disableAll: false,
});

Configuration Options

interface SmartLogConfig {
  environment?: "development" | "production" | string;
  disableAll?: boolean;
  timestampFormat?: "iso" | "locale" | "custom";
  customTimestampFormatter?: () => string;
}

Advanced Usage

Creating Custom Logger Instances

import { createLogger } from "dtducas-smart-log";

const customLogger = createLogger({
  environment: "production",
  disableAll: false,
});

customLogger.error("This will be logged");
customLogger.info("This will NOT be logged in production");

Disabling All Logs

import smartLog from "dtducas-smart-log";

// Disable all logs including errors
smartLog.configure({ disableAll: true });

smartLog.error("This will not be logged");
smartLog.info("This will not be logged");

Custom Timestamp Format

import smartLog from "dtducas-smart-log";

// Use locale format
smartLog.configure({ timestampFormat: "locale" });

// Use custom formatter
smartLog.configure({
  timestampFormat: "custom",
  customTimestampFormatter: () => {
    return new Date().toISOString().split("T")[0]; // YYYY-MM-DD
  },
});

TypeScript Support

Full TypeScript support with exported types:

import smartLog, {
  LogLevel,
  Environment,
  SmartLogConfig,
  SmartLogger,
} from "dtducas-smart-log";

const config: SmartLogConfig = {
  environment: Environment.PRODUCTION,
  disableAll: false,
};

smartLog.configure(config);

Examples

Express.js Application

import express from "express";
import smartLog from "dtducas-smart-log";

const app = express();

app.get("/", (req, res) => {
  smartLog.info("Homepage accessed");
  res.send("Hello World");
});

app.use((err, req, res, next) => {
  smartLog.error("Unhandled error", err);
  res.status(500).send("Internal Server Error");
});

app.listen(3000, () => {
  smartLog.info("Server started on port 3000");
});

Migration from console.log

Before:

console.log("User logged in:", userId);
console.error("Error:", error);
console.warn("Warning:", message);

After:

import smartLog from "dtducas-smart-log";

smartLog.info("User logged in:", userId);
smartLog.error("Error:", error);
smartLog.warn("Warning:", message);

Environment Variables

The package automatically detects the environment using process.env.NODE_ENV:

# Development (all logs enabled)
NODE_ENV=development node app.js

# Production (only errors enabled)
NODE_ENV=production node app.js

License

MIT

Author

Duong Tran Quang (DTDucas) Email: [email protected]

Repository

https://github.com/dtducas/dtducas-smart-log

Issues

Report issues at: https://github.com/dtducas/dtducas-smart-log/issues