Add Console Logs to All Functions in TypeScript Files for Debugging

Enhance your TypeScript codebase with precise function call logging for better debugging.

Workflow Stage:
Use Case
Save Prompt
Prompt Saved

Overview

This prompt aims to guide developers in adding console log statements to TypeScript functions for better debugging. Programmers working with the provided codebase will benefit by gaining insights into function calls during runtime.

Prompt Overview

Purpose: This task aims to enhance debugging by logging function calls in TypeScript files.
Audience: The intended audience includes developers working with the TypeScript codebase who need better traceability.
Distinctive Feature: The solution focuses solely on adding console log statements without altering existing code logic.
Outcome: Developers will gain insights into function execution flow through precise log messages at runtime.

Quick Specs

Variables to Fill

  • [functionName] – Functionname
  • [filePath] – Filepath

Example Variables Block

  • [functionName]: Example Functionname
  • [filePath]: Example Filepath

The Prompt


You are given a codebase with multiple TypeScript (.ts) files located within the `src` folder. Your task is to add console log statements in all functions across these files. The goal is to ensure that whenever any function is called at runtime, a message is logged indicating which function is called and from which file path.
**Important:**
– Do NOT rewrite or modify any existing code logic.
– Only add console.log statements inside every function to trace calls.
– The console log message format must be exactly:
`Calling function [functionName] from path @[filePath]`
where `[functionName]` is the name of the function being executed, and `[filePath]` is the relative path to the file from the `src` folder.
**Guidelines:**
– Identify all functions, including:
– Named functions
– Arrow functions assigned to variables
– Class methods
– Any other executable functions
– Insert the log at the start of each function to log immediately when the function is called.
– Preserve original code formatting and functionality entirely.
– If a function is anonymous or lacks a name, use an appropriate identifier (e.g., `anonymousFunction`) for the debug message.
– Provide the exact lines or diff of the changes that add these console logs in all `.ts` files inside `src`.
# Output Format
For each `.ts` file in `src`, provide the following:
– The relative file path
– The code lines to add the console logs inside each function, showing only the inserted console.log lines with context to indicate placement.
Do not include whole file rewrites; only provide the minimal additions necessary for debugging as per instructions.
# Example
If a file `src/utils/helpers.ts` contains:
“`ts
function add(a: number, b: number) {
return a + b;
}

“`
You should add:
“`diff
+ console.log(“Calling function add from path @src/utils/helpers.ts”);
“`
at the start of the function body.
# Notes
– Ensure all function types are covered.
– The inserted console logs must exactly match the prescribed message format.
– Do not output or modify any other part of the code besides adding these logs.
This will help you trace function calls precisely at runtime without altering the logic.

Screenshot Examples

How to Use This Prompt

  1. [filePath]: relative path to the TypeScript file.
  2. [functionName]: name of the function being executed.
  3. [console.log]: statement to log function calls.
  4. [functionType]: type of function (named, arrow, method).
  5. [context]: placement of the console.log statement.
  6. [debugMessage]: format of the log message.
  7. [preserveCode]: maintain original code functionality.
  8. [insertedLines]: lines added for logging purposes.

Tips for Best Results

  • Add console logs: Insert console.log statements at the start of each function to log the function name and file path.
  • Identify functions: Locate all types of functions including named functions, arrow functions, and class methods.
  • Maintain formatting: Ensure that the original code formatting and functionality remain unchanged while adding logs.
  • Use identifiers for anonymous functions: For anonymous functions, use a descriptive identifier in the log message to indicate the function call.

FAQ

  • How to log function calls in TypeScript?
    Add console.log statements at the start of each function to trace calls.
  • What format should the log messages follow?
    Use: Calling function [functionName] from path @[filePath] for logging.
  • Should I modify existing code logic?
    No, only add console.log statements without changing any existing logic.
  • Where to place the console.log statements?
    Insert them at the beginning of each function in the TypeScript files.

Compliance and Best Practices

  • Best Practice: Review AI output for accuracy and relevance before use.
  • Privacy: Avoid sharing personal, financial, or confidential data in prompts.
  • Platform Policy: Your use of AI tools must comply with their terms and your local laws.

Revision History

  • Version 1.0 (February 2026): Initial release.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Used Prompts

Related articles

Enhance analytics page with Firebase data and UI improvements.

This guide provides clear steps to integrate data and refine the visual interface.

Improve C++MQL4 Code for Horizontal Line Management

Enhance your coding skills by optimizing financial charting applications.

Enhance Playwright Framework for Reliable User Sign-Ups

Improve automation reliability and maintainability for seamless user registration processes.

Improve financial management app code quality and robustness

This approach strengthens the application's reliability and long-term maintainability.