Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Using Log class from tasks
  • Do I need to include something in order to make Log class available in tasks? If I use it as is I currently get Fatal error: Class 'Log' not found'...
  • Which Fuel version?

    If 1.5, you need to have the Log package, and have the package loaded. If any other version, Log is a core class and should always be present.

    Oil itself uses it too, so it should be present and loaded. Did you forget the \ to load from global?
  • Hi Harro. Yes I am still on 1.5 and I do not load it manually. What would be the right way to load it for my tasks?
  • If you're on 1.5, your always_load section MUST load the log package. If not the app itself will not work either.

    This complexity has made us decide to drop the package again in 1.6.
  • In always_load in main config file I do not extra load Log package... but it is working in my app anyway, but not in tasks if I call them via oil refine.
  • Something most load it, because in 1.5 the core doesn't have a Log class anymore. So if the package isn't loaded booting the framework should already give you a "class not found".

    Or did you upgrade from a previous version by simply copying files across, so you've got a stray 1.4 Log class in your fuel/core/classes folder?
  • Ok wierd. Log class is not in fuel/core/classes ... It is not loading from config either:

            'packages'  => array(
                'email',
                'orm',
                'warden',
                'ses',
            ),

    now I am also wondering where the Log package is loaded from :)? This is my admin app.
    Checked my front-end website app, I have log loaded in config. They use the same 1.5 core

            'packages'  => array(
                'log',
                'email',
                'orm',
                'warden',
                'ses',
            ),


  • That explains why your frontend works, and your backend doesn't. They run of different configs, you need to include 'log' in the packages array there too...
  • Not true. My back-end works as well, I have it deployed in production since 1st of May. Log class works flawlessly on config I posted above.

    Now I want to deploy some cron jobs where I would use Fuel's tasks in my back-end app but the Log class does not work in tasks... Strange huh?
  • Now I have added log in always_load of my admin app and run the task via oil refine, but now I get:

    Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/Applications/XAMPP/xamppfiles/htdocs/dewesoftadmin/fuel/app/logs/2013/09/18.php" could not be opened: failed to open stream: Permission denied' in /Applications/XAMPP/xamppfiles/htdocs/dewesoftadmin/fuel/packages/log/src/Monolog/Handler/StreamHandler.php:71

    I have write permissions on log folder? And Log works from app ...
  • ok it was osx permission problem... sudo php oil refine taskchecker worked!
  • Still no clues how the Log worked in my admin app but it wasn't loaded from always_load ... anyway now it works from tasks as well. Thanks yet again!
  • Big question was: did it? Or did it just fail silently and not log anything?
  • It sure did log, I have used it several times. Today as well as I tried to verify again. Very strange!
  • Indeed.

    If you want to know, add a Debug::backtrace() to the Log package's bootstrap file, so you can see where it's loaded from, and what initiated the load. Perhaps that will clear things up.
  • edit: already found it!

    The logger() function which provides a shortcut to the Log class methods does

    ! class_exists('Log') and \Package::load('log');

    to avoid errors when people forget to always load it.

    In case of your tasks, the Log class is probably called before the framework itself calls logger()...
  • Ah great, that explains it. Thanks!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion