Skip to content

Commit 2f1fb8d

Browse files
committed
Remove io dependency
This made the SimplePrinter incompatible with the web platform for little upside. I'd rather not maintain a seperate colors class but the stdlib defines it in 'io' which is not great.
1 parent 97797dd commit 2f1fb8d

File tree

7 files changed

+19
-28
lines changed

7 files changed

+19
-28
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ var logger = Logger(
9090
```
9191

9292

93+
You can try to auto detect if the attached terminal supports ANSI escape
94+
characters by using the output of `io.stdout.supportsAnsiEscapes` as value for
95+
the `colors` argument (assuming you have imported the `io` package with `import 'dart:io' as io;`).
96+
9397
## LogFilter
9498

9599
The `LogFilter` decides which log events should be shown and which don't.<br>
@@ -180,4 +184,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
180184
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
181185
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
182186
SOFTWARE.
183-
```
187+
```

example/main.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:logger/logger.dart';
2-
import 'package:logger/src/printers/simple_printer.dart';
32

43
var logger = Logger(
54
printer: PrettyPrinter(),

lib/logger.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ export 'src/outputs/memory_output.dart';
1212

1313
export 'src/printers/pretty_printer.dart';
1414
export 'src/printers/logfmt_printer.dart';
15+
export 'src/printers/simple_printer.dart';
1516

1617
export 'src/log_output.dart'
1718
if (dart.library.io) 'src/outputs/file_output.dart';
1819

19-
export 'src/log_printer.dart'
20-
if (dart.library.io) 'src/printers/simple_printer.dart';
21-
2220
export 'src/log_filter.dart';
2321
export 'src/log_output.dart';
2422
export 'src/log_printer.dart';

lib/src/ansi_color.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// This class handles colorizing of terminal output.
12
class AnsiColor {
23
/// ANSI Control Sequence Introducer, signals the terminal for new settings.
34
static const ansiEsc = '\x1B[';

lib/src/printers/simple_printer.dart

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import 'dart:convert';
2-
import 'dart:io' as io;
3-
4-
import 'package:io/ansi.dart';
52

63
import 'package:logger/src/logger.dart';
74
import 'package:logger/src/log_printer.dart';
5+
import 'package:logger/src/ansi_color.dart';
86

97
/// Outputs simple log messages:
108
/// ```
@@ -21,24 +19,18 @@ class SimplePrinter extends LogPrinter {
2119
};
2220

2321
static final levelColors = {
24-
Level.verbose: darkGray,
25-
Level.debug: defaultForeground,
26-
Level.info: blue,
27-
Level.warning: yellow,
28-
Level.error: magenta,
29-
Level.wtf: red,
22+
Level.verbose: AnsiColor.fg(AnsiColor.grey(0.5)),
23+
Level.debug: AnsiColor.none(),
24+
Level.info: AnsiColor.fg(12),
25+
Level.warning: AnsiColor.fg(208),
26+
Level.error: AnsiColor.fg(196),
27+
Level.wtf: AnsiColor.fg(199),
3028
};
3129

3230
bool printTime;
33-
34-
/// You can override the auto detected color support with this property. This
35-
/// is useful when Dart incorrectly reports a terminal not supporting colors.
36-
/// This happens, for example, when running the Dart program under Tmux or
37-
/// screen. See https://github.com/dart-lang/sdk/issues/31606.
3831
bool useColor;
3932

40-
SimplePrinter({this.printTime = false})
41-
: useColor = io.stdout.supportsAnsiEscapes;
33+
SimplePrinter({this.printTime = false, this.useColor = true});
4234

4335
@override
4436
List<String> log(LogEvent event) {
@@ -52,7 +44,7 @@ class SimplePrinter extends LogPrinter {
5244
var prefix = levelPrefixes[level];
5345
var color = levelColors[level];
5446

55-
return overrideAnsiOutput(useColor, () => color.wrap(prefix));
47+
return useColor ? color(prefix) : prefix;
5648
}
5749

5850
String _stringifyMessage(dynamic message) {

pubspec.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
name: logger
22
description: Small, easy to use and extensible logger which prints beautiful logs.
3-
version: 0.8.3
3+
version: 0.9.0
44
homepage: https://github.com/leisim/logger
55

66
environment:
77
sdk: ">=2.2.0 <3.0.0"
88

9-
dependencies:
10-
io: ^0.3.3
11-
129
dev_dependencies:
1310
test: any
1411
pedantic: ^1.9.0

test/printers/simple_printer_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const ansiEscapeLiteral = '\x1B';
66

77
void main() {
88
var event = LogEvent(
9-
Level.debug,
9+
Level.verbose,
1010
'some message',
1111
'some error',
1212
StackTrace.current,
@@ -20,7 +20,7 @@ void main() {
2020
var outputs = plainPrinter.log(event);
2121

2222
expect(outputs, hasLength(1));
23-
expect(outputs[0], '[D] some message ERROR: some error');
23+
expect(outputs[0], '[V] some message ERROR: some error');
2424
});
2525

2626
group('color', () {

0 commit comments

Comments
 (0)