| Server IP : 186.64.123.29 / Your IP : 216.73.217.94 Web Server : LiteSpeed System : Linux house.hostinglat.cl 5.15.0-185-generic #195-Ubuntu SMP Fri Jun 19 17:11:50 UTC 2026 x86_64 User : tuemp9827 ( 1016) PHP Version : 8.1.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/tuempresavirtual.cl/public_html/wp-content/plugins/tidio-live-chat/src/Logs/ |
Upload File : |
<?php
namespace TidioLiveChat\Logs;
if (!defined('WPINC')) {
die('File loaded directly. Exiting.');
}
use DateTime;
use TidioLiveChat\Clock\Clock;
use function array_reverse;
use function file_exists;
use function touch;
use function sprintf;
use function error_log;
use function file_get_contents;
final class Logger
{
/** @var string */
private $path;
/** @var Clock */
private $clock;
/**
* @param string $path Debug logs file name
* @param Clock $clock
*/
public function __construct($path, $clock)
{
$this->path = $path;
$this->clock = $clock;
if (!file_exists($this->path)) {
touch($this->path);
}
}
/**
* @param string $message
* @return void
*/
public function info($message)
{
$this->storeLogLine('info', $message);
}
/**
* @param string $message
* @return void
*/
public function debug($message)
{
$this->storeLogLine('debug', $message);
}
/**
* @param string $message
* @return void
*/
public function error($message)
{
$this->storeLogLine('error', $message);
}
/**
* @return string
*/
public function readLog()
{
$logContent = file_get_contents($this->path);
$lines = explode(PHP_EOL, $logContent ?: '');
$reversedLines = array_reverse($lines);
$reversedContent = trim(implode(PHP_EOL, $reversedLines));
return $reversedContent ?: 'Log file is empty';
}
/**
* @return void
*/
public function clearLog()
{
file_put_contents($this->path, '');
}
/**
* @param string $severity
* @param string $message
* @return void
*/
private function storeLogLine($severity, $message)
{
$date = $this->clock->getCurrentTimestamp()->format(DateTime::ATOM);
$formattedError = sprintf('[%s][%s] %s' . PHP_EOL, $date, $severity, $message);
error_log($formattedError, 3, $this->path);
}
}