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

logaway

v1.1.0

Published

A CLI tool to remove console.log statements from JavaScript and TypeScript files

Downloads

299

Readme

logaway

A CLI tool to remove console.log statements from JavaScript and TypeScript files.

Installation

Global Installation

| Package Manager | Command | | :-------------: | :------------------------ | | npm | npm install -g logaway | | yarn | yarn global add logaway | | pnpm | pnpm add -g logaway | | bun | bun add -g logaway |

Local Installation (as dev dependency)

| Package Manager | Command | | :-------------: | :------------------------------- | | npm | npm install --save-dev logaway | | yarn | yarn add --dev logaway | | pnpm | pnpm add -D logaway | | bun | bun add -d logaway |

Then add a script to your package.json:

{
  "scripts": {
    "logaway": "logaway"
  }
}

Configuration

logaway supports configuration through a config file, which can be specified in several formats:

Config File Formats

logaway will automatically search for configuration in the following files (in order of precedence):

  1. logaway.config.js - JavaScript module
  2. .logawayrc.json - JSON file
  3. .logawayrc.yaml - YAML file
  4. .logawayrc.yml - YAML file
  5. .logawayrc - JSON file
  6. logaway field in package.json

Initializing Configuration

You can create a default configuration file using the init command:

logaway init

This will create a .logawayrc.json file with the following default configuration:

{
  "targetDir": "./",
  "ignoredDirs": ["node_modules", "dist", "build"],
  "extensions": [".js", ".jsx", ".ts", ".tsx"],
  "methods": ["log", "debug"],
  "prettier": true
}

Note: targetDir can also be an array of directories to process multiple directories simultaneously:

{
  "targetDir": ["./src", "./lib", "./utils"],
  "ignoredDirs": ["node_modules", "dist", "build"],
  "extensions": [".js", ".jsx", ".ts", ".tsx"],
  "methods": ["log", "debug"],
  "prettier": true
}

Note: The init command will fail if any configuration file already exists in your project.

Config File Examples

logaway.config.js:

export default {
  targetDir: "./",
  ignoredDirs: ["node_modules", "dist"],
  extensions: [".js", ".jsx", ".ts", ".tsx"],
  methods: ["log", "debug"],
  prettier: true,
};

.logawayrc.json:

{
  "targetDir": "./",
  "ignoredDirs": ["node_modules", "dist"],
  "extensions": [".js", ".jsx", ".ts", ".tsx"],
  "methods": ["log", "debug"],
  "prettier": true
}

package.json:

{
  "name": "my-project",
  "logaway": {
    "targetDir": "./src",
    "ignoredDirs": ["node_modules", "dist"],
    "methods": ["log", "debug"]
  }
}

Configuration Precedence

Configuration values are applied in the following order (highest to lowest priority):

  1. Command-line arguments
  2. Config file values
  3. Default values

For example, if you specify --methods=log,error on the command line, it will override any methods setting in your config file.

Usage

Global Usage

logaway [options]

Local Usage (with npm scripts)

npm run logaway [options]

Note: When using npm scripts, you need to add -- before passing arguments to the underlying command.

For example:

npm run logaway --targetDir=./app --preview

Options

| Option | Short | Description | Default | | ---------------- | ------ | -------------------------------------------------- | --------------------- | | --targetDir | -t | Directory(s) to process | "./" | | --ignoredDirs | -d | Comma-separated list of directories to ignore | null | | --ignoredFiles | -f | Comma-separated list of files to ignore | null | | --extensions | -e | Comma-separated list of file extensions to process | ".js,.jsx,.ts,.tsx" | | --methods | -m | Comma-separated list of console methods to remove | "log" | | --prettier | | Format modified files with Prettier | false | | --preview | -p | Preview changes without modifying files | false | | --verbose | -v | Show detailed information for each file | false | | --reportFormat | --rf | Report file format (json,csv) | null | | --reportPath | --rp | Report file path | null | | --help | -h | Show help information | |

Examples

# Process the default ./ directory
logaway

# Specify a target directory and ignore some folders
logaway --targetDir=./app --ignoredDirs=node_modules,dist
logaway -t app -d node_modules,dist

# Process multiple directories
logaway --targetDir=./src --targetDir=./lib --targetDir=./utils
logaway -t src -t lib -t utils

# Remove console.log, console.info and console.warn statements
logaway --methods=log,info,warn
logaway -m log,info,warn

# Format modified files with Prettier
logaway --prettier

# Dry run to preview changes
logaway --preview
logaway -p

# Generate a report file
logaway --reportFormat=json --reportPath=./reports
logaway --rf json --rp reports

# Use with config file (no additional arguments needed)
logaway

# Override config file settings with CLI arguments
logaway --methods=error,warn

Multiple Target Directories

logaway supports processing multiple directories simultaneously. This is useful when you want to clean console statements from different parts of your project at once.

Command Line Usage

You can specify multiple target directories using the --targetDir flag multiple times:

# Process multiple directories
logaway --targetDir=./src --targetDir=./lib --targetDir=./utils
logaway -t src -t lib -t utils

# With additional options
logaway -t src -t components -t utils --methods=log,error --preview

Configuration File Usage

In your configuration file, you can specify targetDir as an array:

JSON Configuration:

{
  "targetDir": ["./src", "./components", "./utils"],
  "methods": ["log", "error", "warn"],
  "prettier": true
}

JavaScript Configuration:

export default {
  targetDir: ["./src", "./components", "./utils"],
  methods: ["log", "error", "warn"],
  prettier: true,
};

Features

  • Validation: All directories are validated before processing begins
  • Unified reporting: Statistics are combined across all processed directories
  • Relative paths: File paths in reports are relative to their respective target directories
  • Error handling: If any directory doesn't exist, the process will stop with a clear error message

Example Output

$ logaway -t src -t lib --verbose

Starting to process 2 directories...
Target directories: src, lib
Ignored directories: node_modules, dist, build
Console methods: log
File extensions: .js, .jsx, .ts, .tsx

=== Summary ===
Files checked: 45
Files modified: 12
Total console statements removed: 87

=== Files with most console statements ===
1. src/auth/login.js: 15 console statements
2. lib/utils/logger.js: 12 console statements
3. src/components/Header.jsx: 8 console statements

All console statements have been removed successfully! 🎉

Examples of Removed Logs

This tool will detect and remove various forms of console.log statements, including:

  1. Simple string log
console.log("User logged in successfully");
  1. Variable log
console.log(userId);
  1. String concatenation
console.log("User ID: " + userId);
  1. Template literals
console.log(`User ${userName} (ID: ${userId}) logged in at ${loginTime}`);
  1. Multiple arguments
console.log("Authentication:", status, "for user", userName);
  1. Object logging
console.log({ userId, userName, email, lastLogin });
  1. Array logging
console.log(userPermissions);
  1. Logging function results
console.log(calculateTotalPrice(items));
  1. Conditional logging with ternary
console.log(
  `Login ${isSuccessful ? "successful" : "failed"} for user ${userName}`
);
  1. JSON stringified object
console.log(JSON.stringify(userData, null, 2));
  1. Destructuring in log
console.log({ name, email, ...otherUserData });
  1. Multiline string log
console.log(`User profile:
  Name: ${userName}
  Email: ${email}
  Role: ${role}
  Last active: ${lastActive}`);
  1. Commented log
// console.log("Debugging user authentication");
  1. Logging with expression
console.log("Cart total: $" + (subtotal + tax).toFixed(2));
  1. Nested object logging
console.log("User settings:", user.preferences.notifications);
  1. Error context logging
console.log("Error in authentication process:", error.message);
  1. Array method result
console.log(users.filter((user) => user.isActive).map((user) => user.name));
  1. Conditional log with && operator
console.log(`#${isDebug ? "DEBUG" : "INFO"}`);
  1. Console log with spread operator
console.log("User data:", ...userData);
  1. Logging with ternary and complex expressions
console.log(
  `Payment ${
    payment.status === "completed" ? "succeeded" : "failed"
  }: ${formatCurrency(payment.amount)}`
);
  1. Optional chaining with nullish coalescing:
console.log(user?.profile?.settings ?? "No settings");
  1. Console.log with generator function results:
console.log(generator.next().value);
  1. Console.log with spread operator and nullish coalescing:
console.log("User data:", ...userData, "Default:", defaultValue ?? "No value");
  1. Console.log with computed property names in objects:
console.log({ ["computed" + "Name"]: value });
  1. Console.log with new operator
console.log(new Date());
  1. Styled console.log with CSS directives
console.log("%cStyled log message", "color: blue; font-weight: bold");
  1. Async function results
console.log(async () => await fetchUserData(userId));
  1. Console.log with multiple conditionals
console.log(
  importantData || "No data available",
  attempts > 3 ? "Retry limit exceeded" : "Retrying..."
);
  1. Console.log with immediately invoked function expression (IIFE)
console.log(
  (function () {
    return calculateComplexValue(a, b);
  })()
);
  1. Console.log with tagged template literals
console.log(debug`User authentication ${status} with token ${token}`);
  1. Console.log with complex conditional chains
console.log(
  user && user.isAdmin
    ? "Admin access"
    : user && user.isEditor
    ? "Editor access"
    : "Regular access"
);
  1. console.log() with array destructuring assignment
console.log(([a, b] = [1, 2]));
  1. console.log() with nested template literals
console.log(`User: ${`${firstName} ${lastName}`}`);
  1. console.log() with no arguments
console.log();
  1. console.log() with a regular expression
console.log(/^user-\d+$/);
  1. console.log() with chained method calls
console.log(
  users
    .find((u) => u.id === 5)
    .getPurchases()
    .filter((p) => p.active)
);
  1. console.log() with unicode escape sequences
console.log("\u0048\u0065\u006c\u006c\u006f");

License

MIT

MIT License

Copyright (c) 2021-present Tanner Linsley

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.