Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3283468
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:02:42+00:00 2026-05-17T20:02:42+00:00

I want to wrap every function call with some logging code. Something that would

  • 0

I want to wrap every function call with some logging code. Something that would produce output like:

func1(param1, param2)
func2(param1)
func3()
func4(param1, param2)

Ideally, I would like an API of the form:

function globalBefore(func);
function globalAfter(func);

I’ve googled quite a bit for this, but it seems like there’s only aspect-oriented solutions that require you to wrap the specific functions you want to log, or whatever. I want something that applies to every function in the global scope (except itself, obviously).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:02:43+00:00Added an answer on May 17, 2026 at 8:02 pm

    A simple approach would be something like this

    var functionPool = {} // create a variable to hold the original versions of the functions
    
    for( var func in window ) // scan all items in window scope
    {
      if (typeof(window[func]) === 'function') // if item is a function
      {
        functionPool[func] = window[func]; // store the original to our global pool
        (function(){ // create an closure to maintain function name
             var functionName = func;
             window[functionName] = function(){ // overwrite the function with our own version
             var args = [].splice.call(arguments,0); // convert arguments to array
             // do the logging before callling the method
             console.log('logging: ' + functionName + '('+args.join(',')+')');
             // call the original method but in the window scope, and return the results
             return functionPool[functionName].apply(window, args );
             // additional logging could take place here if we stored the return value ..
            }
          })();
      }
    }
    

    To undo you would need to run the

    for (func in functionPool)
      window[func] = functionPool[func];
    

    Notes
    This handles only global functions, but you can easily extend it to handle specific objects or methods etc..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a loop in wordpress to output posts. I want to wrap every
I want to write a module (framework specific), that would wrap and extend Facebook
I want to wrap around a list/vector in C++ like in Python. Basically I
I want to wrap some queries in a SharedDbConnectionScope and execute them under a
These 4 queries produce the desired result, however I want to wrap these queries
I want to display some div's in a wrap. The div have same class
I want to keep my templates tidy and nicely intented but would like to
Using Javascript, I want to take the content of a string and wrap every
I have a specific project where I need to wrap every code line at
Here's some working code: class A { public $Foo; public function GetFoo() { $this->Foo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.