0

I am getting error "Call to a member function add() on a non-object" on Kohana::$log

There is not log in application/logs directory. The error I described is found on apache error_log. This is how it appears

[Fri Aug 17 17:07:09 2012] [error] [client MY.IPA.DDR.ESS] PHP Fatal error: Call to a member function add() on a non-object in /var/www/html/application/classes/kohana/exception.php on line 8

This is my error controller.

<?php
class Kohana_Exception extends Kohana_Kohana_Exception {
    public static function handler(Exception $e) {
        if (Kohana::DEVELOPMENT === Kohana::$environment) {
            parent::handler($e);
        } else {
            try {
                Kohana::$log->add(Log::ERROR, "own exception handler");
                Kohana::$log->add(Log::ERROR, parent::text($e));
                $attributes = array('action' => 500, 'message' => rawurlencode($e->getMessage()));
                if ($e instanceof HTTP_Exception) {
                    $attributes['action'] = $e->getCode();
                }
                // Error sub-request.
                echo Request::factory(Route::get('error')->uri($attributes))->execute()->send_headers()->body();
            }
            catch(Exception $e) {
                // Clean the output buffer if one exists
                ob_get_level() and ob_clean();
                // Display the exception text
                echo parent::text($e);
                // Exit with an error status
                exit(1);
            }
        }
    }
}

From the code it seems Kohana::$log is not initialized yet. But this code was working for long time. Now what made it not working?

I am using Kohana-3.2 with PHP 5.3.13 on Fedora 15

Shiplu Mokaddim
  • 56,364
  • 17
  • 141
  • 187

3 Answers3

1

I have solved this problem. If this problem occurs to any other kohana developer and he comes here from google here is the solution.

Run the following command from root shell. Remember if you reboot the server you'll have to run it again.

setsebool -P httpd_unified 1

Additional informaiton: How to trace it.

Check these location

  1. Apache error log
  2. Kohana logs (if you log for debugging) on application directory
  3. check the /var/log/messages.

If its SElinux issue you'll find log entry on /var/log/messages. This is what I got.

setroubleshoot: SELinux is preventing /usr/sbin/httpd from write access on the directory /var/www/html/application/cache. For complete SELinux messages. run sealert -l 087dfdb5-c7de-4238-8e6b-a713213a456d

As stated running sealert -l 087dfdb5-c7de-4238-8e6b-a713213a456d will reveal the command I wrote as solution.

Shiplu Mokaddim
  • 56,364
  • 17
  • 141
  • 187
0

Try to see if:

Log::instance()->add(Log::ERROR, "own exception handler");

works. The current Kohana documentation seems to indicate that using $log should still work, but it might get unset somewhere before the exception handling. Retrieving the instance from the Log class should be available at any time, however.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84
0

You might have a permission problem. In my case it was the httpd service (apache2) that couldn't access the project files. Here is a brutal solution (do it only if your security situation allows it):

$ sudo chmod -R 0777 /var/www/html/mysite/

From: move_uploaded_file gives "failed to open stream: Permission denied " error after all configurations i did

Antonello
  • 11
  • 1