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 970599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:49:54+00:00 2026-05-16T02:49:54+00:00

I am trying to write a logger object which logs messages to screen. here

  • 0

I am trying to write a logger object which logs messages to screen. here is my code.
http://github.com/huseyinyilmaz/javascript-logger
in every function that needs to log something, I am writing loggerstart and loggerEnd functions at start and end of my functions. But I want to run thos codes automaticalls for every function. is there a way to modify Function prototype so every function call can run automatically.
(I am not using any javascript framework.)

  • 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-16T02:49:55+00:00Added an answer on May 16, 2026 at 2:49 am

    EDIT: Rewritten the function to make it more modular

    Well, this is a creepy way to do it, but I use this way sometimes when I need overriding some functions. It works well, allows any kind of customization and easy to understand (still creepy).

    However, you will need to have all your functions stored in some kind of global object. See the example for details.

    function dynamic_call_params(func, fp) {
        return func(fp[0],fp[1],fp[2],fp[3],fp[4],fp[5],fp[6],fp[7],fp[8],fp[9],fp[10],fp[11],fp[12],fp[13],fp[14],fp[15],fp[16],fp[17],fp[18],fp[19]);
    }
    
    function attachWrapperToFunc(object, funcName, wrapperFunction) {
        object["_original_function_"+funcName] = object[funcName];
        object[funcName] = function() {
            return wrapperFunction(object, object["_original_function_"+funcName], funcName, arguments);
        }
    }
    
    function attachWrapperToObject(object, wrapperFunction) {
        for (varname in object) {
            if (typeof(object[varname]) == "function") {
                attachWrapperToFunc(object, varname, wrapperFunction);
            }
        }
    }
    

    And some usage example:

    var myProgram = new Object();
    myProgram.function_one = function(a,b,c,d) {
        alert(a+b+c+d);
    }
    myProgram.function_two = function(a,b) {
        alert(a*b);
    }
    
    myProgram.function_three = function(a) {
        alert(a);
    }
    
    function loggerWrapperFunction(functionObject, origFunction, origFunctionName, origParams) {
        alert("start: "+origFunctionName);
        var result = dynamic_call_params(origFunction, origParams);
        alert("end: "+origFunctionName);
        return result;
    }
    
    attachWrapperToObject(myProgram,loggerWrapperFunction);
    myProgram.function_one(1,2,3,4);
    myProgram.function_two(2,3);
    myProgram.function_three(5);
    

    Output will be:
    start,10,end,start,6,end,start,5,end

    So generally it allows you to wrap each function in some object automatically with a custom written wrapper function.

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

Sidebar

Related Questions

I'm trying to write a blog post which includes a code segment inside a
I am trying to write a decorator to do logging: def logger(myFunc): def new(*args,
I'm trying write a query to find records which don't have a matching record
I am trying to write a unit test for an action method which calls
I'm using the below log4net configuration. I'm trying to write performance logs to a
I'm trying to write a script which basically takes an array of lots of
I'm trying to write a Cucumber scenario that requires me to have a logged
I'm trying to write a script that informs the user when someone has logged
Trying to write a PowerShell cmdlet that will mute the sound at start, unless
I'm trying to write a regex function that will identify and replace a single

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.