-
Notifications
You must be signed in to change notification settings - Fork 360
/
Copy pathlogger.dart
123 lines (112 loc) · 3.71 KB
/
logger.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright 2017 Google Inc. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
import 'package:meta/meta.dart';
import 'package:source_span/source_span.dart';
import 'package:stack_trace/stack_trace.dart';
import 'deprecation.dart';
import 'logger/deprecation_processing.dart';
import 'logger/stderr.dart';
/// An interface for loggers that print messages produced by Sass stylesheets.
///
/// This may be implemented by user code.
///
/// {@category Compile}
abstract class Logger {
/// A logger that silently ignores all messages.
static final Logger quiet = _QuietLogger();
/// Creates a logger that prints warnings to standard error, with terminal
/// colors if [color] is `true` (default `false`).
const factory Logger.stderr({bool color}) = StderrLogger;
/// Emits a warning with the given [message].
///
/// If [span] is passed, it's the location in the Sass source that generated
/// the warning. If [trace] is passed, it's the Sass stack trace when the
/// warning was issued. If [deprecation] is `true`, it indicates that this is
/// a deprecation warning. Implementations should surface all this information
/// to the end user.
void warn(
String message, {
FileSpan? span,
Trace? trace,
bool deprecation = false,
});
/// Emits a debugging message associated with the given [span].
void debug(String message, SourceSpan span);
}
/// A base class for loggers that support the [Deprecation] object, rather than
/// just a boolean flag for whether a warnings is a deprecation warning or not.
///
/// In Dart Sass 2.0.0, we will eliminate this interface and change
/// [Logger.warn]'s signature to match that of [internalWarn]. This is used
/// in the meantime to provide access to the [Deprecation] object to internal
/// loggers.
///
/// Implementers should override the protected [internalWarn] method instead of
/// [warn].
@internal
abstract class LoggerWithDeprecationType implements Logger {
const LoggerWithDeprecationType();
/// This forwards all calls to [internalWarn].
///
/// For non-user deprecation warnings, the [warnForDeprecation] extension
/// method should be called instead.
void warn(
String message, {
FileSpan? span,
Trace? trace,
bool deprecation = false,
}) {
internalWarn(
message,
span: span,
trace: trace,
deprecation: deprecation ? Deprecation.userAuthored : null,
);
}
/// Equivalent to [Logger.warn], but for internal loggers that support
/// the [Deprecation] object.
///
/// Subclasses of this logger should override this method instead of [warn].
@protected
void internalWarn(
String message, {
FileSpan? span,
Trace? trace,
Deprecation? deprecation,
});
}
/// An extension to add a `warnForDeprecation` method to loggers without
/// making a breaking API change.
@internal
extension WarnForDeprecation on Logger {
/// Emits a deprecation warning for [deprecation] with the given [message].
void warnForDeprecation(
Deprecation deprecation,
String message, {
FileSpan? span,
Trace? trace,
}) {
if (deprecation.isFuture && this is! DeprecationProcessingLogger) return;
if (this case LoggerWithDeprecationType self) {
self.internalWarn(
message,
span: span,
trace: trace,
deprecation: deprecation,
);
} else {
warn(message, span: span, trace: trace, deprecation: true);
}
}
}
/// A logger that emits no messages.
final class _QuietLogger implements Logger {
void warn(
String message, {
FileSpan? span,
Trace? trace,
bool deprecation = false,
}) {}
void debug(String message, SourceSpan span) {}
}