';
+ $html .= sprintf('
Timestamp: %s
', $timestampType->format($event->getTimestamp()));
+ $html .= sprintf('
Level: %s
', $event->getLevel()->value);
+ $html .= sprintf('
Message: %s
', htmlspecialchars($event->getMessage(), ENT_QUOTES, 'UTF-8'));
+
+ if($traceType !== TraceFormat::NONE && $event->getFirstTrace() !== null)
+ {
+ $html .= sprintf('
Backtrace: %s
', $traceType->format($event->getFirstTrace()));
+ }
+
+ if ($event->getException() !== null)
+ {
+ $html .= '
Exception Details:
';
+ $html .= self::exceptionToHtml($event->getException());
+ }
+
+ $html .= '
';
+ return $html;
+ }
+
+ /**
+ * Converts an exception to an HTML string.
+ *
+ * @param ExceptionDetails $exception The exception to convert.
+ * @return string The exception as an HTML string.
+ */
+ private static function exceptionToHtml(ExceptionDetails $exception): string
+ {
+ $html = '';
+ $html .= sprintf('
%s: %s (Code: %s)
',
+ htmlspecialchars($exception->getName(), ENT_QUOTES, 'UTF-8'),
+ htmlspecialchars($exception->getMessage(), ENT_QUOTES, 'UTF-8'),
+ $exception->getCode() !== null ? htmlspecialchars((string)$exception->getCode(), ENT_QUOTES, 'UTF-8') : 'N/A'
+ );
+
+ if ($exception->getFile() !== null)
+ {
+ $html .= sprintf('
File: %s
', htmlspecialchars($exception->getFile(), ENT_QUOTES, 'UTF-8'));
+ if ($exception->getLine() !== null)
+ {
+ $html .= sprintf('
Line: %d
', $exception->getLine());
+ }
+ }
+
+ if ($exception->getTrace() !== null)
+ {
+ $html .= '
Stack Trace:
';
+ foreach ($exception->getTrace() as $trace)
+ {
+ $html .= '- ';
+ $html .= self::traceToHtml($trace);
+ $html .= '
';
+ }
+ $html .= '
';
+ }
+
+ if ($exception->getPrevious() !== null)
+ {
+ $html .= '
Caused by:
';
+ $html .= self::exceptionToHtml($exception->getPrevious());
+ }
+
+ $html .= '
';
+ return $html;
+ }
+
+ /**
+ * Converts a stack trace to an HTML string.
+ *
+ * @param StackTrace $trace The stack trace to convert.
+ * @return string The stack trace as an HTML string.
+ */
+ private static function traceToHtml(StackTrace $trace): string
+ {
+ $output = '';
+
+ if ($trace->getFile() !== null)
+ {
+ $output .= sprintf('
File: %s
', htmlspecialchars($trace->getFile(), ENT_QUOTES, 'UTF-8'));
+ }
+
+ if ($trace->getLine() !== null)
+ {
+ $output .= sprintf('
Line: %d
', $trace->getLine());
+ }
+
+ if ($trace->getFunction() !== null)
+ {
+ $output .= sprintf('
Function: %s
', htmlspecialchars($trace->getFunction(), ENT_QUOTES, 'UTF-8'));
+ }
+
+ if ($trace->getClass() !== null)
+ {
+ $output .= sprintf('
Class: %s
', htmlspecialchars($trace->getClass(), ENT_QUOTES, 'UTF-8'));
+ }
+
+ if ($trace->getCallType() !== null)
+ {
+ $output .= sprintf('
Call Type: %s
', htmlspecialchars($trace->getCallType()->value, ENT_QUOTES, 'UTF-8'));
+ }
+
+ if ($trace->getArgs() !== null)
+ {
+ $output .= '
Arguments:
';
+ foreach ($trace->getArgs() as $arg)
+ {
+ $output .= sprintf('- %s
', htmlspecialchars(json_encode($arg, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), ENT_QUOTES, 'UTF-8'));
+ }
+
+ $output .= '
';
+ }
+
+ $output .= '
';
+ return $output;
+ }
+
+ /**
+ * Converts an exception to a string.
+ *
+ * @param ExceptionDetails $exception The exception to convert.
+ * @return string The exception as a string.
+ */
+ private static function exceptionToString(ExceptionDetails $exception): string
+ {
+ $output = sprintf("\n%s: %s (%s)", $exception->getName(), $exception->getMessage(), $exception->getCode() ?? 0);
+
+ if ($exception->getFile() !== null)
+ {
+ $output .= sprintf("\nFile: %s", $exception->getFile());
+
+ if ($exception->getLine() !== null)
+ {
+ $output .= sprintf(":%d", $exception->getLine());
+ }
+ }
+
+ if ($exception->getTrace() !== null)
+ {
+ $output .= "\n";
+ foreach ($exception->getTrace() as $trace)
+ {
+ $output .= sprintf(" %s\n", TraceFormat::FULL->format($trace));
+ }
+ }
+
+ if ($exception->getPrevious() !== null)
+ {
+ $output .= self::exceptionToString($exception->getPrevious());
+ }
+
+ return $output;
+ }
+ }
diff --git a/src/LogLib2/Enums/LogHandlers.php b/src/LogLib2/Enums/LogHandlers.php
new file mode 100644
index 0000000..444df4e
--- /dev/null
+++ b/src/LogLib2/Enums/LogHandlers.php
@@ -0,0 +1,12 @@
+ [self::DEBUG, self::VERBOSE, self::INFO, self::WARNING, self::ERROR, self::CRITICAL],
+ self::VERBOSE => [self::VERBOSE, self::INFO, self::WARNING, self::ERROR, self::CRITICAL],
+ self::INFO => [self::INFO, self::WARNING, self::ERROR, self::CRITICAL],
+ self::WARNING => [self::WARNING, self::ERROR, self::CRITICAL],
+ self::ERROR => [self::ERROR, self::CRITICAL],
+ self::CRITICAL => [self::CRITICAL],
+ };
+ }
+
+ /**
+ * Checks if the provided log level is allowed based on the current instance's levels.
+ *
+ * @param LogLevel $level The log level to check against the allowed levels.
+ * @return bool True if the log level is allowed, false otherwise.
+ */
+ public function levelAllowed(LogLevel $level): bool
+ {
+ return in_array($level, $this->getLevels());
+ }
+
+ /**
+ * Parses the given value and returns the corresponding log level.
+ *
+ * @param int|string $value The value to parse, which can be an integer or a string representation of the log level.
+ * @return LogLevel The log level matching the provided value, or the default log level if no match is found.
+ */
+ public static function parseFrom(int|string $value): LogLevel
+ {
+ if(is_string($value))
+ {
+ $value = strtolower($value);
+ }
+
+ return match($value)
+ {
+ 'debug', 'dbg', 'd', 0 => self::DEBUG,
+ 'verbose', 'verb', 'vrb', 'v', 1 => self::VERBOSE,
+ 'information', 'info', 'inf', 'i', 2 => self::INFO,
+ 'warning', 'warn', 'wrn', 'w', 3 => self::WARNING,
+ 'error', 'err', 'e', 4 => self::ERROR,
+ 'critical', 'crit', 'crt', 'c', 5 => self::CRITICAL,
+ default => self::INFO
+ };
+ }
+ }
diff --git a/src/LogLib2/Enums/TimestampFormat.php b/src/LogLib2/Enums/TimestampFormat.php
new file mode 100644
index 0000000..a54d09a
--- /dev/null
+++ b/src/LogLib2/Enums/TimestampFormat.php
@@ -0,0 +1,63 @@
+ '',
+ self::TIME_ONLY => 'H:i:s',
+ self::TIME_ONLY_MILLIS => 'H:i:s.u',
+ self::DATE_ONLY => 'Y-m-d',
+ self::DATE_TIME => 'Y-m-d H:i:s',
+ self::DATE_TIME_MILLIS => 'Y-m-d H:i:s.u',
+ self::UNIX_TIMESTAMP => 'U',
+ };
+
+ if($time === null)
+ {
+ $time = time();
+ }
+
+ return (new DateTime())->setTimestamp($time)->format($format);
+ }
+
+ /**
+ * Parses the input string into a TimestampFormat enum.
+ *
+ * @param string $input The input string to parse.
+ * @return TimestampFormat The parsed TimestampFormat enum.
+ */
+ public static function parseFrom(string $input): TimestampFormat
+ {
+ return match(strtolower($input))
+ {
+ 'none', '0' => TimestampFormat::NONE,
+ 'time_only_millis', '2' => TimestampFormat::TIME_ONLY_MILLIS,
+ 'date_only', '3' => TimestampFormat::DATE_ONLY,
+ 'date_time', '4' => TimestampFormat::DATE_TIME,
+ 'date_time_millis', '5' => TimestampFormat::DATE_TIME_MILLIS,
+ 'unix_timestamp', '6' => TimestampFormat::UNIX_TIMESTAMP,
+ default => TimestampFormat::TIME_ONLY,
+ };
+ }
+ }
diff --git a/src/LogLib2/Enums/TraceFormat.php b/src/LogLib2/Enums/TraceFormat.php
new file mode 100644
index 0000000..784d840
--- /dev/null
+++ b/src/LogLib2/Enums/TraceFormat.php
@@ -0,0 +1,138 @@
+ TraceFormat::NONE,
+ 'basic', '1' => TraceFormat::BASIC,
+ 'full', '2' => TraceFormat::FULL,
+ default => TraceFormat::BASIC,
+ };
+ }
+
+ /**
+ * Formats the stack trace as a basic string.
+ *
+ * @param StackTrace $stackTrace The stack trace to format.
+ * @return string The formatted stack trace.
+ */
+ private static function formatBasic(StackTrace $stackTrace): string
+ {
+ if($stackTrace->getFunction() === null)
+ {
+ if($stackTrace->getClass() !== null)
+ {
+ return $stackTrace->getClass();
+ }
+
+ if($stackTrace->getFile() !== null)
+ {
+ if($stackTrace->getLine() !== null)
+ {
+ return $stackTrace->getFile() . ':' . $stackTrace->getLine();
+ }
+ else
+ {
+ return $stackTrace->getFile();
+ }
+ }
+ }
+
+ if($stackTrace->getClass() !== null)
+ {
+ return $stackTrace->getClass() . ($stackTrace->getCallType()?->value ?? CallType::STATIC_CALL->value) . $stackTrace->getFunction();
+ }
+
+ if($stackTrace->getFile() !== null)
+ {
+ if($stackTrace->getLine() !== null)
+ {
+ return $stackTrace->getFile() . ':' . $stackTrace->getLine() . ' ' . ($stackTrace->getCallType()?->value ?? CallType::STATIC_CALL->value) . $stackTrace->getFunction();
+ }
+ else
+ {
+ return $stackTrace->getFile() . ' ' . ($stackTrace->getCallType()?->value ?? CallType::STATIC_CALL->value) . $stackTrace->getFunction();
+ }
+ }
+
+ return $stackTrace->getFunction();
+ }
+
+ /**
+ * Formats the stack trace as a full string.
+ *
+ * @param StackTrace $stackTrace The stack trace to format.
+ * @return string The formatted stack trace.
+ */
+ private static function formatFull(StackTrace $stackTrace): string
+ {
+ $output = '';
+
+ if($stackTrace->getClass() !== null)
+ {
+ $output .= $stackTrace->getClass();
+ }
+
+ if($stackTrace->getCallType() !== null)
+ {
+ $output .= $stackTrace->getCallType()->value;
+ }
+
+ if($stackTrace->getFunction() !== null)
+ {
+ $output .= $stackTrace->getFunction();
+ }
+
+ if($stackTrace->getFile() !== null)
+ {
+ $output .= ' (' . $stackTrace->getFile();
+
+ if($stackTrace->getLine() !== null)
+ {
+ $output .= ':' . $stackTrace->getLine();
+ }
+
+ $output .= ')';
+ }
+
+ return $output;
+ }
+ }
diff --git a/src/LogLib2/Exceptions/IOException.php b/src/LogLib2/Exceptions/IOException.php
new file mode 100644
index 0000000..c581ed9
--- /dev/null
+++ b/src/LogLib2/Exceptions/IOException.php
@@ -0,0 +1,16 @@
+application = new Application($application);
+ $this->application->setConsoleConfiguration(self::getDefaultConsoleConfiguration());
+ $this->application->setDescriptorConfiguration(self::getDefaultDescriptorConfiguration());
+ $this->application->setFileConfiguration(self::getDefaultFileConfiguration());
+ $this->application->setHttpConfiguration(self::getDefaultHttpConfiguration());
+ $this->application->setTcpConfiguration(self::getDefaultTcpConfiguration());
+ $this->application->setUdpConfiguration(self::getDefaultUdpConfiguration());
+ }
+
+ /**
+ * Retrieves the Application instance used by the Logger.
+ *
+ * @return Application The Application instance used by the Logger.
+ */
+ public function getApplication(): Application
+ {
+ return $this->application;
+ }
+
+ /**
+ * Retrieves the Application instance used by the Logger.
+ *
+ * @return Application The Application instance used by the Logger.
+ */
+ public function debug(string $message): void
+ {
+ $this->handleEvent($this->createEvent(LogLevel::DEBUG, $message));
+ }
+
+ /**
+ * Logs a verbose message with the provided message.
+ *
+ * @param string $message The message to log.
+ */
+ public function verbose(string $message): void
+ {
+ $this->handleEvent($this->createEvent(LogLevel::VERBOSE, $message));
+ }
+
+ /**
+ * Logs an informational message with the provided message.
+ *
+ * @param string $message The message to log.
+ */
+ public function info(string $message): void
+ {
+ $this->handleEvent($this->createEvent(LogLevel::INFO, $message));
+ }
+
+ /**
+ * Logs a warning message with the provided message.
+ *
+ * @param string $message The message to log.
+ */
+ public function warning(string $message, null|ExceptionDetails|Throwable $e=null): void
+ {
+ $this->handleEvent($this->createEvent(LogLevel::WARNING, $message, $e));
+ }
+
+ /**
+ * Logs an error message with the provided message.
+ *
+ * @param string $message The message to log.
+ */
+ public function error(string $message, null|ExceptionDetails|Throwable $e=null): void
+ {
+ $this->handleEvent($this->createEvent(LogLevel::ERROR, $message, $e));
+ }
+
+ /**
+ * Logs a critical message with the provided message.
+ *
+ * @param string $message The message to log.
+ */
+ public function critical(string $message, null|ExceptionDetails|Throwable $e=null): void
+ {
+ $this->handleEvent($this->createEvent(LogLevel::CRITICAL, $message, $e));
+ }
+
+ /**
+ * Logs an alert message with the provided message.
+ *
+ * @param string $message The message to log.
+ */
+ private function createEvent(LogLevel $level, string $message, null|ExceptionDetails|Throwable $e=null): Event
+ {
+ return new Event($this->application->getName(), $level, $message, Utilities::getBackTrace(Logger::getBacktraceLevel()), time(), $e);
+ }
+
+ /**
+ * Handles the provided event by passing it to the appropriate log handlers.
+ *
+ * @param Event $event The event to handle.
+ */
+ private function handleEvent(Event $event): void
+ {
+ // Return early if the given LogLevel not allowed to be processed with the application's given log level.
+ if(!Utilities::getEnvironmentLogLevel()->levelAllowed($event->getLevel()))
+ {
+ return;
+ }
+
+ // Handle the event with the appropriate log handlers.
+ if($this->application->getConsoleConfiguration()->isEnabled() && ConsoleHandler::isAvailable($this->application))
+ {
+ ConsoleHandler::handleEvent($this->application, $event);
+ }
+
+ if($this->application->getDescriptorConfiguration()->isEnabled() && DescriptorHandler::isAvailable($this->application))
+ {
+ DescriptorHandler::handleEvent($this->application, $event);
+ }
+
+ if($this->application->getFileConfiguration()->isEnabled() && FileHandler::isAvailable($this->application))
+ {
+ FileHandler::handleEvent($this->application, $event);
+ }
+
+ if($this->application->getHttpConfiguration()->isEnabled() && HttpHandler::isAvailable($this->application))
+ {
+ HttpHandler::handleEvent($this->application, $event);
+ }
+
+ if($this->application->getTcpConfiguration()->isEnabled() && TcpHandler::isAvailable($this->application))
+ {
+ TcpHandler::handleEvent($this->application, $event);
+ }
+
+ if($this->application->getUdpConfiguration()->isEnabled() && UdpHandler::isAvailable($this->application))
+ {
+ UdpHandler::handleEvent($this->application, $event);
+ }
+ }
+
+ /**
+ * Retrieves the availability of the log handlers.
+ *
+ * @return array The availability of the log handlers.
+ */
+ public function getAvailability(): array
+ {
+ return [
+ ConsoleHandler::class => ConsoleHandler::isAvailable($this->application),
+ DescriptorConfiguration::class => DescriptorHandler::isAvailable($this->application),
+ FileHandler::class => FileHandler::isAvailable($this->application),
+ HttpHandler::class => HttpHandler::isAvailable($this->application),
+ TcpHandler::class => TcpHandler::isAvailable($this->application),
+ UdpHandler::class => UdpHandler::isAvailable($this->application)
+ ];
+ }
+
+ /**
+ * Retrieves the default ConsoleConfiguration instance.
+ *
+ * @return ConsoleConfiguration The default ConsoleConfiguration instance.
+ */
+ public static function getDefaultConsoleConfiguration(): ConsoleConfiguration
+ {
+ if(self::$defaultConsoleConfiguration === null)
+ {
+ self::$defaultConsoleConfiguration = new ConsoleConfiguration();
+
+ // Apply environment variables to the default ConsoleConfiguration instance.
+ if(getenv('LOGLIB_CONSOLE_ENABLED') !== false)
+ {
+ self::$defaultConsoleConfiguration->setEnabled(filter_var(getenv('LOG_CONSOLE_ENABLED'), FILTER_VALIDATE_BOOLEAN));
+ }
+ if(getenv('LOGLIB_CONSOLE_DISPLAY_NAME') !== false)
+ {
+ self::$defaultConsoleConfiguration->setDisplayName(filter_var(getenv('LOG_CONSOLE_DISPLAY_NAME'), FILTER_VALIDATE_BOOLEAN));
+ }
+ if(getenv('LOGLIB_CONSOLE_DISPLAY_LEVEL') !== false)
+ {
+ self::$defaultConsoleConfiguration->setDisplayLevel(filter_var(getenv('LOG_CONSOLE_DISPLAY_LEVEL'), FILTER_VALIDATE_BOOLEAN));
+ }
+ if(getenv('LOGLIB_CONSOLE_ANSI_FORMAT') !== false)
+ {
+ self::$defaultConsoleConfiguration->setAnsiFormat(AnsiFormat::parseFrom(getenv('LOGLIB_CONSOLE_ANSI_FORMAT')));
+ }
+ if(getenv('LOGLIB_CONSOLE_TRACE_FORMAT') !== false)
+ {
+ self::$defaultConsoleConfiguration->setTraceFormat(TraceFormat::parseFrom(getenv('LOGLIB_CONSOLE_TRACE_FORMAT')));
+ }
+ if(getenv('LOGLIB_CONSOLE_TIMESTAMP_FORMAT') !== false)
+ {
+ self::$defaultConsoleConfiguration->setTimestampFormat(TimestampFormat::parseFrom(getenv('LOGLIB_CONSOLE_TIMESTAMP_FORMAT')));
+ }
+ }
+
+ return self::$defaultConsoleConfiguration;
+ }
+
+ /**
+ * Retrieves the default DescriptorConfiguration instance.
+ *
+ * @return DescriptorConfiguration The default DescriptorConfiguration instance.
+ */
+ public static function getDefaultDescriptorConfiguration(): DescriptorConfiguration
+ {
+ if(self::$defaultDescriptorConfiguration === null)
+ {
+ self::$defaultDescriptorConfiguration = new DescriptorConfiguration();
+
+ // Apply environment variables to the default DescriptorConfiguration instance.
+ if(getenv('LOGLIB_DESCRIPTOR_ENABLED') !== false)
+ {
+ self::$defaultDescriptorConfiguration->setEnabled(filter_var(getenv('LOGLIB_DESCRIPTOR_ENABLED'), FILTER_VALIDATE_BOOLEAN));
+ }
+
+ if(getenv('LOGLIB_DESCRIPTOR_PATH') !== false)
+ {
+ self::$defaultDescriptorConfiguration->setDescriptor(getenv('LOGLIB_DESCRIPTOR_PATH'));
+ }
+
+ if(getenv('LOGLIB_DESCRIPTOR_APPEND_NEWLINE') !== false)
+ {
+ self::$defaultDescriptorConfiguration->setAppendNewline(filter_var(getenv('LOGLIB_DESCRIPTOR_APPEND_NEWLINE'), FILTER_VALIDATE_BOOLEAN));
+ }
+
+ if(getenv('LOGLIB_DESCRIPTOR_LOG_FORMAT') !== false)
+ {
+ self::$defaultDescriptorConfiguration->setLogFormat(LogFormat::parseFrom(getenv('LOGLIB_DESCRIPTOR_LOG_FORMAT')));
+ }
+
+ if(getenv('LOGLIB_DESCRIPTOR_TIMESTAMP_FORMAT') !== false)
+ {
+ self::$defaultDescriptorConfiguration->setTimestampFormat(TimestampFormat::parseFrom(getenv('LOGLIB_DESCRIPTOR_TIMESTAMP_FORMAT')));
+ }
+
+ if(getenv('LOGLIB_DESCRIPTOR_TRACE_FORMAT') !== false)
+ {
+ self::$defaultDescriptorConfiguration->setTraceFormat(TraceFormat::parseFrom(getenv('LOGLIB_DESCRIPTOR_TRACE_FORMAT')));
+ }
+ }
+
+ return self::$defaultDescriptorConfiguration;
+ }
+
+ /**
+ * Retrieves the default FileConfiguration instance.
+ *
+ * @return FileConfiguration The default FileConfiguration instance.
+ */
+ public static function getDefaultFileConfiguration(): FileConfiguration
+ {
+ if(self::$defaultFileConfiguration === null)
+ {
+ self::$defaultFileConfiguration = new FileConfiguration();
+
+ // Apply environment variables to the default FileConfiguration instance.
+ if(getenv('LOGLIB_FILE_ENABLED') !== false)
+ {
+ self::$defaultFileConfiguration->setEnabled(filter_var(getenv('LOGLIB_FILE_ENABLED'), FILTER_VALIDATE_BOOLEAN));
+ }
+
+ if(getenv('LOGLIB_FILE_DEFAULT_PERMISSIONS') !== false)
+ {
+ $permissions = octdec(filter_var(getenv('LOGLIB_FILE_DEFAULT_PERMISSIONS'), FILTER_VALIDATE_INT));
+ if($permissions !== false)
+ {
+ self::$defaultFileConfiguration->setDefaultPermissions($permissions);
+ }
+ }
+
+ if(getenv('LOGLIB_FILE_PATH') !== false)
+ {
+ // Parse magic constants in the file path.
+ $path = getenv('LOGLIB_FILE_PATH');
+ $path = str_ireplace('%CWD%', getcwd(), $path);
+ $path = str_ireplace('%HOME%', getenv('HOME') ?? sys_get_temp_dir(), $path);
+ $path = str_ireplace('%TMP%', sys_get_temp_dir(), $path);
+ $path = str_ireplace('%TEMP%', sys_get_temp_dir(), $path);
+
+ if(!is_dir($path))
+ {
+ @mkdir($path, self::$defaultFileConfiguration->getDefaultPermissions(), true);
+ }
+
+ self::$defaultFileConfiguration->setLogPath($path);
+ }
+
+ if(getenv('LOGLIB_FILE_APPEND_NEWLINE') !== false)
+ {
+ self::$defaultFileConfiguration->setAppendNewline(filter_var(getenv('LOGLIB_FILE_APPEND_NEWLINE'), FILTER_VALIDATE_BOOLEAN));
+ }
+
+ if(getenv('LOGLIB_FILE_LOG_FORMAT') !== false)
+ {
+ self::$defaultFileConfiguration->setLogFormat(LogFormat::parseFrom(getenv('LOGLIB_FILE_LOG_FORMAT')));
+ }
+
+ if(getenv('LOGLIB_FILE_TIMESTAMP_FORMAT') !== false)
+ {
+ self::$defaultFileConfiguration->setTimestampFormat(TimestampFormat::parseFrom(getenv('LOGLIB_FILE_TIMESTAMP_FORMAT')));
+ }
+
+ if(getenv('LOGLIB_FILE_TRACE_FORMAT') !== false)
+ {
+ self::$defaultFileConfiguration->setTraceFormat(TraceFormat::parseFrom(getenv('LOGLIB_FILE_TRACE_FORMAT')));
+ }
+ }
+
+ return self::$defaultFileConfiguration;
+ }
+
+ /**
+ * Retrieves the default HttpConfiguration instance.
+ *
+ * @return HttpConfiguration The default HttpConfiguration instance.
+ */
+ public static function getDefaultHttpConfiguration(): HttpConfiguration
+ {
+ if(self::$defaultHttpConfiguration === null)
+ {
+ self::$defaultHttpConfiguration = new HttpConfiguration();
+
+ // Apply environment variables to the default HttpConfiguration instance.
+ if(getenv('LOGLIB_HTTP_ENABLED') !== false)
+ {
+ self::$defaultHttpConfiguration->setEnabled(filter_var(getenv('LOGLIB_HTTP_ENABLED'), FILTER_VALIDATE_BOOLEAN));
+ }
+
+ if(getenv('LOGLIB_HTTP_ENDPOINT') !== false)
+ {
+ self::$defaultHttpConfiguration->setEndpoint(getenv('LOGLIB_HTTP_ENDPOINT'));
+ }
+
+ if(getenv('LOGLIB_HTTP_LOG_FORMAT') !== false)
+ {
+ self::$defaultHttpConfiguration->setLogFormat(LogFormat::parseFrom(getenv('LOGLIB_HTTP_LOG_FORMAT')));
+ }
+
+ if(getenv('LOGLIB_HTTP_TIMESTAMP_FORMAT') !== false)
+ {
+ self::$defaultHttpConfiguration->setTimestampFormat(TimestampFormat::parseFrom(getenv('LOGLIB_HTTP_TIMESTAMP_FORMAT')));
+ }
+
+ if(getenv('LOGLIB_HTTP_TRACE_FORMAT') !== false)
+ {
+ self::$defaultHttpConfiguration->setTraceFormat(TraceFormat::parseFrom(getenv('LOGLIB_HTTP_TRACE_FORMAT')));
+ }
+ }
+
+ return self::$defaultHttpConfiguration;
+ }
+
+ /**
+ * Retrieves the default TcpConfiguration instance.
+ *
+ * @return TcpConfiguration The default TcpConfiguration instance.
+ */
+ public static function getDefaultTcpConfiguration(): TcpConfiguration
+ {
+ if(self::$defaultTcpConfiguration === null)
+ {
+ self::$defaultTcpConfiguration = new TcpConfiguration();
+
+ // Apply environment variables to the default TcpConfiguration instance.
+ if(getenv('LOGLIB_TCP_ENABLED') !== false)
+ {
+ self::$defaultTcpConfiguration->setEnabled(filter_var(getenv('LOGLIB_TCP_ENABLED'), FILTER_VALIDATE_BOOLEAN));
+ }
+
+ if(getenv('LOGLIB_TCP_HOST') !== false)
+ {
+ self::$defaultTcpConfiguration->setHost(getenv('LOGLIB_TCP_HOST'));
+ }
+
+ if(getenv('LOGLIB_TCP_PORT') !== false)
+ {
+ self::$defaultTcpConfiguration->setPort((int)getenv('LOGLIB_TCP_PORT'));
+ }
+
+ if(getenv('LOGLIB_TCP_APPEND_NEWLINE') !== false)
+ {
+ self::$defaultTcpConfiguration->setAppendNewline(filter_var(getenv('LOGLIB_TCP_APPEND_NEWLINE'), FILTER_VALIDATE_BOOLEAN));
+ }
+
+ if(getenv('LOGLIB_TCP_LOG_FORMAT') !== false)
+ {
+ self::$defaultTcpConfiguration->setLogFormat(LogFormat::parseFrom(getenv('LOGLIB_TCP_LOG_FORMAT')));
+ }
+
+ if(getenv('LOGLIB_TCP_TIMESTAMP_FORMAT') !== false)
+ {
+ self::$defaultTcpConfiguration->setTimestampFormat(TimestampFormat::parseFrom(getenv('LOGLIB_TCP_TIMESTAMP_FORMAT')));
+ }
+ }
+
+ return self::$defaultTcpConfiguration;
+ }
+
+ /**
+ * Retrieves the default UdpConfiguration instance.
+ *
+ * @return UdpConfiguration The default UdpConfiguration instance.
+ */
+ public static function getDefaultUdpConfiguration(): UdpConfiguration
+ {
+ if(self::$defaultUdpConfiguration === null)
+ {
+ self::$defaultUdpConfiguration = new UdpConfiguration();
+
+ // Apply environment variables to the default UdpConfiguration instance.
+ if(getenv('LOGLIB_UDP_ENABLED') !== false)
+ {
+ self::$defaultUdpConfiguration->setEnabled(filter_var(getenv('LOGLIB_UDP_ENABLED'), FILTER_VALIDATE_BOOLEAN));
+ }
+
+ if(getenv('LOGLIB_UDP_HOST') !== false)
+ {
+ self::$defaultUdpConfiguration->setHost(getenv('LOGLIB_UDP_HOST'));
+ }
+
+ if(getenv('LOGLIB_UDP_PORT') !== false)
+ {
+ self::$defaultUdpConfiguration->setPort((int)getenv('LOGLIB_UDP_PORT'));
+ }
+
+ if(getenv('LOGLIB_UDP_APPEND_NEWLINE') !== false)
+ {
+ self::$defaultUdpConfiguration->setAppendNewline(filter_var(getenv('LOGLIB_UDP_APPEND_NEWLINE'), FILTER_VALIDATE_BOOLEAN));
+ }
+
+ if(getenv('LOGLIB_UDP_LOG_FORMAT') !== false)
+ {
+ self::$defaultUdpConfiguration->setLogFormat(LogFormat::parseFrom(getenv('LOGLIB_UDP_LOG_FORMAT')));
+ }
+
+ if(getenv('LOGLIB_UDP_TIMESTAMP_FORMAT') !== false)
+ {
+ self::$defaultUdpConfiguration->setTimestampFormat(TimestampFormat::parseFrom(getenv('LOGLIB_UDP_TIMESTAMP_FORMAT')));
+ }
+
+ if(getenv('LOGLIB_UDP_TRACE_FORMAT') !== false)
+ {
+ self::$defaultUdpConfiguration->setTraceFormat(TraceFormat::parseFrom(getenv('LOGLIB_UDP_TRACE_FORMAT')));
+ }
+ }
+
+ return self::$defaultUdpConfiguration;
+ }
+
+ /**
+ * Retrieves the backtrace level.
+ *
+ * @return int The backtrace level.
+ */
+ public static function getBacktraceLevel(): int
+ {
+ return self::$backtraceLevel;
+ }
+
+ /**
+ * Sets the backtrace level.
+ *
+ * @param int $backtraceLevel The backtrace level.
+ */
+ public static function setBacktraceLevel(int $backtraceLevel): void
+ {
+ self::$backtraceLevel = $backtraceLevel;
+ }
+
+ /**
+ * Retrieves the runtime logger instance.
+ *
+ * @return Logger The runtime logger instance.
+ */
+ public static function getRuntimeLogger(): Logger
+ {
+ if(self::$runtimeLogger === null)
+ {
+ self::$runtimeLogger = new Logger('Runtime');
+ }
+
+ return self::$runtimeLogger;
+ }
+
+ /**
+ * Registers the log handlers.
+ */
+ public static function registerHandlers(): void
+ {
+ if(self::$handlersRegistered)
+ {
+ return;
+ }
+
+ $logger = self::getRuntimeLogger();
+
+ // Register to catch all PHP errors & warnings.
+ set_error_handler(function($errno, $errstr, $errfile, $errline) use ($logger)
+ {
+ switch($errno)
+ {
+ case E_ERROR:
+ case E_CORE_ERROR:
+ case E_COMPILE_ERROR:
+ case E_USER_ERROR:
+ case E_RECOVERABLE_ERROR:
+ case E_CORE_WARNING:
+ case E_COMPILE_WARNING:
+ case E_PARSE:
+ $logger->critical($errstr, Utilities::detailsFromError($errno, $errstr, $errfile, $errline));
+ break;
+
+ case E_WARNING:
+ case E_USER_WARNING:
+ case E_DEPRECATED:
+ case E_USER_DEPRECATED:
+ case E_NOTICE:
+ case E_USER_NOTICE:
+ case E_STRICT:
+ $logger->warning($errstr, Utilities::detailsFromError($errno, $errstr, $errfile, $errline));
+ break;
+
+ default:
+ $logger->error($errstr, Utilities::detailsFromError($errno, $errstr, $errfile, $errline));
+ break;
+ }
+ });
+
+ // Register to catch all uncaught exceptions.
+ set_exception_handler(function(Throwable $e) use ($logger)
+ {
+ $logger->error($e->getMessage(), $e);
+ });
+
+ // Register to catch fatal errors.
+ register_shutdown_function(function() use ($logger)
+ {
+ $error = error_get_last();
+
+ if($error !== null)
+ {
+ $logger->critical($error['message'], Utilities::detailsFromError($error['type'], $error['message'], $error['file'], $error['line']));
+ }
+ });
+
+ self::$handlersRegistered = true;
+ }
+
+ /**
+ * Unregisters the log handlers.
+ */
+ public static function unregisterHandlers(): void
+ {
+ if(!self::$handlersRegistered)
+ {
+ return;
+ }
+
+ restore_error_handler();
+ restore_exception_handler();
+ self::$handlersRegistered = false;
+ }
+
+ /**
+ * Retrieves the registration status of the log handlers.
+ *
+ * @return bool Returns true if the log handlers are registered, false otherwise.
+ */
+ public static function isHandlersRegistered(): bool
+ {
+ return self::$handlersRegistered;
+ }
+ }
\ No newline at end of file
diff --git a/src/LogLib2/Objects/Application.php b/src/LogLib2/Objects/Application.php
new file mode 100644
index 0000000..4d55447
--- /dev/null
+++ b/src/LogLib2/Objects/Application.php
@@ -0,0 +1,189 @@
+name = $name;
+ $this->consoleConfiguration = new ConsoleConfiguration();
+ $this->descriptorConfiguration = new DescriptorConfiguration();
+ $this->fileConfiguration = new FileConfiguration();
+ $this->httpConfiguration = new HttpConfiguration();
+ $this->tcpConfiguration = new TcpConfiguration();
+ $this->udpConfiguration = new UdpConfiguration();
+ }
+
+ /**
+ * Retrieves the name of the application.
+ *
+ * @return string The name of the application.
+ */
+ public function getName(): string
+ {
+ return $this->name;
+ }
+
+ /**
+ * Retrieves the ConsoleConfiguration instance for the application.
+ *
+ * @return ConsoleConfiguration The ConsoleConfiguration instance for the application.
+ */
+ public function getConsoleConfiguration(): ConsoleConfiguration
+ {
+ return $this->consoleConfiguration;
+ }
+
+ /**
+ * Sets the ConsoleConfiguration instance for the application.
+ *
+ * @param ConsoleConfiguration $configuration The ConsoleConfiguration instance for the application.
+ * @return Application Returns the current instance for method chaining.
+ */
+ public function setConsoleConfiguration(ConsoleConfiguration $configuration): Application
+ {
+ $this->consoleConfiguration = $configuration;
+ return $this;
+ }
+
+ /**
+ * Retrieves the DescriptorConfiguration instance for the application.
+ *
+ * @return DescriptorConfiguration The DescriptorConfiguration instance for the application.
+ */
+ public function getDescriptorConfiguration(): DescriptorConfiguration
+ {
+ return $this->descriptorConfiguration;
+ }
+
+ /**
+ * Sets the DescriptorConfiguration instance for the application.
+ *
+ * @param DescriptorConfiguration $configuration The DescriptorConfiguration instance for the application.
+ * @return Application Returns the current instance for method chaining.
+ */
+ public function setDescriptorConfiguration(DescriptorConfiguration $configuration): Application
+ {
+ $this->descriptorConfiguration = $configuration;
+ return $this;
+ }
+
+ /**
+ * Retrieves the FileConfiguration instance for the application.
+ *
+ * @return FileConfiguration The FileConfiguration instance for the application.
+ */
+ public function getFileConfiguration(): FileConfiguration
+ {
+ return $this->fileConfiguration;
+ }
+
+ /**
+ * Sets the FileConfiguration instance for the application.
+ *
+ * @param FileConfiguration $configuration The FileConfiguration instance for the application.
+ * @return Application Returns the current instance for method chaining.
+ */
+ public function setFileConfiguration(FileConfiguration $configuration): Application
+ {
+ $this->fileConfiguration = $configuration;
+ return $this;
+ }
+
+ /**
+ * Retrieves the HttpConfiguration instance for the application.
+ *
+ * @return HttpConfiguration The HttpConfiguration instance for the application.
+ */
+ public function getHttpConfiguration(): HttpConfiguration
+ {
+ return $this->httpConfiguration;
+ }
+
+ /**
+ * Sets the HttpConfiguration instance for the application.
+ *
+ * @param HttpConfiguration $configuration The HttpConfiguration instance for the application.
+ * @return Application Returns the current instance for method chaining.
+ */
+ public function setHttpConfiguration(HttpConfiguration $configuration): Application
+ {
+ $this->httpConfiguration = $configuration;
+ return $this;
+ }
+
+ /**
+ * Retrieves the TcpConfiguration instance for the application.
+ *
+ * @return TcpConfiguration The TcpConfiguration instance for the application.
+ */
+ public function getTcpConfiguration(): TcpConfiguration
+ {
+ return $this->tcpConfiguration;
+ }
+
+ /**
+ * Sets the TcpConfiguration instance for the application.
+ *
+ * @param TcpConfiguration $configuration The TcpConfiguration instance for the application.
+ * @return Application Returns the current instance for method chaining.
+ */
+ public function setTcpConfiguration(TcpConfiguration $configuration): Application
+ {
+ $this->tcpConfiguration = $configuration;
+ return $this;
+ }
+
+ /**
+ * Retrieves the UdpConfiguration instance for the application.
+ *
+ * @return UdpConfiguration The UdpConfiguration instance for the application.
+ */
+ public function getUdpConfiguration(): UdpConfiguration
+ {
+ return $this->udpConfiguration;
+ }
+
+ /**
+ * Sets the UdpConfiguration instance for the application.
+ *
+ * @param UdpConfiguration $configuration The UdpConfiguration instance for the application.
+ * @return Application Returns the current instance for method chaining.
+ */
+ public function setUdpConfiguration(UdpConfiguration $configuration): Application
+ {
+ $this->udpConfiguration = $configuration;
+ return $this;
+ }
+
+ /**
+ * Retrieves the string representation of the application.
+ *
+ * @return string The string representation of the application.
+ */
+ public function __toString(): string
+ {
+ return $this->name;
+ }
+ }
\ No newline at end of file
diff --git a/src/LogLib2/Objects/Configurations/ConsoleConfiguration.php b/src/LogLib2/Objects/Configurations/ConsoleConfiguration.php
new file mode 100644
index 0000000..86edc5a
--- /dev/null
+++ b/src/LogLib2/Objects/Configurations/ConsoleConfiguration.php
@@ -0,0 +1,162 @@
+enabled = true;
+ $this->displayName = true;
+ $this->displayLevel = true;
+ $this->ansiFormat = AnsiFormat::BASIC;
+ $this->traceFormat = TraceFormat::BASIC;
+ $this->timestampFormat = TimestampFormat::TIME_ONLY;
+ }
+
+ /**
+ * Retrieves the enabled status of the console configuration.
+ *
+ * @return bool Returns true if the console configuration is enabled, false otherwise.
+ */
+ public function isEnabled(): bool
+ {
+ return $this->enabled;
+ }
+
+ /**
+ * Sets the enabled status of the console configuration.
+ *
+ * @param bool $enabled The enabled status to set.
+ * @return ConsoleConfiguration Returns the current instance.
+ */
+ public function setEnabled(bool $enabled): ConsoleConfiguration
+ {
+ $this->enabled = $enabled;
+ return $this;
+ }
+
+ /**
+ * Retrieves the display name status of the console configuration.
+ *
+ * @return bool Returns true if the display name is enabled, false otherwise.
+ */
+ public function isDisplayName(): bool
+ {
+ return $this->displayName;
+ }
+
+ /**
+ * Sets the display name status of the console configuration.
+ *
+ * @param bool $displayName The display name status to set.
+ * @return ConsoleConfiguration Returns the current instance.
+ */
+ public function setDisplayName(bool $displayName): ConsoleConfiguration
+ {
+ $this->displayName = $displayName;
+ return $this;
+ }
+
+ /**
+ * Retrieves the display level status of the console configuration.
+ *
+ * @return bool Returns true if the display level is enabled, false otherwise.
+ */
+ public function isDisplayLevel(): bool
+ {
+ return $this->displayLevel;
+ }
+
+ /**
+ * Sets the display level status of the console configuration.
+ *
+ * @param bool $displayLevel The display level status to set.
+ * @return ConsoleConfiguration Returns the current instance.
+ */
+ public function setDisplayLevel(bool $displayLevel): ConsoleConfiguration
+ {
+ $this->displayLevel = $displayLevel;
+ return $this;
+ }
+
+ /**
+ * Retrieves the ANSI format of the console configuration.
+ *
+ * @return AnsiFormat Returns the ANSI format as an AnsiForamt.
+ */
+ public function getAnsiFormat(): AnsiFormat
+ {
+ return $this->ansiFormat;
+ }
+
+ /**
+ * Sets the ANSI format of the console configuration.
+ *
+ * @param AnsiFormat $ansiFormat The ANSI format to set.
+ * @return ConsoleConfiguration Returns the current instance.
+ */
+ public function setAnsiFormat(AnsiFormat $ansiFormat): ConsoleConfiguration
+ {
+ $this->ansiFormat = $ansiFormat;
+ return $this;
+ }
+
+ /**
+ * Retrieves the trace format of the console configuration.
+ *
+ * @return TraceFormat Returns the trace format as a TraceFormat.
+ */
+ public function getTraceFormat(): TraceFormat
+ {
+ return $this->traceFormat;
+ }
+
+ /**
+ * Sets the trace format of the console configuration.
+ *
+ * @param TraceFormat $traceFormat The trace format to set.
+ * @return ConsoleConfiguration Returns the current instance.
+ */
+ public function setTraceFormat(TraceFormat $traceFormat): ConsoleConfiguration
+ {
+ $this->traceFormat = $traceFormat;
+ return $this;
+ }
+
+ /**
+ * Retrieves the timestamp format of the console configuration.
+ *
+ * @return TimestampFormat Returns the timestamp format as a TimestampFormat.
+ */
+ public function getTimestampFormat(): TimestampFormat
+ {
+ return $this->timestampFormat;
+ }
+
+ /**
+ * Sets the timestamp format of the console configuration.
+ *
+ * @param TimestampFormat $timestampFormat The timestamp format to set.
+ * @return ConsoleConfiguration Returns the current instance.
+ */
+ public function setTimestampFormat(TimestampFormat $timestampFormat): ConsoleConfiguration
+ {
+ $this->timestampFormat = $timestampFormat;
+ return $this;
+ }
+ }
\ No newline at end of file
diff --git a/src/LogLib2/Objects/Configurations/DescriptorConfiguration.php b/src/LogLib2/Objects/Configurations/DescriptorConfiguration.php
new file mode 100644
index 0000000..c863988
--- /dev/null
+++ b/src/LogLib2/Objects/Configurations/DescriptorConfiguration.php
@@ -0,0 +1,162 @@
+enabled = false;
+ $this->descriptor = DIRECTORY_SEPARATOR . 'dev' . DIRECTORY_SEPARATOR . 'null';
+ $this->appendNewline = false;
+ $this->logFormat = LogFormat::JSONL;
+ $this->timestampFormat = TimestampFormat::UNIX_TIMESTAMP;
+ $this->traceFormat = TraceFormat::FULL;
+ }
+
+ /**
+ * Retrieves the enabled status of the descriptor configuration.
+ *
+ * @return bool Returns true if the descriptor configuration is enabled, false otherwise.
+ */
+ public function isEnabled(): bool
+ {
+ return $this->enabled;
+ }
+
+ /**
+ * Sets the enabled status of the descriptor configuration.
+ *
+ * @param bool $enabled The enabled status to set.
+ * @return DescriptorConfiguration Returns the current instance.
+ */
+ public function setEnabled(bool $enabled): DescriptorConfiguration
+ {
+ $this->enabled = $enabled;
+ return $this;
+ }
+
+ /**
+ * Retrieves the descriptor of the descriptor configuration.
+ *
+ * @return string Returns the descriptor as a string.
+ */
+ public function getDescriptor(): string
+ {
+ return $this->descriptor;
+ }
+
+ /**
+ * Sets the descriptor of the descriptor configuration.
+ *
+ * @param string $descriptor The descriptor to set.
+ * @return DescriptorConfiguration Returns the current instance.
+ */
+ public function setDescriptor(string $descriptor): DescriptorConfiguration
+ {
+ $this->descriptor = $descriptor;
+ return $this;
+ }
+
+ /**
+ * Retrieves the append newline status of the descriptor configuration.
+ *
+ * @return bool Returns true if the descriptor configuration appends a newline, false otherwise.
+ */
+ public function isAppendNewline(): bool
+ {
+ return $this->appendNewline;
+ }
+
+ /**
+ * Sets the append newline status of the descriptor configuration.
+ *
+ * @param bool $appendNewline The append newline status to set.
+ * @return DescriptorConfiguration Returns the current instance.
+ */
+ public function setAppendNewline(bool $appendNewline): DescriptorConfiguration
+ {
+ $this->appendNewline = $appendNewline;
+ return $this;
+ }
+
+ /**
+ * Retrieves the log type of the descriptor configuration.
+ *
+ * @return LogFormat Returns the log type.
+ */
+ public function getLogFormat(): LogFormat
+ {
+ return $this->logFormat;
+ }
+
+ /**
+ * Sets the log type of the descriptor configuration.
+ *
+ * @param LogFormat $logFormat The log type to set.
+ * @return DescriptorConfiguration Returns the current instance.
+ */
+ public function setLogFormat(LogFormat $logFormat): DescriptorConfiguration
+ {
+ $this->logFormat = $logFormat;
+ return $this;
+ }
+
+ /**
+ * Retrieves the timestamp type of the descriptor configuration.
+ *
+ * @return TimestampFormat Returns the timestamp type.
+ */
+ public function getTimestampFormat(): TimestampFormat
+ {
+ return $this->timestampFormat;
+ }
+
+ /**
+ * Sets the timestamp type of the descriptor configuration.
+ *
+ * @param TimestampFormat $timestampFormat The timestamp type to set.
+ * @return DescriptorConfiguration Returns the current instance.
+ */
+ public function setTimestampFormat(TimestampFormat $timestampFormat): DescriptorConfiguration
+ {
+ $this->timestampFormat = $timestampFormat;
+ return $this;
+ }
+
+ /**
+ * Retrieves the trace format of the descriptor configuration.
+ *
+ * @return TraceFormat Returns the trace format.
+ */
+ public function getTraceFormat(): TraceFormat
+ {
+ return $this->traceFormat;
+ }
+
+ /**
+ * Sets the trace format of the descriptor configuration.
+ *
+ * @param TraceFormat $traceFormat The trace format to set.
+ * @return DescriptorConfiguration Returns the current instance.
+ */
+ public function setTraceFormat(TraceFormat $traceFormat): DescriptorConfiguration
+ {
+ $this->traceFormat = $traceFormat;
+ return $this;
+ }
+ }
\ No newline at end of file
diff --git a/src/LogLib2/Objects/Configurations/FileConfiguration.php b/src/LogLib2/Objects/Configurations/FileConfiguration.php
new file mode 100644
index 0000000..13d97c5
--- /dev/null
+++ b/src/LogLib2/Objects/Configurations/FileConfiguration.php
@@ -0,0 +1,210 @@
+enabled = true;
+ $this->logPath = Utilities::getEnvironmentLogPath();
+ $this->defaultPermissions = 0777;
+ $this->appendNewline = true;
+ $this->logFormat = LogFormat::TXT;
+ $this->timestampFormat = TimestampFormat::TIME_ONLY;
+ $this->traceFormat = TraceFormat::BASIC;
+ }
+
+ /**
+ * Retrieves the enabled status of the file configuration.
+ *
+ * @return bool Returns true if the file configuration is enabled, false otherwise.
+ */
+ public function isEnabled(): bool
+ {
+ return $this->enabled;
+ }
+
+ /**
+ * Sets the enabled status of the file configuration.
+ *
+ * @param bool $enabled The enabled status to set.
+ * @return FileConfiguration Returns the current instance.
+ */
+ public function setEnabled(bool $enabled): FileConfiguration
+ {
+ $this->enabled = $enabled;
+ return $this;
+ }
+
+ /**
+ * Retrieves the log level of the file configuration.
+ *
+ * @return LogLevel Returns the log level as a LogLevel.
+ */
+ public function getLogLevel(): LogLevel
+ {
+ return $this->logLevel;
+ }
+
+ /**
+ * Sets the log level of the file configuration.
+ *
+ * @param LogLevel $logLevel The log level to set.
+ * @return FileConfiguration Returns the current instance.
+ */
+ public function setLogLevel(LogLevel $logLevel): FileConfiguration
+ {
+ $this->logLevel = $logLevel;
+ return $this;
+ }
+
+ /**
+ * Retrieves the log path of the file configuration.
+ *
+ * @return string Returns the log path as a string.
+ */
+ public function getLogPath(): string
+ {
+ return $this->logPath;
+ }
+
+ /**
+ * Sets the log path of the file configuration.
+ *
+ * @param string $logPath The log path to set.
+ * @return FileConfiguration Returns the current instance.
+ */
+ public function setLogPath(string $logPath): FileConfiguration
+ {
+ $this->logPath = $logPath;
+ return $this;
+ }
+
+ /**
+ * Retrieves the default permissions of the file configuration.
+ *
+ * @return int Returns the default permissions as an integer.
+ */
+ public function getDefaultPermissions(): int
+ {
+ return $this->defaultPermissions;
+ }
+
+ /**
+ * @param int $defaultPermissions
+ * @return FileConfiguration
+ */
+ public function setDefaultPermissions(int $defaultPermissions): FileConfiguration
+ {
+ $this->defaultPermissions = $defaultPermissions;
+ return $this;
+ }
+
+ /**
+ * Retrieves the append newline status of the file configuration.
+ *
+ * @return bool Returns true if the file configuration appends a newline, false otherwise.
+ */
+ public function isAppendNewline(): bool
+ {
+ return $this->appendNewline;
+ }
+
+ /**
+ * Sets the append newline status of the file configuration.
+ *
+ * @param bool $appendNewline The append newline status to set.
+ * @return FileConfiguration Returns the current instance.
+ */
+ public function setAppendNewline(bool $appendNewline): FileConfiguration
+ {
+ $this->appendNewline = $appendNewline;
+ return $this;
+ }
+
+ /**
+ * Retrieves the log type of the file configuration.
+ *
+ * @return LogFormat Returns the log type.
+ */
+ public function getLogFormat(): LogFormat
+ {
+ return $this->logFormat;
+ }
+
+ /**
+ * Sets the log type of the file configuration.
+ *
+ * @param LogFormat $logFormat The log type to set.
+ * @return FileConfiguration Returns the current instance.
+ */
+ public function setLogFormat(LogFormat $logFormat): FileConfiguration
+ {
+ $this->logFormat = $logFormat;
+ return $this;
+
+ }
+
+ /**
+ * Retrieves the timestamp format of the file configuration.
+ *
+ * @return TimestampFormat Returns the timestamp format as a TimestampFormat.
+ */
+ public function getTimestampFormat(): TimestampFormat
+ {
+ return $this->timestampFormat;
+ }
+
+ /**
+ * Sets the timestamp format of the file configuration.
+ *
+ * @param TimestampFormat $timestampFormat The timestamp format to set.
+ * @return FileConfiguration Returns the current instance.
+ */
+ public function setTimestampFormat(TimestampFormat $timestampFormat): FileConfiguration
+ {
+ $this->timestampFormat = $timestampFormat;
+ return $this;
+ }
+
+ /**
+ * Retrieves the trace format of the file configuration.
+ *
+ * @return TraceFormat Returns the trace format as a TraceFormat.
+ */
+ public function getTraceFormat(): TraceFormat
+ {
+ return $this->traceFormat;
+ }
+
+ /**
+ * Sets the trace format of the file configuration.
+ *
+ * @param TraceFormat $traceFormat The trace format to set.
+ * @return FileConfiguration Returns the current instance.
+ */
+ public function setTraceFormat(TraceFormat $traceFormat): FileConfiguration
+ {
+ $this->traceFormat = $traceFormat;
+ return $this;
+ }
+ }
\ No newline at end of file
diff --git a/src/LogLib2/Objects/Configurations/HttpConfiguration.php b/src/LogLib2/Objects/Configurations/HttpConfiguration.php
new file mode 100644
index 0000000..8a2afcd
--- /dev/null
+++ b/src/LogLib2/Objects/Configurations/HttpConfiguration.php
@@ -0,0 +1,162 @@
+enabled = false;
+ $this->endpoint = 'http://0.0.0.0:5131';
+ $this->appendNewline = false;
+ $this->logFormat = LogFormat::JSONL;
+ $this->timestampFormat = TimestampFormat::UNIX_TIMESTAMP;
+ $this->traceFormat = TraceFormat::FULL;
+ }
+
+ /**
+ * Retrieves the enabled status of the HTTP configuration.
+ *
+ * @return bool Returns true if the HTTP configuration is enabled, false otherwise.
+ */
+ public function isEnabled(): bool
+ {
+ return $this->enabled;
+ }
+
+ /**
+ * Sets the enabled status of the HTTP configuration.
+ *
+ * @param bool $enabled The enabled status to set.
+ * @return HttpConfiguration Returns the current instance.
+ */
+ public function setEnabled(bool $enabled): HttpConfiguration
+ {
+ $this->enabled = $enabled;
+ return $this;
+ }
+
+ /**
+ * Retrieves the endpoint of the HTTP configuration.
+ *
+ * @return string Returns the endpoint as a string.
+ */
+ public function getEndpoint(): string
+ {
+ return $this->endpoint;
+ }
+
+ /**
+ * Sets the endpoint of the HTTP configuration.
+ *
+ * @param string $endpoint The endpoint to set.
+ * @return HttpConfiguration Returns the current instance.
+ */
+ public function setEndpoint(string $endpoint): HttpConfiguration
+ {
+ $this->endpoint = $endpoint;
+ return $this;
+ }
+
+ /**
+ * Retrieves the append newline status of the HTTP configuration.
+ *
+ * @return bool Returns true if the HTTP configuration appends a newline, false otherwise.
+ */
+ public function isAppendNewline(): bool
+ {
+ return $this->appendNewline;
+ }
+
+ /**
+ * Sets the append newline status of the HTTP configuration.
+ *
+ * @param bool $appendNewline The append newline status to set.
+ * @return HttpConfiguration Returns the current instance.
+ */
+ public function setAppendNewline(bool $appendNewline): HttpConfiguration
+ {
+ $this->appendNewline = $appendNewline;
+ return $this;
+ }
+
+ /**
+ * Retrieves the log format of the HTTP configuration.
+ *
+ * @return LogFormat Returns the log format.
+ */
+ public function getLogFormat(): LogFormat
+ {
+ return $this->logFormat;
+ }
+
+ /**
+ * Sets the log format of the HTTP configuration.
+ *
+ * @param LogFormat $logFormat The log format to set.
+ * @return HttpConfiguration Returns the current instance.
+ */
+ public function setLogFormat(LogFormat $logFormat): HttpConfiguration
+ {
+ $this->logFormat = $logFormat;
+ return $this;
+ }
+
+ /**
+ * Retrieves the timestamp format of the HTTP configuration.
+ *
+ * @return TimestampFormat Returns the timestamp format.
+ */
+ public function getTimestampFormat(): TimestampFormat
+ {
+ return $this->timestampFormat;
+ }
+
+ /**
+ * Sets the timestamp format of the HTTP configuration.
+ *
+ * @param TimestampFormat $timestampFormat The timestamp format to set.
+ * @return HttpConfiguration Returns the current instance.
+ */
+ public function setTimestampFormat(TimestampFormat $timestampFormat): HttpConfiguration
+ {
+ $this->timestampFormat = $timestampFormat;
+ return $this;
+ }
+
+ /**
+ * Retrieves the trace format of the HTTP configuration.
+ *
+ * @return TraceFormat Returns the trace format.
+ */
+ public function getTraceFormat(): TraceFormat
+ {
+ return $this->traceFormat;
+ }
+
+ /**
+ * Sets the trace format of the HTTP configuration.
+ *
+ * @param TraceFormat $traceFormat The trace format to set.
+ * @return HttpConfiguration Returns the current instance.
+ */
+ public function setTraceFormat(TraceFormat $traceFormat): HttpConfiguration
+ {
+ $this->traceFormat = $traceFormat;
+ return $this;
+ }
+ }
\ No newline at end of file
diff --git a/src/LogLib2/Objects/Configurations/TcpConfiguration.php b/src/LogLib2/Objects/Configurations/TcpConfiguration.php
new file mode 100644
index 0000000..28ac5b1
--- /dev/null
+++ b/src/LogLib2/Objects/Configurations/TcpConfiguration.php
@@ -0,0 +1,174 @@
+enabled = false;
+ $this->host = '0.0.0.0';
+ $this->port = 5131;
+ $this->appendNewline = false;
+ $this->logFormat = LogFormat::JSONL;
+ $this->timestampFormat = TimestampFormat::UNIX_TIMESTAMP;
+ $this->traceFormat = TraceFormat::FULL;
+ }
+
+ /**
+ * Retrieves the enabled status of the TCP configuration.
+ *
+ * @return bool Returns true if the TCP configuration is enabled, false otherwise.
+ */
+ public function isEnabled(): bool
+ {
+ return $this->enabled;
+ }
+
+ /**
+ * Sets the enabled status of the TCP configuration.
+ *
+ * @param bool $enabled The enabled status to set.
+ * @return TcpConfiguration Returns the current instance.
+ */
+ public function setEnabled(bool $enabled): TcpConfiguration
+ {
+ $this->enabled = $enabled;
+ return $this;
+ }
+
+ /**
+ * Retrieves the host of the TCP configuration.
+ *
+ * @return string Returns the host as a string.
+ */
+ public function getHost(): string
+ {
+ return $this->host;
+ }
+
+ /**
+ * Sets the host of the TCP configuration.
+ *
+ * @param string $host The host to set.
+ * @return TcpConfiguration Returns the current instance.
+ */
+ public function setHost(string $host): TcpConfiguration
+ {
+ $this->host = $host;
+ return $this;
+ }
+
+ /**
+ * Retrieves the port of the TCP configuration.
+ *
+ * @return int Returns the port as an integer.
+ */
+ public function getPort(): int
+ {
+ return $this->port;
+ }
+
+ /**
+ * Sets the port of the TCP configuration.
+ *
+ * @param int $port The port to set.
+ * @return TcpConfiguration Returns the current instance.
+ */
+ public function setPort(int $port): TcpConfiguration
+ {
+ $this->port = $port;
+ return $this;
+ }
+
+ /**
+ * Retrieves the append newline status of the TCP configuration.
+ *
+ * @return bool Returns true if the TCP configuration appends a newline, false otherwise.
+ */
+ public function isAppendNewline(): bool
+ {
+ return $this->appendNewline;
+ }
+
+ /**
+ * Sets the append newline status of the TCP configuration.
+ *
+ * @param bool $appendNewline The append newline status to set.
+ * @return TcpConfiguration Returns the current instance.
+ */
+ public function setAppendNewline(bool $appendNewline): TcpConfiguration
+ {
+ $this->appendNewline = $appendNewline;
+ return $this;
+ }
+
+ /**
+ * Retrieves the log format of the TCP configuration.
+ *
+ * @return LogFormat Returns the log format.
+ */
+ public function getLogFormat(): LogFormat
+ {
+ return $this->logFormat;
+ }
+
+ /**
+ * Sets the log format of the TCP configuration.
+ *
+ * @param LogFormat $logFormat The log format to set.
+ * @return TcpConfiguration Returns the current instance.
+ */
+ public function setLogFormat(LogFormat $logFormat): TcpConfiguration
+ {
+ $this->logFormat = $logFormat;
+ return $this;
+ }
+
+ /**
+ * Retrieves the timestamp format of the TCP configuration.
+ *
+ * @return TimestampFormat Returns the timestamp format.
+ */
+ public function getTimestampFormat(): TimestampFormat
+ {
+ return $this->timestampFormat;
+ }
+
+ /**
+ * Sets the timestamp format of the TCP configuration.
+ *
+ * @param TimestampFormat $timestampFormat The timestamp format to set.
+ * @return TcpConfiguration Returns the current instance.
+ */
+ public function setTimestampFormat(TimestampFormat $timestampFormat): TcpConfiguration
+ {
+ $this->timestampFormat = $timestampFormat;
+ return $this;
+ }
+
+ /**
+ * Retrieves the trace format of the TCP configuration.
+ *
+ * @return TraceFormat Returns the trace format.
+ */
+ public function getTraceFormat(): TraceFormat
+ {
+ return $this->traceFormat;
+ }
+ }
\ No newline at end of file
diff --git a/src/LogLib2/Objects/Configurations/UdpConfiguration.php b/src/LogLib2/Objects/Configurations/UdpConfiguration.php
new file mode 100644
index 0000000..d71ee0c
--- /dev/null
+++ b/src/LogLib2/Objects/Configurations/UdpConfiguration.php
@@ -0,0 +1,186 @@
+enabled = false;
+ $this->host = '0.0.0.0';
+ $this->port = 5131;
+ $this->appendNewline = false;
+ $this->logFormat = LogFormat::JSONL;
+ $this->timestampFormat = TimestampFormat::UNIX_TIMESTAMP;
+ $this->traceFormat = TraceFormat::FULL;
+ }
+
+ /**
+ * Retrieves the enabled status of the TCP configuration.
+ *
+ * @return bool Returns true if the TCP configuration is enabled, false otherwise.
+ */
+ public function isEnabled(): bool
+ {
+ return $this->enabled;
+ }
+
+ /**
+ * Sets the enabled status of the TCP configuration.
+ *
+ * @param bool $enabled The enabled status to set.
+ * @return UdpConfiguration Returns the current instance.
+ */
+ public function setEnabled(bool $enabled): UdpConfiguration
+ {
+ $this->enabled = $enabled;
+ return $this;
+ }
+
+ /**
+ * Retrieves the host of the TCP configuration.
+ *
+ * @return string Returns the host as a string.
+ */
+ public function getHost(): string
+ {
+ return $this->host;
+ }
+
+ /**
+ * Sets the host of the TCP configuration.
+ *
+ * @param string $host The host to set.
+ * @return UdpConfiguration Returns the current instance.
+ */
+ public function setHost(string $host): UdpConfiguration
+ {
+ $this->host = $host;
+ return $this;
+ }
+
+ /**
+ * Retrieves the port of the TCP configuration.
+ *
+ * @return int Returns the port as an integer.
+ */
+ public function getPort(): int
+ {
+ return $this->port;
+ }
+
+ /**
+ * Sets the port of the TCP configuration.
+ *
+ * @param int $port The port to set.
+ * @return UdpConfiguration Returns the current instance.
+ */
+ public function setPort(int $port): UdpConfiguration
+ {
+ $this->port = $port;
+ return $this;
+ }
+
+ /**
+ * Retrieves the append newline status of the TCP configuration.
+ *
+ * @return bool Returns true if the TCP configuration appends a newline, false otherwise.
+ */
+ public function isAppendNewline(): bool
+ {
+ return $this->appendNewline;
+ }
+
+ /**
+ * Sets the append newline status of the TCP configuration.
+ *
+ * @param bool $appendNewline The append newline status to set.
+ * @return UdpConfiguration Returns the current instance.
+ */
+ public function setAppendNewline(bool $appendNewline): UdpConfiguration
+ {
+ $this->appendNewline = $appendNewline;
+ return $this;
+ }
+
+ /**
+ * Retrieves the log format of the TCP configuration.
+ *
+ * @return LogFormat Returns the log format.
+ */
+ public function getLogFormat(): LogFormat
+ {
+ return $this->logFormat;
+ }
+
+ /**
+ * Sets the log format of the TCP configuration.
+ *
+ * @param LogFormat $logFormat The log format to set.
+ * @return UdpConfiguration Returns the current instance.
+ */
+ public function setLogFormat(LogFormat $logFormat): UdpConfiguration
+ {
+ $this->logFormat = $logFormat;
+ return $this;
+ }
+
+ /**
+ * Retrieves the timestamp format of the TCP configuration.
+ *
+ * @return TimestampFormat Returns the timestamp format.
+ */
+ public function getTimestampFormat(): TimestampFormat
+ {
+ return $this->timestampFormat;
+ }
+
+ /**
+ * Sets the timestamp format of the TCP configuration.
+ *
+ * @param TimestampFormat $timestampFormat The timestamp format to set.
+ * @return UdpConfiguration Returns the current instance.
+ */
+ public function setTimestampFormat(TimestampFormat $timestampFormat): UdpConfiguration
+ {
+ $this->timestampFormat = $timestampFormat;
+ return $this;
+ }
+
+ /**
+ * Retrieves the trace format of the TCP configuration.
+ *
+ * @return TraceFormat Returns the trace format.
+ */
+ public function getTraceFormat(): TraceFormat
+ {
+ return $this->traceFormat;
+ }
+
+ /**
+ * Sets the trace format of the TCP configuration.
+ *
+ * @param TraceFormat $traceFormat The trace format to set.
+ * @return UdpConfiguration Returns the current instance.
+ */
+ public function setTraceFormat(TraceFormat $traceFormat): UdpConfiguration
+ {
+ $this->traceFormat = $traceFormat;
+ return $this;
+ }
+ }
\ No newline at end of file
diff --git a/src/LogLib2/Objects/Event.php b/src/LogLib2/Objects/Event.php
new file mode 100644
index 0000000..4556391
--- /dev/null
+++ b/src/LogLib2/Objects/Event.php
@@ -0,0 +1,215 @@
+applicationName = $applicationName;
+ if($timestamp === null)
+ {
+ $timestamp = time();
+ }
+ $this->timestamp = $timestamp;
+ $this->level = $level;
+ $this->message = $message;
+ $this->exception = $exceptionDetails;
+ $this->traces = $backtrace;
+ }
+
+ /**
+ * Retrieves the application name.
+ *
+ * @return string Returns the application name as a string.
+ */
+ public function getApplicationName(): string
+ {
+ return $this->applicationName;
+ }
+
+ /**
+ * Retrieves the timestamp.
+ *
+ * @return int Returns the timestamp as an integer.
+ */
+ public function getTimestamp(): int
+ {
+ return $this->timestamp;
+ }
+
+ /**
+ * Retrieves the log level.
+ *
+ * @return LogLevel Returns the log level as a LogLevel instance.
+ */
+ public function getLevel(): LogLevel
+ {
+ return $this->level;
+ }
+
+ /**
+ * Retrieves the message.
+ *
+ * @return string Returns the message as a string.
+ */
+ public function getMessage(): string
+ {
+ return $this->message;
+ }
+
+ /**
+ * Retrieves the exception details.
+ *
+ * @return ExceptionDetails|null Returns the exception details, or null if not set.
+ */
+ public function getException(): ?ExceptionDetails
+ {
+ return $this->exception;
+ }
+
+ /**
+ * Retrieves the backtrace.
+ *
+ * @return StackTrace[] Returns the backtrace as an array of StackTrace instances.
+ */
+ public function getTraces(): array
+ {
+ return $this->traces;
+ }
+
+ /**
+ * Retrieves the first trace.
+ *
+ * @return StackTrace|null Returns the first trace or null if no traces are set.
+ */
+ public function getFirstTrace(): ?StackTrace
+ {
+ if(count($this->traces) > 0)
+ {
+ return $this->traces[0];
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns a standard array representation of the event.
+ *
+ * @return array The standard array representation of the event.
+ */
+ public function toStandardArray(TimestampFormat $timestampFormat, TraceFormat $traceFormat): array
+ {
+ $result = $this->toArray();
+
+ /// Rename the traces to stack_trace
+ $result['stack_trace'] = $result['traces'];
+ unset($result['traces']);
+
+ // Format the timestamp
+ if($timestampFormat === TimestampFormat::NONE)
+ {
+ $result['timestamp'] = TimestampFormat::UNIX_TIMESTAMP->format($result['timestamp']);
+ }
+ else
+ {
+ $result['timestamp'] = $timestampFormat->format($result['timestamp']);
+ }
+
+ // Format the trace
+ if(count($result['stack_trace']) > 0)
+ {
+ $result['trace'] = $traceFormat->format($this->getFirstTrace());
+ }
+
+ return $result;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function toArray(): array
+ {
+ $result = [
+ 'application_name' => $this->applicationName,
+ 'timestamp' => $this->timestamp,
+ 'level' => $this->level->value,
+ 'message' => $this->message,
+ 'traces' => [],
+ 'exception' => null,
+ ];
+
+ foreach($this->traces as $trace)
+ {
+ $result['traces'][] = $trace->toArray();
+ }
+
+ if($this->exception !== null)
+ {
+ $result['exception'] = $this->exception->toArray();
+ }
+
+ return $result;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public static function fromArray(?array $data=null): Event
+ {
+ $traces = [];
+ if(isset($data['traces']))
+ {
+ foreach($data['traces'] as $traceData)
+ {
+ $traces[] = StackTrace::fromArray($traceData);
+ }
+ }
+
+ $exceptionDetails = null;
+ if(isset($data['exception']))
+ {
+ $exceptionDetails = ExceptionDetails::fromArray($data['exception']);
+ }
+
+ return new Event(
+ $data['application_name'],
+ LogLevel::from($data['level']),
+ $data['message'],
+ $traces,
+ $data['timestamp'],
+ $exceptionDetails
+ );
+ }
+ }
\ No newline at end of file
diff --git a/src/LogLib2/Objects/ExceptionDetails.php b/src/LogLib2/Objects/ExceptionDetails.php
new file mode 100644
index 0000000..c78c22f
--- /dev/null
+++ b/src/LogLib2/Objects/ExceptionDetails.php
@@ -0,0 +1,171 @@
+name = $name;
+ $this->message = $message;
+ $this->code = $code;
+ $this->file = $file;
+ $this->line = $line;
+ $this->trace = $trace;
+ $this->previous = $previous;
+ }
+
+ public function getName(): string
+ {
+ return $this->name;
+ }
+
+ public function getMessage(): string
+ {
+ return $this->message;
+ }
+
+ public function getCode(): ?int
+ {
+ return $this->code;
+ }
+
+ public function getFile(): ?string
+ {
+ return $this->file;
+ }
+
+ public function getLine(): ?int
+ {
+ return $this->line;
+ }
+
+ public function getTrace(): ?array
+ {
+ return $this->trace;
+ }
+
+ public function getPrevious(): ?ExceptionDetails
+ {
+ return $this->previous;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function toArray(): array
+ {
+ $result = [
+ 'name' => $this->name,
+ 'message' => $this->message,
+ 'code' => $this->code,
+ 'file' => $this->file,
+ 'line' => $this->line,
+ 'trace' => [],
+ 'previous' => null,
+ ];
+
+ if($this->trace !== null)
+ {
+ foreach($this->trace as $trace)
+ {
+ $result['trace'][] = $trace->toArray();
+ }
+ }
+
+ if($this->previous !== null)
+ {
+ $result['previous'] = $this->previous->toArray();
+ }
+
+ return $result;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public static function fromArray(?array $data=null): SerializableInterface
+ {
+
+ $trace = [];
+ if(isset($data['trace']))
+ {
+ foreach($data['trace'] as $traceData)
+ {
+ $trace[] = StackTrace::fromArray($traceData);
+ }
+ }
+
+ $previous = null;
+ if(isset($data['previous']))
+ {
+ $previous = self::fromArray($data['previous']);
+ }
+
+ return new ExceptionDetails(
+ $data['name'] ?? '',
+ $data['message'] ?? '',
+ $data['code'] ?? null,
+ $data['file'] ?? null,
+ $data['line'] ?? null,
+ $trace,
+ $previous
+ );
+ }
+
+ /**
+ * Creates a new instance from the provided Throwable instance.
+ *
+ * @param Throwable $e The Throwable instance to create the ExceptionDetails instance from.
+ * @return ExceptionDetails The created ExceptionDetails instance.
+ */
+ public static function fromThrowable(Throwable $e): ExceptionDetails
+ {
+ $trace = [];
+ foreach($e->getTrace() as $traceData)
+ {
+ $trace[] = StackTrace::fromTrace($traceData);
+ }
+
+ $previous = null;
+ if($e->getPrevious() !== null)
+ {
+ $previous = self::fromThrowable($e->getPrevious());
+ }
+
+ return new ExceptionDetails(
+ get_class($e),
+ $e->getMessage(),
+ $e->getCode(),
+ $e->getFile(),
+ $e->getLine(),
+ $trace,
+ $previous
+ );
+ }
+ }
\ No newline at end of file
diff --git a/src/LogLib2/Objects/StackTrace.php b/src/LogLib2/Objects/StackTrace.php
new file mode 100644
index 0000000..63d9650
--- /dev/null
+++ b/src/LogLib2/Objects/StackTrace.php
@@ -0,0 +1,207 @@
+file = $file;
+ $this->line = $line;
+ $this->function = $function;
+
+ if($args !== null && !empty($args))
+ {
+ $this->args = $args;
+ }
+ else
+ {
+ $this->args = null;
+ }
+
+ $this->class = $class;
+ $this->callType = $callType;
+ }
+
+ /**
+ * Retrieves the file name.
+ *
+ * @return string|null Returns the file as a string, or null if no file is set.
+ */
+ public function getFile(): ?string
+ {
+ return $this->file;
+ }
+
+ /**
+ * Retrieves the line number.
+ *
+ * @return int|null Returns the line number or null if not set.
+ */
+ public function getLine(): ?int
+ {
+ return $this->line;
+ }
+
+ /**
+ * Retrieves the function name.
+ *
+ * @return string|null The function name or null if not set.
+ */
+ public function getFunction(): ?string
+ {
+ return $this->function;
+ }
+
+ /**
+ * Retrieves the arguments.
+ *
+ * @return array|null Returns an array of arguments or null if no arguments are set.
+ */
+ public function getArgs(): ?array
+ {
+ return $this->args;
+ }
+
+ /**
+ *
+ * @return string|null The class name or null if not set.
+ */
+ public function getClass(): ?string
+ {
+ return $this->class;
+ }
+
+ /**
+ * Retrieves the call type.
+ *
+ * @return CallType|null The call type or null if not set.
+ */
+ public function getCallType(): ?CallType
+ {
+ return $this->callType;
+ }
+
+ /**
+ * Determines whether the current object contains no data.
+ *
+ * @return bool True if all properties are null, false otherwise.
+ */
+ public function isEmpty(): bool
+ {
+ return
+ $this->file === null &&
+ $this->line === null &&
+ $this->function === null &&
+ $this->args === null &&
+ $this->class === null &&
+ $this->callType === null;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function toArray(): array
+ {
+ return [
+ 'file' => $this->file,
+ 'line' => $this->line,
+ 'function' => $this->function,
+ 'args' => $this->args,
+ 'class' => $this->class,
+ 'call_type' => $this->callType?->value ?? CallType::STATIC_CALL->value,
+ ];
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public static function fromArray(?array $data=null): StackTrace
+ {
+ $callType = null;
+ if(isset($data['call_type']))
+ {
+ $callType = CallType::tryFrom($data['call_type']);
+ }
+
+ return new StackTrace(
+ $data['file'] ?? null,
+ $data['line'] ?? null,
+ $data['function'] ?? null,
+ $data['args'] ?? null,
+ $data['class'] ?? null,
+ $callType
+ );
+ }
+
+ /**
+ * Creates a new instance from the provided trace data.
+ *
+ * @param array $trace The trace data to be used.
+ * @return StackTrace The new instance created from the trace data.
+ */
+ public static function fromTrace(array $trace): StackTrace
+ {
+ $parsedTrace = [
+ 'file' => $trace['file'] ?? null,
+ 'function' => $trace['function'] ?? null,
+ 'class' => $trace['class'] ?? null,
+ 'call' => $trace['call'] ?? null,
+ ];
+
+ if(isset($trace['line']))
+ {
+ $parsedTrace['line'] = (int) $trace['line'];
+ }
+ else
+ {
+ $parsedTrace['line'] = null;
+ }
+
+ if(isset($trace['args']))
+ {
+ $result = [];
+ if(array_is_list($trace['args']))
+ {
+ foreach($trace['args'] as $arg)
+ {
+ $result[] = Utilities::getSafeValue($arg);
+ }
+ }
+ else
+ {
+ foreach($trace['args'] as $key => $arg)
+ {
+ $result[$key] = Utilities::getSafeValue($arg);
+ }
+ }
+
+ $parsedTrace['args'] = $result;
+ }
+
+ return StackTrace::fromArray($parsedTrace);
+ }
+ }
\ No newline at end of file
diff --git a/src/LogLib2/Program.php b/src/LogLib2/Program.php
deleted file mode 100644
index c33672c..0000000
--- a/src/LogLib2/Program.php
+++ /dev/null
@@ -1,18 +0,0 @@
-