Skip to content

Commit

Permalink
Revert "Add platform detection"
Browse files Browse the repository at this point in the history
This reverts commit 625c0dc.
Platform detection was not working. The booleans `isWeb` and `isVM` always
stayed `false`.
  • Loading branch information
haarts committed Sep 28, 2020
1 parent cc884b6 commit 01aa9e1
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 307 deletions.
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,15 @@ var logger = Logger(
);
```

### Auto Detecting Platform
### Auto detecting

The class `LogPlatform` tries to automatically identify `lineLength` and `colors`
support for console output, depending on the detected platform (VM or Web).
With the `io` package you can auto detect the `lineLength` and `colors` arguments.
Assuming you have imported the `io` package with `import 'dart:io' as io;` you
can auto detect `colors` with `io.stdout.supportsAnsiEscapes` and `lineLength`
with `io.stdout.terminalColumns`.

If in VM platform it uses `dart:io` (`colors` with `io.stdout.supportsAnsiEscapes`
and `lineLength` with `io.stdout.terminalColumns`).

If you want to allow output in `stderr` (if present in the runtime platform),
you should enable it:

```dart
LogPlatform.enableSTDERR = true ;
```
You should probably do this unless there's a good reason you don't want to
import `io`, for example when using this library on the web.

## LogFilter

Expand Down
2 changes: 0 additions & 2 deletions lib/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ export 'src/printers/simple_printer.dart';
export 'src/printers/hybrid_printer.dart';
export 'src/printers/prefix_printer.dart';

export 'src/platform/platform.dart';

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

Expand Down
6 changes: 1 addition & 5 deletions lib/src/outputs/console_output.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import 'package:logger/src/logger.dart';
import 'package:logger/src/log_output.dart';
import 'package:logger/src/platform/platform.dart';

/// Default implementation of [LogOutput].
///
/// It sends everything to the system console.
class ConsoleOutput extends LogOutput {
@override
void output(OutputEvent event) {
var allLines = LogPlatform.joinLines(event.lines, event.level);
var printer = LogPlatform.getConsolePrinter(event.level);

printer(allLines);
event.lines.forEach(print);
}
}
124 changes: 0 additions & 124 deletions lib/src/platform/platform.dart

This file was deleted.

21 changes: 0 additions & 21 deletions lib/src/platform/platform_standard.dart

This file was deleted.

51 changes: 0 additions & 51 deletions lib/src/platform/platform_vm.dart

This file was deleted.

54 changes: 0 additions & 54 deletions lib/src/platform/platform_web.dart

This file was deleted.

41 changes: 9 additions & 32 deletions lib/src/printers/pretty_printer.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'dart:convert';

import 'package:logger/src/ansi_color.dart';
import 'package:logger/src/logger.dart';
import 'package:logger/src/log_printer.dart';
import 'package:logger/src/platform/platform.dart';
import 'package:logger/src/ansi_color.dart';

/// Default implementation of [LogPrinter].
///
/// Output looks like this:
/// Outut looks like this:
/// ```
/// ┌──────────────────────────
/// │ Error info
Expand Down Expand Up @@ -64,52 +63,30 @@ class PrettyPrinter extends LogPrinter {

static DateTime _startTime;

/// Amount of [StackTrace] lines to show with message (non-error log).
/// Defaults to LogPlatform.DEFAULT_METHOD_COUNT.
final int methodCount;

/// Amount of error [StackTrace] lines to show with message.
/// Defaults to LogPlatform.DEFAULT_ERROR_METHOD_COUNT.
final int errorMethodCount;

/// Columns length to format log.
/// Defaults to LogPlatform.DEFAULT_LINE_LENGTH.
final int lineLength;

/// If [true] uses colors for logging.
/// Defaults to LogPlatform.DEFAULT_USE_COLORS.
final bool colors;

/// If [true] uses emojis to identify logging types.
/// Defaults to LogPlatform.DEFAULT_USE_EMOJI.
final bool printEmojis;

/// If [true] shows a line with log event time.
/// Defaults to false.
final bool printTime;

String _topBorder = '';
String _middleBorder = '';
String _bottomBorder = '';

PrettyPrinter({
int methodCount,
int errorMethodCount,
int lineLength,
bool colors,
bool printEmojis,
this.methodCount = 2,
this.errorMethodCount = 8,
this.lineLength = 120,
this.colors = true,
this.printEmojis = true,
this.printTime = false,
}) : methodCount = methodCount ?? LogPlatform.DEFAULT_METHOD_COUNT,
errorMethodCount =
errorMethodCount ?? LogPlatform.DEFAULT_ERROR_METHOD_COUNT,
lineLength = lineLength ?? LogPlatform.DEFAULT_LINE_LENGTH,
colors = colors ?? LogPlatform.DEFAULT_USE_COLORS,
printEmojis = printEmojis ?? LogPlatform.DEFAULT_USE_EMOJI {
}) {
_startTime ??= DateTime.now();

var doubleDividerLine = StringBuffer();
var singleDividerLine = StringBuffer();
for (var i = 0; i < this.lineLength - 1; i++) {
for (var i = 0; i < lineLength - 1; i++) {
doubleDividerLine.write(doubleDivider);
singleDividerLine.write(singleDivider);
}
Expand Down
Loading

0 comments on commit 01aa9e1

Please sign in to comment.