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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:10:38+00:00 2026-06-07T09:10:38+00:00

Possible Duplicate: Intercept calls to console.log in Chrome Can I extend the console object

  • 0

Possible Duplicate:
Intercept calls to console.log in Chrome
Can I extend the console object (for rerouting the logging) in javascript?

When my JS app writes to the console.log, I want to capture that log message so that I can AJAX that log output to the server. How do I do that?

The code that writes to the log is from external services, which is why I can’t just ajax it directly.

  • 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-06-07T09:10:40+00:00Added an answer on June 7, 2026 at 9:10 am

    You can hijack JavaScript functions in the following manner:

    (function(){
        var oldLog = console.log;
        console.log = function (message) {
            // DO MESSAGE HERE.
            oldLog.apply(console, arguments);
        };
    })();
    
    1. Line 1 wraps your function in a closure so no other functions have direct access to oldLog (for maintainability reasons).
    2. Line 2 captures the original method.
    3. Line 3 creates a new function.
    4. Line 4 is where you send message to your server.
    5. Line 5 is invokes the original method as it would have been handled originally.

    apply is used so we can invoke it on console using the original arguments. Simply calling oldLog(message) would fail because log depends on its association with console.


    Update Per zzzzBov’s comment below, in IE9 console.log isn’t actually a function so oldLog.apply would fail. See console.log.apply not working in IE9 for more details.

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

Sidebar

Related Questions

Possible Duplicate: how can i validate a url in javascript using regular expression I
Possible Duplicate: How can I detect the browser with PHP or JavaScript? I need
Possible Duplicate: Can .NET intercept and change css files? I have configured IIS6 to
Possible Duplicate: Javascript Object.Watch for all browsers? I just read Mozilla's documentation for the
Possible Duplicate: What do parentheses surrounding a JavaScript object/function/class declaration mean? Recently discussing with
Possible Duplicate: Intercept method call in Objective-C How to log all methods used in
Possible Duplicate: how to disable javascript errors on “twebbrowser” ? I'm using the TWebBrowser
Possible Duplicate: Why does Android app run in small window on tablet emulator? i
Possible Duplicate: Supporting Open In… menu item in my app for iOS Mail And
Possible Duplicate: launch facebook app from other app Im a beginner with facebook api

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.