Apache error log always viewed

Source: Internet
Author: User
Tags apache error log

When doing the project, sometimes need to look at the Apache error log, and then need to be very cumbersome to open the directory below, look at the information, only when the wrong time I will open the file.

But recently I found that in the development of the time, I ignored a lot of errors, although not cause errors, but can not be a day to explode.

I am not happy every time I open that file, and then I have to manually refresh, too troublesome, so I made a web version, can always view the error log.

This gadget is simple, is simply to print the file content to the page, and in the new error when a title flashing tips.

When a new message is available, the label becomes

With three files, jquery does not explain, a script class library. Two PHP file encoding format I changed to ANSI format, because at the beginning of debugging, from the Error.txt read out of the Chinese will be garbled.

content.php

This file is used to read error.txt information.

$path = ' C:\Program Files (x86) \apache software foundation\apache2.2\logs\error.log ';//custom Path $STR = file_get_contents ( $path) $str = Str_replace ("\ r \ n", ' <p style= ' padding:3px 0;margin:0 ' ></p> ', $str); $str = Str_replace (' < Script> ', ' &lt;script&gt; ', $str); $str = Str_replace (' </script> ', ' &lt;/script&gt; ', $str); Echo ($STR);

1, as long as the path to its own absolute path can be, there is a change to the line changed to a P tag style, here can also be customized

2, do a bit of rough <script> filter, if not so filtered, return to the index.php page will execute the script code

index.php

This file is the page where the error message is displayed

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin-top:10px;border:none; "/>

<! Doctype html>

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin-top:10px;border:none; "/>

1, the format of the page is GBK

2, there are two or three div to save the read error message,

3, error is used to show, the following will do some tags to add

4. Error_bak is used to back up the original information obtained by Ajax

5. Error_data is to compare the data returned by Ajax with Error_bak backup data to determine if the log has changed

6. The script logic is as follows

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin-top:10px;border:none; "/>

id    of <script type= "text/javascript" >    var move;//timer function  var titlename = document.title;//page title when initializing     var first =  true;//is the first time you read the error log      /**     *  @method   private     *  @name  _settitle     * @ description  Timer display new error message prompt      */    function _settitle ()  {        var title = document.title;         if (Title == titlename) {             document.title =  "with new error" ";         }else{            document.title  = titlename;         }        move = settimeout (' _ Settitle () ',     }    /**     * @ '; method private     *  @name  _filter     *   @description   filter out HTML tags      *  @param  str [string]  " String to be Filtered "     */    function _filter (str)  {         return str.replace (/<[^>]+>/g, "");     }     /**     *  @method  private      *  @name  _get     *  @description   getting error logs asynchronously       */    function _get ()  {         var old_bak = $ (' #error_bak '). html (); Because the new error will be marked red, here to make a wrong backup, the following judgments are used to do the backup          $.get (' content.php ',  {}, function (data)  {             $ (' #error_data '). HTML (data);             var current = $ (' #error_data '). html ();//Add to HTML code, and then read the code to do the comparison, because after adding to the HTML will be escaped, The data returned from the Ajax will be             if (_filter (current)  != _filter (Old_bak))  {//comparison with backup                  $ (' #error '). HTML (data);                 $ (' #error_bak '). HTML (data);                 if (!first)  {                      var red = data.replace (Old_bak,   ");                     $ (' #error '). html (old_bak +  ' <div style= "color:red" > ' +red+ ' </ Div> ')//New error marked red                      _settitle ();                 }            }             // console.log (_filter (data));             // console.log (_filter (old_bak));             first = false;         });     }    $ (document). Ready (function ()  {         //initialization Read error log         _get ();         //Timing Get error log         setinterval (function ()  {            _get ();         }, 4000)         //Click on the page to cancel the title timed display         $ (document). Click (function ()  {             document.title = titleName;             cleartimeout (move);         });     });</script>

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin-top:10px;border:none; "/>

1. Use jquery's get to read the error log

2, when there is a new error log, do a little hint

3, there is a new log, the page content will be refreshed

4. Add a color distinction to the new lines of error log

5. Bind an event to cancel the new error prompt

2014-09-22 Bug fixes:

1, the data obtained from the content.php in the time of making replace, and did not replace the success, when the returned data added to the HTML, HTML will do some coding, resulting in the substitution is unsuccessful.

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin-top:10px;border:none; "/>

Function _get ()  {       //.         $.get (' content.php ',  {}, function (data)  {             //...             if (_filter (current)  != _filter (Old_bak))  {//compared to backup                  //...                 if (!first)  {                      var red = $ (' #error '). html (). Replace (old_bak,  ");                     //...                 }            }             //.         });     }

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" Margin-top:10px;border:none; "/>

Just write a relatively rough version, there are a lot of problems, we can make changes according to their own situation.


Apache error log always viewed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.