Added initial codebase

This commit is contained in:
netkas 2025-01-22 01:02:17 -05:00
parent 493a86bc9b
commit 80a6af74ed
41 changed files with 5676 additions and 29 deletions

29
examples/example1.php Normal file
View file

@ -0,0 +1,29 @@
<?php
require 'ncc';
require 'example_class.php';
import('net.nosial.loglib2');
\LogLib2\Logger::setBacktraceLevel(3);
\LogLib2\Logger::registerHandlers();
$logger = new \LogLib2\Logger('Example');
// Iterate 10 times
for($i = 0; $i < 10; $i++)
{
// Log a message with a random log level
$logger->info('This is an example log message.');
}
$a = [];
$b = $a['foo']; // <-- This will throw a notice that will be caught by the logger
$exception = new \Exception('This is an example exception.');
$logger->error("test", $exception);
$example = new ExampleClass($logger);
$example->sleepExample(5);
$example->throwDoubleException();

View file

@ -0,0 +1,39 @@
<?php
class ExampleClass {
private \LogLib2\Logger $logger;
public function __construct(\LogLib2\Logger $logger) {
$this->logger = $logger;
}
public function getLogger(): \LogLib2\Logger {
return $this->logger;
}
public function sleepExample(int $seconds): void {
$this->logger->info("Sleeping for $seconds seconds...");
sleep($seconds);
$this->logger->info("Finished sleeping for $seconds seconds.");
}
public function throwException(): void {
throw new \Exception("This is an example exception.");
}
public function throwDoubleException(): void {
try
{
$this->throwException();
}
catch(Exception $e)
{
throw new Exception("this is a new exception", 0, $e);
}
}
public function warningExceptionExample(): void {
$this->logger->warning("Throwing a warning exception...", new \Exception("This is an example warning exception."));
}
}