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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:39:09+00:00 2026-06-13T15:39:09+00:00

I’m developing a php application and I have created logging feature for it. I

  • 0

I’m developing a php application and I have created logging feature for it. I mean everytime that something wents wrong I write it in my log file so if an user reports a bug, I can use my log file to trace that bug.

The problem is that if I upload my project on production server, I have to disable PHP’s default error display; I just want to log php errors inside my own log file alongside of webserver’s ‘error.log’. Is there any way so I can do that?

  • 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-13T15:39:10+00:00Added an answer on June 13, 2026 at 3:39 pm

    For FEATURED USABLE EXCEPTIONS (i’m calling full featured usable exceptions, (without stack trace)):

    Set if you are developer to:

       define('EXCEPTION_HANDLER_ACTIVE', true);
    

    In production this will also should be to true, but modified of code to not show errors on end users. (use: error_reporting(0); ini_set('display_errors', false) on top of page));

    First set main function for handling exceptions:

    set_error_handler("_handler_exception");
    

    Function for calling handler of exception:

    function _handler_exception($err_severity, $err_msg, $err_filepath, $err_line)
        {
            if (EXCEPTION_HANDLER_ACTIVE == 1)
            {
                $eh = new exceptionhandler;
    
                $eh->exception_active = true;
                $eh->set_exception_handler_log($err_severity, $err_msg, $err_filepath, $err_line);
            }
            else
            {
                $eh = new exceptionhandler;
    
                $eh->exception_active = false;
                $eh->set_exception_handler_log($err_severity, $err_msg, $err_filepath, $err_line);
            }
        }
    

    Class exceptionhandler:

    class exceptionhandler
    {
        public $exception_active = true;
    
       public function set_exception_handler_log($err_severity, $err_msg, $err_filepath, $err_line)
        {        
        $ret_err_severity = NULL;
        $ret_err_no = NULL;
        $ret_info = NULL;
        $filenameerr = NULL;
        $dbout = NULL;
    
        switch ($err_severity)
        {
            case E_ERROR:
                $ret_err_severity = "E_ERROR"." [ ".$err_severity." ]";
                $ret_err_no = "1";
                $ret_info = "Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted.";
                $ret_err_msg = $err_msg;
                break;
    
            case E_STRICT:
                $ret_err_severity = "E_STRICT"." [ ".$err_severity." ]";
                $ret_err_no = "2048";
                $ret_info = "Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code. ";
                $ret_err_msg = $err_msg;
                break;
            default:
                $ret_err_severity = "CODE"." [ ".$err_severity." ]";
                $ret_err_no = $err_severity;
                $ret_info = "Other error";
                $ret_err_msg = $err_msg;
                break;
        }
    
        $ef = explode("/", $err_filepath);
        $ec = (count($ef) - 1);
        $filenameerr = $ef[$ec];
    
        $backtrace = debug_backtrace();
    
        if (!isset($doc_root)) {
            $doc_root = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']);
        }
    
        $debug_backtrace_parse = print_r(debug_backtrace(), true);
        $debug_backtrace2 = str_replace($err_msg, '<b>'.$err_msg.'</b>', $debug_backtrace_parse);
        $debug_backtrace = str_replace($err_filepath, '<b>'.$err_filepath.'</b>', $debug_backtrace2);
    
        $line = (isset($backtrace[1]['line'])) ? htmlspecialchars($backtrace[1]['line']) : '';
        $file = (isset($backtrace[1]['file'])) ? htmlspecialchars(str_replace(array('\\', $doc_root), array('/', ''), $backtrace[1]['file'])) : '';
        $class = !empty($backtrace[2]['class']) ? htmlspecialchars($backtrace[2]['class']) . '::' : '';
        $function = !empty($backtrace[2]['function']) ? htmlspecialchars($backtrace[2]['function']) . '() ' : '';
        $dbout = "<pre>$class$function =&gt;$file #$line</b><pre>";
    
        $memory = memory_get_usage()/1024/1024;
    
        if ($this->exception_active == true)
        {
            $source_highlight = $this->source_highlight($file, $backtrace);
    
            ob_start();
            include_once(exception.tpl);
            $buffer = ob_get_contents();
            ob_end_clean();
            echo $buffer;
            exit(-1);
        }
        }
    

    Exception.tpl

    <html>
        <head>
        <title><?php echo $ret_err_severity; ?> | <?php echo $filenameerr; ?></title>
        <style type="text/css">
            div#errorhandlerexception
            {
                border: 1px solid #ff0000;
                background-color: #ff9999;
                width: 96%;
                padding: 10px;
                color: #000;
                font-family: sans-serif;
                font-size: 10px;
                margin: 0 auto;
            }
            div#errorhandlerexception h2
            {
                border-bottom: 1px solid #fff;
                color: #ffffff;
            }
            div#errorhandlerexception td
            {
                background-color: #ffcccc;
                width: 100%;
                padding: 3px;
            }
            div#errorhandlerexception .main
            {
                width: 100px;
                height: 30px;
            }
            div#errorhandlerexception
            {
                margin-bottom: 40px;
            }
            .linenum
            {
                text-align:right;
                background:#FDECE1;
                border:1px solid #cc6666;
                padding:0px 1px 0px 9px;
                float:left;
                width:25px;
                margin:3px 0px 30px 0px;
                font-family: Courier New, Courier;
                font-size: 11px;
            }
            .code
            {
                font-family:Courier New, Courier;
                font-size: 11px;
                float: left;
                width: 100%;
            }
            .linetext
            {
                width:95%;
                text-align:left;
                background: #fff;
                border: 1px solid #cc6666;
                border-left:0px;
                padding:0px 1px 0px 8px;
                font-family: Courier New, Courier;
                float:left;
                margin:3px 0px 30px 0px;
                font-size: 11px;
            }
            br.clear
            {
                font-family:Courier New, Courier;
                clear:both;
                font-size: 11px;
            }
            #exception_selected_block
            {
                background-color: #ffff00;
            }
            div.exception_filename
            {
                border-left: 19px solid #AA7777;
                border-top: 3px solid #AA7777;
                color: #000000;
                float: left;
                font-weight: bold;
                padding: 6px;
                width: 98%;
            }
        </style>
        </head>
    
    <body>
    <div id="errorhandlerexception"><?php #echo $msg; ?>
    <h2>EXCEPTION ERROR HANDLER</h2>
    <table>
        <tr><td class="main">Status:</td><td><?php echo $ret_err_severity; echo " #".$err_severity; ?></td></tr>
        <tr><td class="main">Debug stack:</td><td><?php echo $dbout; ?></td></tr>
        <tr><td class="main">Code:</td><td><?php echo $ret_err_no; ?></td></tr>
        <tr><td class="main">Message:</td><td><?php echo $ret_err_msg; ?></td></tr>
        <tr><td class="main">Info:</td><td><?php echo $ret_info; ?></td></tr>
        <tr><td class="main">File:</td><td><?php echo $filenameerr; ?><br><?php echo $err_filepath; ?></td></tr>
        <tr><td class="main">Line:</td><td><?php echo $err_line; ?></td></tr>
        <tr><td class="main" colspan="2"><?php echo $source_highlight; ?></td></tr>
        <tr><td class="main">Debug backtrace:</td><td><pre><?php echo $debug_backtrace; ?></pre></td></tr>
    </table>
    </div>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.