aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/scssphp/scssphp/src/Logger/StreamLogger.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/scssphp/scssphp/src/Logger/StreamLogger.php')
-rw-r--r--vendor/scssphp/scssphp/src/Logger/StreamLogger.php47
1 files changed, 32 insertions, 15 deletions
diff --git a/vendor/scssphp/scssphp/src/Logger/StreamLogger.php b/vendor/scssphp/scssphp/src/Logger/StreamLogger.php
index 7db7cc189..f11f0f19e 100644
--- a/vendor/scssphp/scssphp/src/Logger/StreamLogger.php
+++ b/vendor/scssphp/scssphp/src/Logger/StreamLogger.php
@@ -12,12 +12,17 @@
namespace ScssPhp\ScssPhp\Logger;
+use ScssPhp\ScssPhp\Deprecation;
+use ScssPhp\ScssPhp\StackTrace\Trace;
+use ScssPhp\ScssPhp\Util;
+use ScssPhp\ScssPhp\Util\Path;
+use SourceSpan\FileSpan;
+use SourceSpan\SourceSpan;
+
/**
* A logger that prints to a PHP stream (for instance stderr)
- *
- * @final
*/
-class StreamLogger implements LoggerInterface
+final class StreamLogger implements LoggerInterface
{
private $stream;
private $closeOnDestruct;
@@ -26,7 +31,7 @@ class StreamLogger implements LoggerInterface
* @param resource $stream A stream resource
* @param bool $closeOnDestruct If true, takes ownership of the stream and close it on destruct to avoid leaks.
*/
- public function __construct($stream, $closeOnDestruct = false)
+ public function __construct($stream, bool $closeOnDestruct = false)
{
$this->stream = $stream;
$this->closeOnDestruct = $closeOnDestruct;
@@ -42,21 +47,33 @@ class StreamLogger implements LoggerInterface
}
}
- /**
- * @inheritDoc
- */
- public function warn($message, $deprecation = false)
+ public function warn(string $message, ?Deprecation $deprecation = null, ?FileSpan $span = null, ?Trace $trace = null): void
{
- $prefix = ($deprecation ? 'DEPRECATION ' : '') . 'WARNING: ';
+ $prefix = ($deprecation !== null ? 'DEPRECATION ' : '') . 'WARNING';
+
+ if ($span === null) {
+ $formattedMessage = ': ' . $message;
+ } elseif ($trace !== null) {
+ // If there's a span and a trace, the span's location information is
+ // probably duplicated in the trace, so we just use it for highlighting.
+ $formattedMessage = ': ' . $message . "\n\n" . $span->highlight();
+ } else {
+ $formattedMessage = ' on ' . $span->message("\n" . $message);
+ }
- fwrite($this->stream, $prefix . $message . "\n\n");
+ if ($trace !== null) {
+ $formattedMessage .= "\n" . Util::indent(rtrim($trace->getFormattedTrace()), 4);
+ }
+
+ fwrite($this->stream, $prefix . $formattedMessage . "\n\n");
}
- /**
- * @inheritDoc
- */
- public function debug($message)
+ public function debug(string $message, SourceSpan $span): void
{
- fwrite($this->stream, $message . "\n");
+ $url = $span->getStart()->getSourceUrl() === null ? '-' : Path::prettyUri($span->getStart()->getSourceUrl());
+ $line = $span->getStart()->getLine() + 1;
+ $location = "$url:$line ";
+
+ fwrite($this->stream, \sprintf("%sDEBUG: %s", $location, $message) . "\n");
}
}