-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from roufy235/dev
Dev
- Loading branch information
Showing
13 changed files
with
265 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# ASSETS/APP | ||
|
||
**This directory is required.** | ||
|
||
This directory contains your scss,js,images files that are going to be compiled by GulpJs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php /** @noinspection UnknownInspectionInspection */ | ||
|
||
namespace MultiveLogger; | ||
|
||
use Monolog\Formatter\LineFormatter; | ||
use Monolog\Handler\RotatingFileHandler; | ||
use Monolog\Handler\StreamHandler; | ||
use Monolog\Logger; | ||
use Psr\Log\LoggerInterface; | ||
|
||
final class LoggerFactory { | ||
private string $path; | ||
private int $level; | ||
private array $handler = []; | ||
private $testLogger; | ||
|
||
public function __construct(array $settings) { | ||
$this->path = (string)$settings['path']; | ||
$this->level = (int)$settings['level']; | ||
|
||
// This can be used for testing to make the Factory testable | ||
if (isset($settings['test'])) { | ||
$this->testLogger = $settings['test']; | ||
} | ||
} | ||
|
||
public function createLogger(string $name = null): LoggerInterface { | ||
if ($this->testLogger) { | ||
return $this->testLogger; | ||
} | ||
|
||
$logger = new Logger($name ?: uuid_create()); | ||
|
||
foreach ($this->handler as $handler) { | ||
$logger->pushHandler($handler); | ||
} | ||
|
||
$this->handler = []; | ||
|
||
return $logger; | ||
} | ||
|
||
public function addFileHandler(string $filename, int $level = null): self { | ||
$filename = sprintf('%s/%s', $this->path, $filename); | ||
$rotatingFileHandler = new RotatingFileHandler($filename, 0, $level ?? $this->level, true, 0777); | ||
|
||
// The last "true" here tells monolog to remove empty []'s | ||
$rotatingFileHandler->setFormatter(new LineFormatter(null, null, false, true)); | ||
|
||
$this->handler[] = $rotatingFileHandler; | ||
|
||
return $this; | ||
} | ||
|
||
/** @noinspection PhpUnused */ | ||
public function addConsoleHandler(int $level = null): self { | ||
$streamHandler = new StreamHandler('php://stdout', $level ?? $this->level); | ||
$streamHandler->setFormatter(new LineFormatter(null, null, false, true)); | ||
|
||
$this->handler[] = $streamHandler; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php /** @noinspection UnknownInspectionInspection */ | ||
|
||
|
||
namespace MultiveLogger; | ||
|
||
|
||
use Exception; | ||
use MultiveLogger\models\UserModel; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class LoggerNewAccount { | ||
|
||
private LoggerInterface $logger; | ||
|
||
public function __construct(LoggerFactory $logger) { | ||
$this->logger = $logger | ||
->addFileHandler('user_creator.log') | ||
->createLogger(); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
* @noinspection PhpUnused | ||
*/ | ||
public function registerUser(UserModel $user): void { | ||
try { | ||
// Log success | ||
$this->logger->info(sprintf('User created: %s', $user->getUserId())); | ||
} catch (Exception $exception) { | ||
// Log error message | ||
$this->logger->error($exception->getMessage()); | ||
throw $exception; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
|
||
namespace MultiveLogger\models; | ||
|
||
|
||
class UserModel { | ||
public int $userId; | ||
public function __construct() { | ||
$this->userId = 0; | ||
} | ||
public function getUserId(): int { | ||
return $this->userId; | ||
} | ||
public function setName(int $userId): void { | ||
$this->userId = $userId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.