<?php
declare (strict_types = 1);
namespace ProxyPay\Traits;

trait Log
{

	public function log(mixed $data, string $context = ''): void
	{
		$name = strtolower(static::class);
		$name = explode('\\', $name);
		$name = array_pop($name);

		$logName = sprintf("%s/%s.txt", $this->config->log_path, $name);
		$date    = date('Y-m-d H:i:s');
		if (!is_scalar($data)) {
			$data = json_encode($data, JSON_UNESCAPED_UNICODE);
		}
		$message = "{$date} {$context}\n$data\n\n";
		file_put_contents($logName, $message, FILE_APPEND);
	}
}
