Skip to content

Commit 073806e

Browse files
authored
Issue #16
1 parent c9434e8 commit 073806e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/SimpleLoggerFactory.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace smalex86\logger;
44

55
use smalex86\logger\Logger;
6-
use smalex86\logger\route\FileRoute;
76
use Psr\Log\LoggerInterface;
87
use DateTime;
98

@@ -36,6 +35,11 @@ class SimpleLoggerFactory {
3635
* @var string
3736
*/
3837
protected static $dateFormat;
38+
/**
39+
* It determines to use FileRoute or FileRouteWithPid
40+
* @var bool
41+
*/
42+
protected static $withPid;
3943

4044
/**
4145
* Factory parameters init
@@ -46,12 +50,13 @@ class SimpleLoggerFactory {
4650
* @param string $dateFormat
4751
*/
4852
public static function init($maxLevel, $logFilename, $folder,
49-
$dateFormat = DateTime::W3C)
53+
$dateFormat = DateTime::W3C, $withPid = false)
5054
{
5155
self::$maxLevel = $maxLevel;
5256
self::$logFilename = $logFilename;
5357
self::$folder = $folder;
5458
self::$dateFormat = $dateFormat;
59+
self::$withPid = $withPid;
5560
}
5661

5762
/**
@@ -62,7 +67,12 @@ public static function init($maxLevel, $logFilename, $folder,
6267
public static function getLogger(): LoggerInterface
6368
{
6469
$logger = new Logger();
65-
$logger->routeList->attach(new FileRoute([
70+
if (!self::$withPid) {
71+
$routeClass = 'smalex86\logger\route\FileRoute';
72+
} else {
73+
$routeClass = 'smalex86\logger\route\FileRouteWithPid';
74+
}
75+
$logger->routeList->attach(new $routeClass([
6676
'dateFormat' => self::$dateFormat,
6777
'isEnabled' => true,
6878
'maxLevel' => self::$maxLevel,

0 commit comments

Comments
 (0)