Don't know if this is some sort of bug, but it looks like log_treshold doesn't work for all the routes executed via oil. The main config file has log_threshold set to Fuel::L_ALL and it works fine when executing regular http call.
When it is execuced as an oil call, it logs only fatal errors, ignoring the setting above.
Is this a bug or is there something else in the config that I've missed ?
The configured log_threshold is processed by the Log class when it initializes, no matter where it is used.
Are you sure your webserver and oil are using the same environment, and therefore read the same config file? Oil by default runs in development, if you want to use a different one, you need to set it:
Now, I have test task file with a method as follows:
public static function error_test() { echo 'test'; echo \Cli::new_line(1); echo \Request::forge('/dev/test')->execute(); }
What I get in the output: test Uncaught exception Fuel\Core\PhpErrorException: Undefined variable: sfsafsdf You have new mail in /var/mail/root
and in the logs: INFO - 2017-07-24 12:18:48 --> Fuel\Core\Request::__construct - Creating a new main Request with URI = "dev/test" INFO - 2017-07-24 12:18:48 --> Fuel\Core\Request::execute - Called INFO - 2017-07-24 12:18:48 --> Fuel\Core\Request::execute - Setting main Request
But no information about the error is logged in the log. I've tried to change default logging level by changing core config but no effect. I'm also quite sure that everything runs under production (db connection works as defined in the config for production) also this bit of code indicates correct environment setting:
echo \Fuel::$env gives me 'production' so it is not that.
It doesn't log anything if error_reporting() returns zero.
If it is not zero:
- if the error count is equal to the throttle value in the config, it doesn't log but throws an exception
- if the error count is lower, and the evironment isn't "production", it doesn't log but throws an exception
- if the error count is lower, and the error type isn't set in error_reporting(). it doesn't log but throws an exception
So my gut feeling is the default error_reporting() settings in your php.ini, because for http requests, it is explicitly set to -1 (all errors) in your index.php, but oil doesn't set anything.
[ wanwizard@catwoman] $ FUEL_ENV=production oil r test:error_test
test
Notice - Undefined variable: jhajkdh in APPPATH/views/welcome/index.php on line 1
Method used:
public static function error_test()
{
echo 'test';
echo \Cli::new_line(1);
echo \Request::forge('/')->execute();
}
First line of the welcome view:
<?php echo $jhajkdh; ?>
The log file contains:
[wanwizard@catwoman] $ cat 24.php
<?php defined('COREPATH') or exit('No direct script access allowed'); ?>
INFO - 2017-07-24 14:38:56 --> Fuel\Core\Request::__construct - Creating a new main Request with URI = ""
INFO - 2017-07-24 14:38:56 --> Fuel\Core\Request::execute - Called
INFO - 2017-07-24 14:38:56 --> Fuel\Core\Request::execute - Setting main Request
ERROR - 2017-07-24 14:38:56 --> Notice - Undefined variable: jhajkdh in /data/www/mvhosts/fuel.catwoman.flexcoders.local/19develop/fuel/app/views/welcome/index.php on line 1
I've tried to force env to production on command line and it gives me same results and I've also confirmed that it runs on production by default (it is set on vhost definition level).
Don't know if that's any important informaton, but all environments share single main config file (app/config/config.php) and error logging treshold is set to E_ALL. The only setting different between environments is db.php files, but I've also tried to alter core config and set the flag there, but results were exactly the same
Oil doesn't use the vhost definition. You have to use the command format I gave you.
And yes, it is important, the code checks in several places if the environment is set to \Fuel::PRODUCTION, to prevent leakage of sensitive information, and that includes the way errors are handled.
If the environment is not set to \Fuel::PRODUCTION, the log entries will not be created but the execution will be aborted, which is why you see the exception being returned, and I don't.
Ay yes, what you have said makes more sense now. I think that was an issue last time when we wanted to simplify deployment process and environment is also set in application's bootstrap file :
But I'm pretty sure it is on production as \Fuel::$env -> production also it connects correctly to the production database and it would not on any other case.
<?php defined('COREPATH') or exit('No direct script access allowed'); ?>
INFO - 2017-07-25 15:59:14 --> Fuel\Core\Request::__construct - Creating a new main Request with URI = ""
INFO - 2017-07-25 15:59:14 --> Fuel\Core\Request::execute - Called
INFO - 2017-07-25 15:59:14 --> Fuel\Core\Request::execute - Setting main Request
ERROR - 2017-07-25 15:59:14 --> Notice - Undefined variable: hjagdjga in /data/www/mvhosts/fuel.catwoman.flexcoders.local/18develop/fuel/app/views/welcome/index.php on line 1
works fine here too, no exception from the oil command, and a correct log entry.
Your app doesn't have something overloaded that can interfere with the error handling?
I've upgraded core to 1.9, however problem still exists. Notice errors are correctly logged when request comes through http call, anything executed via oil is logged above warning level.
I'll try to dig deeper into the problem and let you know about my findings, thank you for all the help so far.