category -> product association implemented
This commit is contained in:
1 parent
0b8c5de8b0
commit
c8bcfe6bd6
41 files changed
+2222
-703
No files matched your search
@@ -1,25 +1,70 @@
|
||||
<?php
|
||||
if (!defined("_PS_VERSION_")) {
|
||||
exit();
|
||||
}
|
||||
|
||||
class EcomZoneLogger
|
||||
{
|
||||
const LOG_FILE = _PS_ROOT_DIR_ . '/var/logs/ecomzone.log';
|
||||
|
||||
public static function log($message, $level = 'INFO', $context = [])
|
||||
private static $logFile = 'ecomzone.log';
|
||||
private static $maxLogSize = 10485760; // 10MB
|
||||
|
||||
public static function log($message, $level = "INFO", $context = [])
|
||||
{
|
||||
$date = date('Y-m-d H:i:s');
|
||||
$contextStr = !empty($context) ? json_encode($context) : '';
|
||||
$logMessage = "[$date] [$level] $message $contextStr\n";
|
||||
|
||||
file_put_contents(self::LOG_FILE, $logMessage, FILE_APPEND);
|
||||
|
||||
// Also log to PrestaShop
|
||||
PrestaShopLogger::addLog(
|
||||
"EcomZone: $message",
|
||||
($level === 'ERROR' ? 3 : 1),
|
||||
null,
|
||||
'EcomZone',
|
||||
null,
|
||||
true
|
||||
);
|
||||
try {
|
||||
$logDir = _PS_MODULE_DIR_ . 'ecomzone/log/';
|
||||
if (!is_dir($logDir)) {
|
||||
mkdir($logDir, 0755, true);
|
||||
}
|
||||
|
||||
$timestamp = date('Y-m-d H:i:s');
|
||||
$contextStr = !empty($context) ? json_encode($context) : '';
|
||||
|
||||
$logMessage = sprintf(
|
||||
"[%s] %s: %s %s\n",
|
||||
$timestamp,
|
||||
$level,
|
||||
$message,
|
||||
$contextStr
|
||||
);
|
||||
|
||||
file_put_contents(
|
||||
$logDir . self::$logFile,
|
||||
$logMessage,
|
||||
FILE_APPEND
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
// Fallback to PrestaShop's logger
|
||||
PrestaShopLogger::addLog(
|
||||
"EcomZone: $message",
|
||||
($level === 'ERROR' ? 3 : 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function initLogFile()
|
||||
{
|
||||
if (!file_exists(self::$logFile)) {
|
||||
$logDir = dirname(self::$logFile);
|
||||
if (!is_dir($logDir)) {
|
||||
mkdir($logDir, 0755, true);
|
||||
}
|
||||
touch(self::$logFile);
|
||||
chmod(self::$logFile, 0666);
|
||||
}
|
||||
}
|
||||
|
||||
private static function rotateLogIfNeeded()
|
||||
{
|
||||
if (!file_exists(self::$logFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (filesize(self::$logFile) > self::$maxLogSize) {
|
||||
$backup = self::$logFile . "." . date("Y-m-d-H-i-s") . ".bak";
|
||||
rename(self::$logFile, $backup);
|
||||
touch(self::$logFile);
|
||||
chmod(self::$logFile, 0666);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user