"Refactor logging logic to improve log level and backtrace information

The code has been updated to enhance the way log levels and backtrace information is handled. Changes have been done to ensure the backtrace ignores any calls coming from the LogLib namespace, improving clarity and reducing noise in the log output. Additionally, changes were made to 'colorize' and 'log' methods to adjust the typing of the log level from string to integer, enhancing the consistency of log level usage throughout the code. Removed the Backtrace class that was not serving any purpose after these updates. Tests are also updated to ensure proper functionality."
This commit is contained in:
Netkas 2023-10-12 23:40:05 -04:00
parent 7f2332e228
commit 951bdb325e
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
7 changed files with 157 additions and 228 deletions

View file

@ -1,179 +0,0 @@
<?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace LogLib\Objects;
class Backtrace
{
/**
* @var string|null
*/
private $function;
/**
* @var int|null
*/
private $line;
/**
* @var string|null
*/
private $file;
/**
* @var string|null
*/
private $class;
/**
* @see CallType
* @var string|null
*/
private $type;
/**
* @var array|null
*/
private $args;
/**
* Public Constructor
*
* @param array|null $backtrace
*/
public function __construct(?array $backtrace=null)
{
if($backtrace === null)
{
return;
}
$this->function = $backtrace['function'] ?? null;
$this->line = $backtrace['line'] ?? null;
$this->file = $backtrace['file'] ?? null;
$this->class = $backtrace['class'] ?? null;
$this->type = $backtrace['type'] ?? null;
$this->args = $backtrace['args'] ?? null;
}
/**
* Optional. Returns the function name of the backtrace
*
* @return string|null
*/
public function getFunction(): ?string
{
return $this->function;
}
/**
* Sets the function name of the backtrace
*
* @param string|null $function
*/
public function setFunction(?string $function): void
{
$this->function = $function;
}
/**
* Optional. Returns the line number of the backtrace
*
* @return int|null
*/
public function getLine(): ?int
{
return $this->line;
}
/**
* Sets the line number of the backtrace
*
* @param int|null $line
*/
public function setLine(?int $line): void
{
$this->line = $line;
}
/**
* Optional. Returns the file name of the backtrace
*
* @return string|null
*/
public function getFile(): ?string
{
return $this->file;
}
/**
* Sets the file name of the backtrace
*
* @param string|null $file
*/
public function setFile(?string $file): void
{
$this->file = $file;
}
/**
* Optional. Returns the class name, if any, of the backtrace
*
* @return string|null
*/
public function getClass(): ?string
{
return $this->class;
}
/**
* Sets the class name, if any, of the backtrace
*
* @param string|null $class
*/
public function setClass(?string $class): void
{
$this->class = $class;
}
/**
* Optional. Returns the current call type. If a method call, "->" is returned.
*
* @return string|null
*/
public function getType(): ?string
{
return $this->type;
}
/**
* Sets the current call type. If a method call, "->" is returned.
*
* @param string|null $type
*/
public function setType(?string $type): void
{
$this->type = $type;
}
/**
* Optional. Return the functions arguments or included file name(s)
*
* @return array|null
*/
public function getArgs(): ?array
{
return $this->args;
}
/**
* Sets the function arguments or included file name(s)
*
* @param array|null $args
*/
public function setArgs(?array $args): void
{
$this->args = $args;
}
}

View file

@ -12,12 +12,12 @@
{
/**
* @see LevelType
* @var string
* @var int
*/
private $level;
/**
* @var Backtrace[]|null
* @var array|null
*/
private $backtrace;