diff --git a/example/echo.dart b/example/echo.dart index 8c4d039..2e1bc16 100644 --- a/example/echo.dart +++ b/example/echo.dart @@ -1,37 +1,39 @@ library echo; import "dart:html"; -import "dart:convert"; +import 'package:logging/logging.dart'; import "package:sockjs_client/sockjs.dart" as SockJS; DivElement div = querySelector('#first div'); InputElement inp = querySelector('#first input'); FormElement form = querySelector('#first form'); -print(m, [p = '']) { - if(!p.isEmpty) { - p = JSON.encode(p); - } +_log(LogRecord l) { div - ..append(new Element.html("")..text=("$m$p")) - ..append(new Element.html("
")); - - div.scrollTop += 10000; + ..append(new Element.html("")..text = "${l.message}") + ..append(new Element.html("
")) + ..scrollTop += 10000; } main() { - print("Starting"); + // Setup Logging + Logger.root.level = Level.INFO; + Logger.root.onRecord.listen(_log); + + final LOG = new Logger("sockjs"); + + LOG.info("Starting"); var sockjs_url = 'http://127.0.0.1:8081/echo'; var sockjs = new SockJS.Client(sockjs_url, protocolsWhitelist:['websocket', 'xhr-streaming'], debug: true); querySelector('#first input').focus(); - sockjs.on.open.add( (_) => print('[*] open ${sockjs.protocol}') ); - sockjs.on.message.add( (e) => print('[.] message ${e.data}') ); - sockjs.on.close.add( (_) => print('[*] close') ); + sockjs.onOpen.listen( (_) => LOG.info('[*] open ${sockjs.protocol}') ); + sockjs.onMessage.listen( (e) => LOG.info('[.] message ${e.data}') ); + sockjs.onClose.listen( (_) => LOG.info('[*] close') ); inp.onKeyUp.listen( (KeyboardEvent e) { if (e.keyCode == 13) { - print('[ ] sending ${inp.value}'); + LOG.info('[ ] sending ${inp.value}'); sockjs.send(inp.value); inp.value = ''; } diff --git a/pubspec.yaml b/pubspec.yaml index 653c211..a8e27ac 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,5 +6,6 @@ authors: description: A SockJS client in Dart dependencies: browser: '>=0.9.0 <1.0.0' + logging: '>=0.9.0 <1.0.0' environment: - sdk: '>=1.0.0' \ No newline at end of file + sdk: '>=1.0.0 <2.0.0' \ No newline at end of file