Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send log errors to a file

I developed a website for my graduation however it still only one thing I have do. What I want is when the script is installed on a website I want to send the name of the website who has installed my script, also whenever there is an error I want to send it to my website so for example:

This website installed my script

www.security-dz.com/myscript

I want to see the path + website in an other file in other website. For example:

www.getlog.com/mylogs.php

The purpose of this is keep my customers update and give them support and see the errors that happen so I can fix them in next updates.

like image 247
user3395024 Avatar asked Mar 29 '14 11:03

user3395024


People also ask

How can we log error messages to a file?

Approach 1: The error_log() function can be used to send error messages to a given file. First argument to the function is the error message to be sent. Second argument tells where to send/log the error message. In this case, second argument is set to 3, used to redirect error message to a file.

How do you log errors into a file in Python?

Logging an exception in python with an error can be done in the logging. exception() method. This function logs a message with level ERROR on this logger. The arguments are interpreted as for debug().

What is an error log file?

An error log is a file that contains detailed records of error conditions a computer software encounters when it's running.

How do I find the error log file?

The name and the location of the log is set by the ErrorLog command and the default apache access log file locations are: RHEL / Red Hat / CentOS / Fedora Linux Apache access log file location – /var/log/httpd/error_log. Debian / Ubuntu Linux Apache access log file location – /var/log/apache2/error. log.


1 Answers

You might want to take a closer look at the JQuery docs for ajax requests, so you can use a secure http connection for logging. This javascript code basically describes a function that sends the errors in text-format to your server-side script. This script can in turn write the error description to a file on the server. I'd recommend using a DB instead; That way you can easily write a web-client that displays all reported errors (and filters and the other good stuff).

You can extract the origin url from the referer [sic] field in the ajax http get-request on the server.

(function () { // function operator, in case console doesn't exist
    !console ?
        (console = {}) : console;
    !console.log ?
        (console.log = function () { }) : console.log;
    !console.info ?
        (console.info = console.log) : console.info;
    !console.error ?
        (console.error = console.log) : console.error;
}());
// Uses JQuery
function reportError (errDesc) {
    var path = "www.getlog.com/mylogs.php";
    $.ajax({
        url: path,
        type: "GET",
        async: true,
        cache: false,
        contentType: "application/x-www-form-urlencoded; charset=UTF-8",
        crossDomain: true,
        data: errDesc,
        dataType: "jsonp",
        error: function (req, type, errObj) {
            console.error("Reporting error failed: " + type + "\nAt url: " + path + "\n" + errObj);
        // In case you need to debug the error reporting function
        },
        succes: function (res) {
            console.info("Reported error to server:\nRequest:" + errDesc + "\nResponse: " + res);
        // extra error logging facility on client-side, invisible to most users
        },
        global: false // prevent triggering global ajax event handlers
    });
    return errDesc; // in case you want to reuse the errDesc
}

Code has been validated with jshint. Please let me know if there are still issues, because I didn't take the time to completely replicate your setup (setting up 2 different domains etc.)

Addendum: Some useful reading if you're having issues with cross-domain messaging, JSON is not a subset of javascript, Cross-origin resource sharing, JSONP.

like image 142
dot slash hack Avatar answered Sep 28 '22 01:09

dot slash hack