Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Add a Log level
  • Hi,

    For an application, I want to be able to log usefull informations in logs, alongside the errors and others logs. Doing so to next create a log viewer in my admin to access it easily.

    The problem is that when I use the L_INFO levels, log wont works until I change the log_threshold config entry. But if I do so, A bunch of fuel internal infos will be written in logs for each request.

    So I can add a log level entry but to do so I have to duplicate the Log class in my app folder, and the fuel class to, because log levels are Fuel class constants, and TBH, I would appreciate a better solution.

    What is the best way to handle this ? Thanks.   
  • HarroHarro
    Accepted Answer
    Fuel uses the Monolog package to do the actual logging. Tnese are the log levels Monolog supports: https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md#log-levels

    These levels are mapped to Fuel constants:
    L_DEBUG = 100;
    L_INFO = 200;
    L_WARNING = 300;
    L_ERROR = 400;

    which means 250, 500, 550 and 600 are still available for use. You can use your own constants, extend the Fuel class and add them there, or simply use the numbers.

    So say you create a global constant L_NOTICE = 250, you can configure your config file like so

    'log_threshold'    => L_NOTICE,

    which would cause everything 250 and above to be logged.

    To write a log entry, you can use

    logger(L_NOTICE, "this is my notice");

    or

    \Log::write(L_NOTICE, "this is my notice");

Howdy, Stranger!

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

In this Discussion