Jump to content

How to log a warning?


theillo

Recommended Posts

In back office, under "Advanced Parameters" there's a LOGS tab.

 

Also there is a email template, called "log_alert" which has the text "WARNING: you have received a new log alert in your Back Office." in it.

 

And there is abstract class AbstractLoggerCore under "classes/log/AbstractLogger.php"

 

 

And I see quite a few messages getting logged, but I could not find out how to log one myself.

 

I'd like to record a warning and notify the store admin, if something goes wrong in the module I am creating. Anybody has a good idea how to do this?

 

 

 
Link to comment
Share on other sites

yes, it is very simple.  For a good example, open the PaymentModule class and search for "PrestaShopLogger::addLog". 

 

Just realize this class and function will only work with PS v1.6. 

 

In PS v1.4 and v1.5, the class name is Logger.  and it does not exist in v1.4.0.3 or earlier.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Great, thanks! 

 

To test it I just called it in the constructor of one of my admin controllers. It worked once, no matter how many time I reload the page... :D We'll see. 

 

 

So in classes/PrestaShopLogger.php we have 

public static function addLog($message, $severity = 1, $error_code = null, $object_type = null, $object_id = null, $allow_duplicate = false, $id_employee = null)

This method makes a call to sendByMail($log), which will first check if we have email logs turned on. 

if (intval(Configuration::get('PS_LOGS_BY_EMAIL')) <= intval($log->severity))

Anybody know if there's an interface in back office where PS_LOGS_BY_EMAIL get's set? Of course I could just turn it on before logging the alert if I insist on an email being sent, but that seems improper.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...