Skip to content

Commit b17a69e

Browse files
committed
ICL: Initial initialization logic & custom formatter added.
1 parent 68dbb13 commit b17a69e

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/Log/Formatter.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Illuminated\Console\Log;
4+
5+
use Monolog\Formatter\LineFormatter;
6+
7+
class Formatter extends LineFormatter
8+
{
9+
public function __construct()
10+
{
11+
parent::__construct("[%datetime%]: [%level_name%]: %message%\n%context% %extra%\n", null, true, true);
12+
}
13+
}

src/Loggable.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminated\Console;
44

5+
use Illuminated\Console\Log\Formatter;
56
use Monolog\Handler\RotatingFileHandler;
67
use Monolog\Logger;
78
use Symfony\Component\Console\Input\InputInterface;
@@ -17,15 +18,20 @@ protected function initialize(InputInterface $input, OutputInterface $output)
1718
}
1819

1920
protected function initializeLogging()
21+
{
22+
$log = new Logger('ICL', $this->getLogHandlers());
23+
$log->info('Hello World!');
24+
}
25+
26+
private function getLogHandlers()
2027
{
2128
$type = $this->type();
22-
$environment = app()->environment();
2329
$path = storage_path("logs/cloud/{$type}/{$this->entity}/date.log");
2430

25-
$handler = new RotatingFileHandler($path, 30);
26-
$handler->setFilenameFormat('{date}', 'Y-m-d');
27-
$log = new Logger($environment, [$handler]);
31+
$rotatingFileHandler = new RotatingFileHandler($path, 30);
32+
$rotatingFileHandler->setFilenameFormat('{date}', 'Y-m-d');
33+
$rotatingFileHandler->setFormatter(new Formatter());
2834

29-
$log->info('Hello World!');
35+
return [$rotatingFileHandler];
3036
}
3137
}

0 commit comments

Comments
 (0)