Created
December 16, 2021 13:45
-
-
Save jonpontet/200ac25f6c3e0d9d7575eec17128eac5 to your computer and use it in GitHub Desktop.
Add a generic logging function to your custom PrestaShop module that will log messages to the Logs page of the Back Office
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Generic logging function | |
* | |
* @param $event | |
* @param $info | |
* @param int $level | |
* @param null $supplementary | |
* @return bool | |
*/ | |
public function logGeneric($event, $info, $level = 1, $supplementary = null) | |
{ | |
if (!$level) { | |
$level = 1; | |
}; | |
$customer_id = 'unknown'; | |
if (isset($this->context->customer)) { | |
$customer_id = $this->context->customer->id; | |
} | |
$message = sprintf('%s : %s (customer_id : %s%s)',$event, $info, $customer_id, | |
($supplementary) ? sprintf(', supplementary : %s', $supplementary) : ''); | |
return PrestaShopLogger::addLog($message, $level); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment