Skip to content

Instantly share code, notes, and snippets.

@jonpontet
Created December 16, 2021 13:45
Show Gist options
  • Save jonpontet/200ac25f6c3e0d9d7575eec17128eac5 to your computer and use it in GitHub Desktop.
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
<?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