hesabixWCPlugin/admin/services/HesabixLogService.php

72 lines
2.1 KiB
PHP
Raw Normal View History

<?php
2025-08-05 17:24:52 +03:30
/**
* Hesabix Log Service
*
* @package Hesabix
* @author Mohammad Rezai
* @author URI https://pirouz.xyz
* @since 1.0.0
*/
class HesabixLogService
{
public static function writeLogStr($str)
{
2025-08-05 17:24:52 +03:30
$fileName = WP_CONTENT_DIR . '/hesabix-' . date("20y-m-d") . '.txt';
2025-08-05 17:24:52 +03:30
$dateTime = new DateTimeImmutable('now', wp_timezone());
$date = $dateTime->format('[Y-m-d H:i:s] ');
$str = $date . $str;
$str = mb_convert_encoding($str, 'UTF-8');
file_put_contents($fileName, PHP_EOL . $str, FILE_APPEND);
}
public static function writeLogObj($obj)
{
2025-08-05 17:24:52 +03:30
$fileName = WP_CONTENT_DIR . '/hesabix-' . date("20y-m-d") . '.txt';
ob_start();
var_dump($obj);
file_put_contents($fileName, PHP_EOL . ob_get_flush(), FILE_APPEND);
}
public static function log($params)
{
2025-08-05 17:24:52 +03:30
$fileName = WP_CONTENT_DIR . '/hesabix-' . date("20y-m-d") . '.txt';
$log = '';
2025-08-05 17:24:52 +03:30
$dateTime = new DateTimeImmutable('now', wp_timezone());
$date = $dateTime->format('[Y-m-d H:i:s] ');
foreach ($params as $message) {
if (is_array($message) || is_object($message)) {
$log .= $date . print_r($message, true) . "\n";
} elseif (is_bool($message)) {
$log .= $date . ($message ? 'true' : 'false') . "\n";
} else {
$log .= $date . $message . "\n";
}
}
$log = mb_convert_encoding($log, 'UTF-8');
file_put_contents($fileName, PHP_EOL . $log, FILE_APPEND);
}
public static function readLog($URL)
{
return file_exists($URL) ? file_get_contents($URL) : '';
}
public static function clearLog()
{
2025-08-05 17:24:52 +03:30
$fileName = WP_CONTENT_DIR . '/hesabix-' . date("20y-m-d") . '.txt';
if (file_exists($fileName)) {
file_put_contents($fileName, "");
}
}
public static function getLogFilePath()
{
2025-08-05 17:24:52 +03:30
return WP_CONTENT_DIR . '/hesabix-' . date("20y-m-d") . '.txt';
}
}