Logging for test handlers
This commit is contained in:
parent
126acda31b
commit
47b4ef3546
5 changed files with 61 additions and 18 deletions
8
.idea/runConfigurations/tests_in_shelf.xml
Normal file
8
.idea/runConfigurations/tests_in_shelf.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="tests in shelf" type="DartTestRunConfigurationType" factoryName="Dart Test" singleton="true" nameIsGenerated="true">
|
||||
<option name="filePath" value="$PROJECT_DIR$" />
|
||||
<option name="scope" value="FOLDER" />
|
||||
<option name="testRunnerOptions" value="-j 4" />
|
||||
<method />
|
||||
</configuration>
|
||||
</component>
|
29
pubspec.yaml
29
pubspec.yaml
|
@ -1,14 +1,15 @@
|
|||
name: angel_shelf
|
||||
description: Shelf interop with Angel.
|
||||
version: 1.2.0
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/shelf
|
||||
environment:
|
||||
sdk: ">=1.19.0"
|
||||
dependencies:
|
||||
angel_framework: ">=1.1.0-alpha <2.0.0"
|
||||
shelf: ^0.6.0
|
||||
dev_dependencies:
|
||||
angel_test: ^1.1.0
|
||||
shelf_proxy: ^0.1.0
|
||||
test: ^0.12.0
|
||||
author: "Tobe O <thosakwe@gmail.com>"
|
||||
description: "Shelf interop with Angel."
|
||||
homepage: "https://github.com/angel-dart/shelf"
|
||||
name: "angel_shelf"
|
||||
version: "1.2.0"
|
||||
dependencies:
|
||||
angel_framework: ">=1.1.0-alpha <2.0.0"
|
||||
shelf: "^0.6.0"
|
||||
dev_dependencies:
|
||||
angel_test: "^1.1.0"
|
||||
console: "^2.2.4"
|
||||
shelf_proxy: "^0.1.0"
|
||||
test: "^0.12.0"
|
||||
environment:
|
||||
sdk: ">=1.19.0"
|
||||
|
|
|
@ -2,13 +2,14 @@ import 'dart:async';
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:angel_client/io.dart' as c;
|
||||
import 'package:angel_diagnostics/angel_diagnostics.dart';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_shelf/angel_shelf.dart';
|
||||
import 'package:angel_test/angel_test.dart';
|
||||
import 'package:charcode/charcode.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:shelf/shelf.dart' as shelf;
|
||||
import 'package:test/test.dart';
|
||||
import 'pretty_logging.dart';
|
||||
|
||||
main() {
|
||||
c.Angel client;
|
||||
|
@ -39,7 +40,7 @@ main() {
|
|||
var app = new Angel()..lazyParseBodies = true;
|
||||
app.get('/angel', 'Angel');
|
||||
app.use(embedShelf(handler, throwOnNullResponse: true));
|
||||
await app.configure(logRequests());
|
||||
app.logger = new Logger.detached('angel')..onRecord.listen(prettyLog);
|
||||
|
||||
server = await app.startServer(InternetAddress.LOOPBACK_IP_V4, 0);
|
||||
client =
|
||||
|
|
32
test/pretty_logging.dart
Normal file
32
test/pretty_logging.dart
Normal file
|
@ -0,0 +1,32 @@
|
|||
import 'package:console/console.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
/// Prints the contents of a [LogRecord] with pretty colors.
|
||||
void prettyLog(LogRecord record) {
|
||||
var pen = new TextPen();
|
||||
chooseLogColor(pen.reset(), record.level);
|
||||
pen(record.toString());
|
||||
|
||||
if (record.error != null)
|
||||
pen(record.error.toString());
|
||||
if (record.stackTrace != null)
|
||||
pen(record.stackTrace.toString());
|
||||
|
||||
pen();
|
||||
}
|
||||
|
||||
/// Chooses a color based on the logger [level].
|
||||
void chooseLogColor(TextPen pen, Level level) {
|
||||
if (level == Level.SHOUT)
|
||||
pen.darkRed();
|
||||
else if (level == Level.SEVERE)
|
||||
pen.red();
|
||||
else if (level == Level.WARNING)
|
||||
pen.yellow();
|
||||
else if (level == Level.INFO)
|
||||
pen.magenta();
|
||||
else if (level == Level.FINER)
|
||||
pen.blue();
|
||||
else if (level == Level.FINEST)
|
||||
pen.darkBlue();
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
import 'package:angel_diagnostics/angel_diagnostics.dart';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_shelf/angel_shelf.dart';
|
||||
import 'package:angel_test/angel_test.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:shelf/shelf.dart' as shelf;
|
||||
import 'package:test/test.dart';
|
||||
import 'pretty_logging.dart';
|
||||
|
||||
main() {
|
||||
TestClient client;
|
||||
|
@ -21,7 +22,7 @@ main() {
|
|||
});
|
||||
|
||||
await app.configure(supportShelf());
|
||||
await app.configure(logRequests());
|
||||
app.logger = new Logger.detached('angel')..onRecord.listen(prettyLog);
|
||||
client = await connectTo(app);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue