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

apify-logger

v1.0.1

Published

Automatic logging system for Apify with sensitive data masking and console capture

Readme

Apify Logger 🔒

npm version License: MIT

A sophisticated, automatic logging system designed specifically for Apify Actors. It provides automatic sensitive data masking, console interception, and flexible log management to keep your Actor logs clean, secure, and useful.

🚀 Features

  • 🔒 Automatic Masking: Automatically detects and masks API keys, tokens, passwords, emails, and credit card numbers.
  • 🎯 Console Interception: Seamlessly intercepts console.log, console.info, console.warn, and console.error.
  • 📊 Log Buffering: Stores logs in memory with a configurable buffer size.
  • 📤 Multi-format Export: Export your logs as JSON, CSV, or plain text.
  • 🛠️ Highly Customizable: Add your own masking patterns and configure log levels.
  • 🧹 Clean Output: Formats logs with timestamps and levels for better readability.

📋 Table of Contents


📦 Installation

Install via npm:

npm install apify-logger

⚡ Quick Start

The simplest way to use the logger is to initialize it at the start of your Actor. It will automatically start intercepting console calls.

import ApifySmartLogger from "apify-logger";
// or for CommonJS
// const ApifySmartLogger = require("apify-logger");

// Initialize (auto-captures console logs by default)
const logger = new ApifySmartLogger();

// Use standard console methods - they are now automatically masked!
console.log("My API Key is: sk_test_51Mzabc123456789");
// Output: [2023-10-27T10:00:00.000Z] [LOG] My API Key is: api_key=***MASKED***

console.log("Visit https://example.com for more info");
// Output: [2023-10-27T10:00:00.000Z] [LOG] Visit ***URL_MASKED*** for more info

// You can also use the logger instance directly
logger.info("Actor started successfully");
logger.error("Something went wrong", { errorCode: 500 });

⚙️ Configuration

You can customize the logger behavior by passing an options object to the constructor:

const logger = new ApifySmartLogger({
  enabled: true, // Set to false to disable all logging (Default: true)
  autoCapture: true, // Automatically intercept console methods (Default: true)
  logLevel: "info", // Minimum level to log: 'debug', 'info', 'warn', 'error' (Default: 'info')
  maxBufferSize: 1000, // Maximum number of log entries to keep in memory (Default: 1000)
  customPatterns: [
    // Add your own regex patterns for masking
    {
      pattern: /internal-id-\d+/gi,
      mask: "ID-***MASKED***",
    },
  ],
});

📖 API Reference

Logging Methods

The logger provides methods for different log levels. If autoCapture is enabled, these will also be used by the global console object.

  • logger.debug(...args)
  • logger.info(...args)
  • logger.warn(...args)
  • logger.error(...args)

Log Retrieval

logger.getLogs(filter)

Returns an array of log entries from the buffer.

Parameters:

  • filter (Object):
    • level (String): Filter by level ('debug', 'info', etc.)
    • since (Date|String|Number): Filter logs after this timestamp.
    • limit (Number): Limit the number of returned logs.
const errors = logger.getLogs({ level: "error", limit: 10 });

logger.clearLogs()

Clears the internal log buffer.

Exporting Logs

logger.exportLogs(format)

Returns the buffered logs as a string in the specified format.

Parameters:

  • format (String): 'json', 'csv', or 'text' (Default: 'json')
const csvData = logger.exportLogs("csv");

Utility Methods

logger.setLogLevel(level)

Dynamically change the minimum log level.

logger.addCustomPattern(pattern, mask)

Add a new masking pattern at runtime.

logger.restoreConsole()

Stops intercepting console methods and restores the original console behavior.

ApifySmartLogger.createInstance(options)

Static factory method to create a new instance.


🛡️ Default Masking Patterns

By default, the logger masks the following sensitive information:

  • API Keys: api_key, apiKey, x-api-key, graphql_key
  • Tokens: token, bearer tokens
  • Credentials: password, secret
  • Headers: authorization
  • URLs: All HTTP/HTTPS URLs and other protocol-based URLs
  • IP Addresses: IPv4 addresses
  • Local Sites: localhost, 127.0.0.1 (with or without ports)
  • Domain Names: Common TLDs (.com, .net, .org, .io, .actor, etc.)
  • Git URLs: SSH-style git URLs (git@...)
  • Personal Info: Email addresses
  • Financial: Credit card numbers (13-19 digits)

📄 License

This project is licensed under the MIT License.


Created by Aashish Timsina