@@ -37,10 +37,10 @@ class Logger extends AbstractLogger
37
37
private $ formatter ;
38
38
private $ handle ;
39
39
40
- public function __construct ($ minLevel = null , $ output = ' php://stderr ' , callable $ formatter = null )
40
+ public function __construct ($ minLevel = null , $ output = null , callable $ formatter = null )
41
41
{
42
42
if (null === $ minLevel ) {
43
- $ minLevel = 'php://stdout ' === $ output || 'php://stderr ' === $ output ? LogLevel::CRITICAL : LogLevel::WARNING ;
43
+ $ minLevel = null === $ output || 'php://stdout ' === $ output || 'php://stderr ' === $ output ? LogLevel::ERROR : LogLevel::WARNING ;
44
44
45
45
if (isset ($ _ENV ['SHELL_VERBOSITY ' ]) || isset ($ _SERVER ['SHELL_VERBOSITY ' ])) {
46
46
switch ((int ) (isset ($ _ENV ['SHELL_VERBOSITY ' ]) ? $ _ENV ['SHELL_VERBOSITY ' ] : $ _SERVER ['SHELL_VERBOSITY ' ])) {
@@ -58,7 +58,7 @@ public function __construct($minLevel = null, $output = 'php://stderr', callable
58
58
59
59
$ this ->minLevelIndex = self ::$ levels [$ minLevel ];
60
60
$ this ->formatter = $ formatter ?: [$ this , 'format ' ];
61
- if (false === $ this ->handle = \is_resource ($ output ) ? $ output : @fopen ($ output , 'a ' )) {
61
+ if ($ output && false === $ this ->handle = \is_resource ($ output ) ? $ output : @fopen ($ output , 'a ' )) {
62
62
throw new InvalidArgumentException (sprintf ('Unable to open "%s". ' , $ output ));
63
63
}
64
64
}
@@ -77,7 +77,11 @@ public function log($level, $message, array $context = [])
77
77
}
78
78
79
79
$ formatter = $ this ->formatter ;
80
- @fwrite ($ this ->handle , $ formatter ($ level , $ message , $ context ));
80
+ if ($ this ->handle ) {
81
+ @fwrite ($ this ->handle , $ formatter ($ level , $ message , $ context ));
82
+ } else {
83
+ error_log ($ formatter ($ level , $ message , $ context ));
84
+ }
81
85
}
82
86
83
87
/**
0 commit comments