Rename classes to enums and update usage

This commit is contained in:
netkas 2024-10-26 00:18:08 -04:00
parent 2dd8f912b2
commit fa27ed6405
10 changed files with 234 additions and 235 deletions

View file

@ -5,8 +5,8 @@
namespace LogLib\Classes; namespace LogLib\Classes;
use Exception; use Exception;
use LogLib\Abstracts\ConsoleColors; use LogLib\Enums\ConsoleColors;
use LogLib\Abstracts\LevelType; use LogLib\Enums\LogLevel;
use LogLib\Log; use LogLib\Log;
use LogLib\Objects\Event; use LogLib\Objects\Event;
use LogLib\Objects\Options; use LogLib\Objects\Options;
@ -15,21 +15,9 @@
class Console class Console
{ {
/** private static array $application_colors = [];
* @var array private static float|int|null $last_tick_time;
*/ private static ?int $largest_tick_length;
private static $application_colors = [];
/**
* @var float|int|null
*/
private static $last_tick_time;
/**
* @var int|null
*/
private static $largest_tick_length;
/** /**
* Formats the application name with a color for the console * Formats the application name with a color for the console
@ -68,17 +56,17 @@
* Applies a specified color to the given text, using ANSI escape sequences. * Applies a specified color to the given text, using ANSI escape sequences.
* *
* @param string $text The text to apply the color to. * @param string $text The text to apply the color to.
* @param string $color The ANSI color code to apply to the text. * @param ConsoleColors $color The ANSI color code to apply to the text.
* @return string The text with the specified color applied. * @return string The text with the specified color applied.
*/ */
private static function color(string $text, string $color): string private static function color(string $text, ConsoleColors $color): string
{ {
if(!Log::getRuntimeOptions()->displayAnsi()) if(!Log::getRuntimeOptions()->displayAnsi())
{ {
return $text; return $text;
} }
return "\033[" . $color . "m" . $text . "\033[0m"; return "\033[" . $color->value . "m" . $text . "\033[0m";
} }
/** /**
@ -96,12 +84,12 @@
$color = match($event->getLevel()) $color = match($event->getLevel())
{ {
LevelType::DEBUG => ConsoleColors::LIGHT_PURPLE, LogLevel::DEBUG => ConsoleColors::LIGHT_PURPLE,
LevelType::VERBOSE => ConsoleColors::LIGHT_CYAN, LogLevel::VERBOSE => ConsoleColors::LIGHT_CYAN,
LevelType::INFO => ConsoleColors::WHITE, LogLevel::INFO => ConsoleColors::WHITE,
LevelType::WARNING => ConsoleColors::YELLOW, LogLevel::WARNING => ConsoleColors::YELLOW,
LevelType::FATAL => ConsoleColors::RED, LogLevel::FATAL => ConsoleColors::RED,
LevelType::ERROR => ConsoleColors::LIGHT_RED, LogLevel::ERROR => ConsoleColors::LIGHT_RED,
default => null, default => null,
}; };
@ -165,7 +153,7 @@
return; return;
} }
if(Validate::checkLevelType(LevelType::DEBUG, Log::getRuntimeOptions()->getLoglevel())) if(Validate::checkLevelType(LogLevel::DEBUG, Log::getRuntimeOptions()->getLoglevel()))
{ {
$backtrace_output = Utilities::getTraceString($event, Log::getRuntimeOptions()->displayAnsi()); $backtrace_output = Utilities::getTraceString($event, Log::getRuntimeOptions()->displayAnsi());
@ -184,7 +172,7 @@
return; return;
} }
if(Validate::checkLevelType(LevelType::VERBOSE, Log::getRuntimeOptions()->getLoglevel())) if(Validate::checkLevelType(LogLevel::VERBOSE, Log::getRuntimeOptions()->getLoglevel()))
{ {
$backtrace_output = Utilities::getTraceString($event, Log::getRuntimeOptions()->displayAnsi()); $backtrace_output = Utilities::getTraceString($event, Log::getRuntimeOptions()->displayAnsi());

View file

@ -2,8 +2,8 @@
namespace LogLib\Classes; namespace LogLib\Classes;
use LogLib\Abstracts\CallType; use LogLib\Enums\CallType;
use LogLib\Abstracts\LevelType; use LogLib\Enums\LogLevel;
use LogLib\Objects\Event; use LogLib\Objects\Event;
use OptsLib\Parse; use OptsLib\Parse;
use Throwable; use Throwable;
@ -28,19 +28,19 @@
/** /**
* Converts a log level to its corresponding string representation. * Converts a log level to its corresponding string representation.
* *
* @param int $level The log level to convert. * @param LogLevel $level The log level to convert.
* @return string The string representation of the log level. * @return string The string representation of the log level.
*/ */
public static function levelToString(int $level): string public static function levelToString(LogLevel $level): string
{ {
return match ($level) return match ($level)
{ {
LevelType::DEBUG => 'DBG', LogLevel::DEBUG => 'DBG',
LevelType::VERBOSE => 'VRB', LogLevel::VERBOSE => 'VRB',
LevelType::INFO => 'INF', LogLevel::INFO => 'INF',
LevelType::WARNING => 'WRN', LogLevel::WARNING => 'WRN',
LevelType::FATAL => 'CRT', LogLevel::FATAL => 'CRT',
LevelType::ERROR => 'ERR', LogLevel::ERROR => 'ERR',
default => 'UNK', default => 'UNK',
}; };
} }
@ -69,7 +69,7 @@
/** /**
* Returns the log level based on the configuration. * Returns the log level based on the configuration.
* *
* @return int The log level. This value represents the severity or importance of the log messages. * @return LogLevel The log level. This value represents the severity or importance of the log messages.
* The returned value will be one of the constants defined in the LevelType class: * The returned value will be one of the constants defined in the LevelType class:
* - DEBUG (6) * - DEBUG (6)
* - VERBOSE (5) * - VERBOSE (5)
@ -80,54 +80,54 @@
* - SILENT (0) * - SILENT (0)
* If no log level is configured or the configured level is not recognized, the INFO level (4) will be returned by default. * If no log level is configured or the configured level is not recognized, the INFO level (4) will be returned by default.
*/ */
public static function getLogLevel(): int public static function getLogLevel(): LogLevel
{ {
$args = Parse::getArguments(); $args = Parse::getArguments();
switch(strtolower(($args['log'] ?? $args['log-level'] ?? (getenv('LOG_LEVEL') ?: 'info') ?? 'info'))) switch(strtolower(($args['log'] ?? $args['log-level'] ?? (getenv('LOG_LEVEL') ?: 'info') ?? 'info')))
{ {
case LevelType::DEBUG: case LogLevel::DEBUG:
case 'debug': case 'debug':
case '6': case '6':
case 'dbg': case 'dbg':
return LevelType::DEBUG; return LogLevel::DEBUG;
case LevelType::VERBOSE: case LogLevel::VERBOSE:
case 'verbose': case 'verbose':
case '5': case '5':
case 'vrb': case 'vrb':
return LevelType::VERBOSE; return LogLevel::VERBOSE;
default: default:
case LevelType::INFO: case LogLevel::INFO:
case 'info': case 'info':
case '4': case '4':
case 'inf': case 'inf':
return LevelType::INFO; return LogLevel::INFO;
case LevelType::WARNING: case LogLevel::WARNING:
case 'warning': case 'warning':
case '3': case '3':
case 'wrn': case 'wrn':
return LevelType::WARNING; return LogLevel::WARNING;
case LevelType::ERROR: case LogLevel::ERROR:
case 'error': case 'error':
case '2': case '2':
case 'err': case 'err':
return LevelType::ERROR; return LogLevel::ERROR;
case LevelType::FATAL: case LogLevel::FATAL:
case 'fatal': case 'fatal':
case '1': case '1':
case 'crt': case 'crt':
return LevelType::FATAL; return LogLevel::FATAL;
case LevelType::SILENT: case LogLevel::SILENT:
case 'silent': case 'silent':
case '0': case '0':
case 'sil': case 'sil':
return LevelType::SILENT; return LogLevel::SILENT;
} }
} }
@ -164,7 +164,7 @@
{ {
if($event->getBacktrace() === null || count($event->getBacktrace()) === 0) if($event->getBacktrace() === null || count($event->getBacktrace()) === 0)
{ {
return CallType::LAMBDA_CALL; return CallType::LAMBDA_CALL->value;
} }
$backtrace = $event->getBacktrace()[count($event->getBacktrace()) - 1]; $backtrace = $event->getBacktrace()[count($event->getBacktrace()) - 1];
@ -184,20 +184,20 @@
{ {
if(isset($backtrace['file'])) if(isset($backtrace['file']))
{ {
return ($ansi ? "\033[1;37m" : '') . basename($backtrace['file']) . ($ansi ? "\033[0m" : '') . CallType::STATIC_CALL . CallType::LAMBDA_CALL; return ($ansi ? "\033[1;37m" : '') . basename($backtrace['file']) . ($ansi ? "\033[0m" : '') . CallType::STATIC_CALL->value . CallType::LAMBDA_CALL->value;
} }
return basename($backtrace['file']) . CallType::STATIC_CALL . CallType::LAMBDA_CALL; return basename($backtrace['file']) . CallType::STATIC_CALL->value . CallType::LAMBDA_CALL->value;
} }
if($backtrace['function'] === 'eval') if($backtrace['function'] === 'eval')
{ {
if(isset($backtrace['file'])) if(isset($backtrace['file']))
{ {
return ($ansi ? "\033[1;37m" : '') . basename($backtrace['file']) . ($ansi ? "\033[0m" : '') . CallType::STATIC_CALL . CallType::EVAL_CALL; return ($ansi ? "\033[1;37m" : '') . basename($backtrace['file']) . ($ansi ? "\033[0m" : '') . CallType::STATIC_CALL->value . CallType::EVAL_CALL->value;
} }
return basename($backtrace['file']) . CallType::STATIC_CALL . CallType::EVAL_CALL; return basename($backtrace['file']) . CallType::STATIC_CALL->value . CallType::EVAL_CALL->value;
} }
if($ansi) if($ansi)
@ -218,11 +218,11 @@
if($class === null) if($class === null)
{ {
return $function . CallType::FUNCTION_CALL; return $function . CallType::FUNCTION_CALL->value;
} }
$type = ($backtrace['type'] === CallType::METHOD_CALL ? CallType::METHOD_CALL : CallType::STATIC_CALL); $type = ($backtrace['type'] === CallType::METHOD_CALL ? CallType::METHOD_CALL : CallType::STATIC_CALL);
return "{$class}{$type}{$function}" . CallType::FUNCTION_CALL; return "{$class}{$type->value}{$function}" . CallType::FUNCTION_CALL->value;
} }

View file

@ -2,98 +2,78 @@
namespace LogLib\Classes; namespace LogLib\Classes;
use LogLib\Abstracts\LevelType; use LogLib\Enums\LogLevel;
class Validate class Validate
{ {
/**
* Checks if the given level is a valid level type.
*
* @param int $level The level to check.
* @return bool Returns true if the level is valid
*/
public static function LevelType(int $level): bool
{
return in_array($level, LevelType::ALL);
}
/** /**
* Checks if the given input level is valid for the current level. * Checks if the given input level is valid for the current level.
* *
* @param int $input The input level to check. * @param LogLevel $input The input level to check.
* @param int $current_level The current level to compare against. * @param LogLevel $current_level The current level to compare against.
* @return bool Returns true if the input level is valid for the current level, false otherwise. * @return bool Returns true if the input level is valid for the current level, false otherwise.
*/ */
public static function checkLevelType(int $input, int $current_level): bool public static function checkLevelType(LogLevel $input, LogLevel $current_level): bool
{ {
if(!self::LevelType($input))
{
return false;
}
if(!self::LevelType($current_level))
{
return false;
}
switch($current_level) switch($current_level)
{ {
case LevelType::DEBUG: case LogLevel::DEBUG:
$levels = [ $levels = [
LevelType::DEBUG, LogLevel::DEBUG,
LevelType::VERBOSE, LogLevel::VERBOSE,
LevelType::INFO, LogLevel::INFO,
LevelType::WARNING, LogLevel::WARNING,
LevelType::FATAL, LogLevel::FATAL,
LevelType::ERROR LogLevel::ERROR
]; ];
return in_array($input, $levels, true); return in_array($input, $levels, true);
case LevelType::VERBOSE: case LogLevel::VERBOSE:
$levels = [ $levels = [
LevelType::VERBOSE, LogLevel::VERBOSE,
LevelType::INFO, LogLevel::INFO,
LevelType::WARNING, LogLevel::WARNING,
LevelType::FATAL, LogLevel::FATAL,
LevelType::ERROR LogLevel::ERROR
]; ];
return in_array($input, $levels, true); return in_array($input, $levels, true);
case LevelType::INFO: case LogLevel::INFO:
$levels = [ $levels = [
LevelType::INFO, LogLevel::INFO,
LevelType::WARNING, LogLevel::WARNING,
LevelType::FATAL, LogLevel::FATAL,
LevelType::ERROR LogLevel::ERROR
]; ];
return in_array($input, $levels, true); return in_array($input, $levels, true);
case LevelType::WARNING: case LogLevel::WARNING:
$levels = [ $levels = [
LevelType::WARNING, LogLevel::WARNING,
LevelType::FATAL, LogLevel::FATAL,
LevelType::ERROR LogLevel::ERROR
]; ];
return in_array($input, $levels, true); return in_array($input, $levels, true);
case LevelType::ERROR: case LogLevel::ERROR:
$levels = [ $levels = [
LevelType::FATAL, LogLevel::FATAL,
LevelType::ERROR LogLevel::ERROR
]; ];
return in_array($input, $levels, true); return in_array($input, $levels, true);
case LevelType::FATAL: case LogLevel::FATAL:
return $input === LevelType::FATAL; return $input == LogLevel::FATAL;
default: case LogLevel::SILENT:
case LevelType::SILENT:
return false; return false;
} }
return false;
} }
} }

View file

@ -1,41 +1,41 @@
<?php <?php
namespace LogLib\Abstracts; namespace LogLib\Enums;
final class CallType enum CallType : string
{ {
/** /**
* Represents a method call. * Represents a method call.
* *
* @var string METHOD_CALL * @var string METHOD_CALL
*/ */
public const METHOD_CALL = '->'; case METHOD_CALL = '->';
/** /**
* Represents a static method call. * Represents a static method call.
* *
* @var string STATIC_CALL * @var string STATIC_CALL
*/ */
public const STATIC_CALL = '::'; case STATIC_CALL = '::';
/** /**
* Represents a function call. * Represents a function call.
* *
* @var string FUNCTION_CALL * @var string FUNCTION_CALL
*/ */
public const FUNCTION_CALL = '()'; case FUNCTION_CALL = '()';
/** /**
* Represents a lambda function call. * Represents a lambda function call.
* *
* @var string LAMBDA_CALL * @var string LAMBDA_CALL
*/ */
public const LAMBDA_CALL = 'λ'; case LAMBDA_CALL = 'λ';
/** /**
* Represents an eval() call. * Represents an eval() call.
* *
* @var string EVAL_CALL * @var string EVAL_CALL
*/ */
public const EVAL_CALL = 'eval()'; case EVAL_CALL = 'eval()';
} }

View file

@ -1,42 +1,42 @@
<?php <?php
namespace LogLib\Abstracts; namespace LogLib\Enums;
final class ConsoleColors enum ConsoleColors : string
{ {
public const BLACK = "0;30"; case BLACK = "0;30";
public const DARK_GRAY = "1;30"; case DARK_GRAY = "1;30";
public const BLUE = "0;34"; case BLUE = "0;34";
public const LIGHT_BLUE = "1;34"; case LIGHT_BLUE = "1;34";
public const GREEN = "0;32"; case GREEN = "0;32";
public const LIGHT_GREEN = "1;32"; case LIGHT_GREEN = "1;32";
public const CYAN = "0;36"; case CYAN = "0;36";
public const LIGHT_CYAN = "1;36"; case LIGHT_CYAN = "1;36";
public const RED = "0;31"; case RED = "0;31";
public const LIGHT_RED = "1;31"; case LIGHT_RED = "1;31";
public const PURPLE = "0;35"; case PURPLE = "0;35";
public const LIGHT_PURPLE = "1;35"; case LIGHT_PURPLE = "1;35";
public const BROWN = "0;33"; case BROWN = "0;33";
public const YELLOW = "1;33"; case YELLOW = "1;33";
public const LIGHT_GRAY = "0;37"; case LIGHT_GRAY = "0;37";
public const WHITE = "1;37"; case WHITE = "1;37";
public const RESET = "0"; case RESET = "0";
/** /**
* Represents an array of all possible supported color values. * Represents an array of all possible supported color values.

View file

@ -1,43 +1,43 @@
<?php <?php
namespace LogLib\Abstracts; namespace LogLib\Enums;
final class LevelType enum LogLevel : int
{ {
/** /**
* Silent type. * Silent type.
*/ */
public const SILENT = 0; case SILENT = 0;
/** /**
* Fatal type. * Fatal type.
*/ */
public const FATAL = 1; case FATAL = 1;
/** /**
* Error type. * Error type.
*/ */
public const ERROR = 2; case ERROR = 2;
/** /**
* *
*/ */
public const WARNING = 3; case WARNING = 3;
/** /**
* Information type. * Information type.
*/ */
public const INFO = 4; case INFO = 4;
/** /**
* Verbose type. * Verbose type.
*/ */
public const VERBOSE = 5; case VERBOSE = 5;
/** /**
* Debug type. * Debug type.
*/ */
public const DEBUG = 6; case DEBUG = 6;
/** /**
* All types. * All types.

View file

@ -5,10 +5,10 @@
namespace LogLib; namespace LogLib;
use InvalidArgumentException; use InvalidArgumentException;
use LogLib\Abstracts\LevelType;
use LogLib\Classes\Console; use LogLib\Classes\Console;
use LogLib\Classes\Utilities; use LogLib\Classes\Utilities;
use LogLib\Classes\Validate; use LogLib\Classes\Validate;
use LogLib\Enums\LogLevel;
use LogLib\Objects\Event; use LogLib\Objects\Event;
use LogLib\Objects\Options; use LogLib\Objects\Options;
use LogLib\Objects\RuntimeOptions; use LogLib\Objects\RuntimeOptions;
@ -110,21 +110,15 @@
* Logs a message with a specified application name, level, optional message, and optional throwable. * Logs a message with a specified application name, level, optional message, and optional throwable.
* *
* @param string $application_name The name of the application * @param string $application_name The name of the application
* @param int $level The level type of the log (default is LevelType::INFO) * @param LogLevel $level The level type of the log (default is LevelType::INFO)
* @param string|null $message The message of the log event * @param string|null $message The message of the log event
* @param Throwable|null $throwable The exception that was thrown, if any * @param Throwable|null $throwable The exception that was thrown, if any
* @return void * @return void
* @throws InvalidArgumentException If the provided level type is invalid or a message is null
*/ */
private static function log(string $application_name, int $level=LevelType::INFO, ?string $message=null, ?Throwable $throwable=null): void private static function log(string $application_name, LogLevel $level=LogLevel::INFO, ?string $message=null, ?Throwable $throwable=null): void
{ {
$application = self::getOptions($application_name); $application = self::getOptions($application_name);
if(!Validate::levelType($level))
{
throw new InvalidArgumentException(sprintf('Invalid level type: %s', $level));
}
if(!Validate::checkLevelType($level, self::getRuntimeOptions()->getLoglevel())) if(!Validate::checkLevelType($level, self::getRuntimeOptions()->getLoglevel()))
{ {
return; return;
@ -155,7 +149,7 @@
*/ */
public static function info(string $application_name, string $message): void public static function info(string $application_name, string $message): void
{ {
self::log($application_name, LevelType::INFO, $message); self::log($application_name, LogLevel::INFO, $message);
} }
/** /**
@ -165,7 +159,7 @@
*/ */
public static function verbose(string $application_name, string $message): void public static function verbose(string $application_name, string $message): void
{ {
self::log($application_name, LevelType::VERBOSE, $message); self::log($application_name, LogLevel::VERBOSE, $message);
} }
/** /**
@ -175,7 +169,7 @@
*/ */
public static function debug(string $application_name, string $message): void public static function debug(string $application_name, string $message): void
{ {
self::log($application_name, LevelType::DEBUG, $message); self::log($application_name, LogLevel::DEBUG, $message);
} }
/** /**
@ -188,7 +182,7 @@
*/ */
public static function warning(string $application_name, string $message, ?Throwable $throwable=null): void public static function warning(string $application_name, string $message, ?Throwable $throwable=null): void
{ {
self::log($application_name, LevelType::WARNING, $message, $throwable); self::log($application_name, LogLevel::WARNING, $message, $throwable);
} }
/** /**
@ -201,7 +195,7 @@
**/ **/
public static function error(string $application_name, string $message, ?Throwable $throwable=null): void public static function error(string $application_name, string $message, ?Throwable $throwable=null): void
{ {
self::log($application_name, LevelType::ERROR, $message, $throwable); self::log($application_name, LogLevel::ERROR, $message, $throwable);
} }
/** /**
@ -214,7 +208,7 @@
*/ */
public static function fatal(string $application_name, string $message, ?Throwable $throwable=null): void public static function fatal(string $application_name, string $message, ?Throwable $throwable=null): void
{ {
self::log($application_name, LevelType::FATAL, $message, $throwable); self::log($application_name, LogLevel::FATAL, $message, $throwable);
} }
/** /**

View file

@ -4,15 +4,14 @@
namespace LogLib\Objects; namespace LogLib\Objects;
use LogLib\Abstracts\LevelType;
use LogLib\Classes\Utilities; use LogLib\Classes\Utilities;
use LogLib\Enums\LogLevel;
use Throwable; use Throwable;
class Event class Event
{ {
/** /**
* @see LevelType * @var LogLevel
* @var int
*/ */
private $level; private $level;
@ -35,11 +34,11 @@
* Event constructor. * Event constructor.
* *
* @param string $message * @param string $message
* @param int $level * @param LogLevel $level
* @param Throwable|null $exception * @param Throwable|null $exception
* @param array|null $backtrace * @param array|null $backtrace
*/ */
public function __construct(string $message, int $level, ?Throwable $exception=null, ?array $backtrace=null) public function __construct(string $message, LogLevel $level, ?Throwable $exception=null, ?array $backtrace=null)
{ {
$this->message = $message; $this->message = $message;
$this->level = $level; $this->level = $level;
@ -50,10 +49,10 @@
/** /**
* Returns the level of the event * Returns the level of the event
* *
* @see LevelType * @return LogLevel
* @return int * @see LogLevel
*/ */
public function getLevel(): int public function getLevel(): LogLevel
{ {
return $this->level; return $this->level;
} }
@ -108,5 +107,4 @@
{ {
$this->backtrace = $backtrace; $this->backtrace = $backtrace;
} }
} }

View file

@ -4,115 +4,155 @@
namespace LogLib\Objects; namespace LogLib\Objects;
use LogLib\Abstracts\LevelType;
use LogLib\Classes\Utilities; use LogLib\Classes\Utilities;
use LogLib\Enums\LogLevel;
class RuntimeOptions class RuntimeOptions
{ {
/** private $consoleOutput;
* Indicates if the console output is enabled private bool $displayAnsi;
* private bool $handleExceptions;
* @var bool private LogLevel $logLevel;
* @property_name console_output private bool $fileLoggingEnabled;
*/ private LogLevel $fileLoggingLevel;
private $console_output;
/** /**
* Indicates if ANSI colors should be used in the console output
* *
* @var bool * @return void
* @property_name display_ansi
*/
private $display_ansi;
/**
* Indicates if LogLib should handle uncaught exceptions
*
* @var bool
* @property_name handle_exceptions
*/
private $handle_exceptions;
/**
* The current log level
*
* @var int
* @see LevelType
*/
private $log_level;
/**
* Public Constructor
*/ */
public function __construct() public function __construct()
{ {
$this->console_output = Utilities::runningInCli(); $this->consoleOutput = Utilities::runningInCli();
$this->display_ansi = Utilities::getDisplayAnsi(); $this->displayAnsi = Utilities::getDisplayAnsi();
$this->log_level = Utilities::getLogLevel(); $this->logLevel = Utilities::getLogLevel();
$this->handle_exceptions = true; $this->fileLoggingEnabled = true;
$this->fileLoggingLevel = LogLevel::ERROR;
$this->handleExceptions = true;
} }
/** /**
* @return bool * Checks if console output is enabled.
*
* @return bool Returns true if console output is enabled, false otherwise.
*/ */
public function isConsoleOutput(): bool public function isConsoleOutput(): bool
{ {
return $this->console_output; return $this->consoleOutput;
} }
/** /**
* @param bool $console_output * Set the console output flag.
*
* @param bool $consoleOutput Indicates whether to enable or disable console output.
* @return void
*/ */
public function setConsoleOutput(bool $console_output): void public function setConsoleOutput(bool $consoleOutput): void
{ {
$this->console_output = $console_output; $this->consoleOutput = $consoleOutput;
} }
/** /**
* @return bool * Determines if ANSI display is enabled.
*
* @return bool Returns true if ANSI display is enabled, false otherwise.
*/ */
public function displayAnsi(): bool public function displayAnsi(): bool
{ {
return $this->display_ansi; return $this->displayAnsi;
} }
/** /**
* @param bool $display_ansi * Sets whether to display ANSI colors in the console output.
*
* @param bool $displayAnsi A boolean value indicating whether ANSI colors should be displayed.
* @return void
*/ */
public function setDisplayAnsi(bool $display_ansi): void public function setDisplayAnsi(bool $displayAnsi): void
{ {
$this->display_ansi = $display_ansi; $this->displayAnsi = $displayAnsi;
} }
/** /**
* @return bool * Get the flag indicating whether exceptions are being handled.
*
* @return bool True if exceptions are being handled
*/ */
public function handleExceptions(): bool public function handleExceptions(): bool
{ {
return $this->handle_exceptions; return $this->handleExceptions;
} }
/** /**
* @param bool $handle_exceptions * Set the exception handling behavior.
*
* @param bool $handleExceptions A boolean value indicating whether to handle exceptions.
* @return void
*/ */
public function setHandleExceptions(bool $handle_exceptions): void public function setHandleExceptions(bool $handleExceptions): void
{ {
$this->handle_exceptions = $handle_exceptions; $this->handleExceptions = $handleExceptions;
} }
/** /**
* @return int * Returns the current log level.
*
* @return LogLevel The current log level.
*/ */
public function getLoglevel(): int public function getLoglevel(): LogLevel
{ {
return $this->log_level; return $this->logLevel;
} }
/** /**
* @param int $log_level * Sets the log level for logging operations.
*
* @param LogLevel $logLevel The log level to be set.
* @return void
*/ */
public function setLoglevel(int $log_level): void public function setLoglevel(LogLevel $logLevel): void
{ {
$this->log_level = $log_level; $this->logLevel = $logLevel;
}
/**
* Checks if file logging is enabled.
*
* @return bool True if file logging is enabled, false otherwise.
*/
public function isFileLoggingEnabled(): bool
{
return $this->fileLoggingEnabled;
}
/**
* Enables or disables file logging.
*
* @param bool $fileLoggingEnabled Indicates whether file logging should be enabled.
* @return void
*/
public function setFileLoggingEnabled(bool $fileLoggingEnabled): void
{
$this->fileLoggingEnabled = $fileLoggingEnabled;
}
/**
* Gets the current file logging level.
*
* @return LogLevel The file logging level.
*/
public function getFileLoggingLevel(): LogLevel
{
return $this->fileLoggingLevel;
}
/**
* Set the logging level for file output.
*
* @param LogLevel $fileLoggingLevel The logging level to be used for file output.
* @return void
*/
public function setFileLoggingLevel(LogLevel $fileLoggingLevel): void
{
$this->fileLoggingLevel = $fileLoggingLevel;
} }
} }

View file

@ -1,10 +1,9 @@
<?php <?php
use LogLib\Abstracts\LevelType; use LogLib\Log;
use LogLib\Log; use LogLib\Objects\Options;
use LogLib\Objects\Options;
require('ncc'); require('ncc');
import('net.nosial.loglib', 'latest'); import('net.nosial.loglib', 'latest');
$options = new Options('net.nosial.optslib'); $options = new Options('net.nosial.optslib');