Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: pkg/appengine/lib/src/api_impl/logging_impl.dart

Issue 804973002: Add appengine/gcloud/mustache dependencies. (Closed) Base URL: git@github.com:dart-lang/pub-dartlang-dart.git@master
Patch Set: Added AUTHORS/LICENSE/PATENTS files Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/appengine/lib/appengine.dart ('k') | pkg/appengine/lib/src/api_impl/modules_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/appengine/lib/src/api_impl/logging_impl.dart
diff --git a/pkg/appengine/lib/src/api_impl/logging_impl.dart b/pkg/appengine/lib/src/api_impl/logging_impl.dart
new file mode 100644
index 0000000000000000000000000000000000000000..50c39d9940cdefe8d608923e2c3222a19fc31559
--- /dev/null
+++ b/pkg/appengine/lib/src/api_impl/logging_impl.dart
@@ -0,0 +1,61 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library appengine.logging_impl;
+
+import 'dart:async';
+
+import 'package:fixnum/fixnum.dart';
+import 'package:appengine/api/logging.dart';
+
+import '../protobuf_api/rpc/rpc_service.dart';
+import '../protobuf_api/logging_service.dart';
+import '../protobuf_api/internal/log_service.pb.dart' as pb;
+
+class LoggingRpcImpl extends Logging {
+ final LoggingServiceClientRPCStub _clientRPCStub;
+ final List<pb.UserAppLogLine> _logLines = <pb.UserAppLogLine>[];
+
+ LoggingRpcImpl(RPCService rpcService, String ticket)
+ : _clientRPCStub = new LoggingServiceClientRPCStub(rpcService, ticket);
+
+ void log(LogLevel level, String message, {DateTime timestamp}) {
+ if (timestamp == null) {
+ timestamp = new DateTime.now();
+ }
+
+ // Issue 15747158.
+ print('$timestamp: ApplicationLog | $level: ${message.trim()}');
+
+ _logLines.add(_createLogLine(level, message, timestamp));
+ }
+
+ pb.UserAppLogLine _createLogLine(
+ LogLevel level, String message, DateTime timestamp) {
+ var timestampUsec = timestamp.toUtc().millisecondsSinceEpoch * 1000;
+ return new pb.UserAppLogLine()
+ ..timestampUsec = new Int64(timestampUsec)
+ ..level = new Int64(level.level)
+ ..message = message;
+ }
+
+ Future flush() {
+ if (_logLines.isEmpty) {
+ return new Future.value();
+ }
+
+ var group = new pb.UserAppLogGroup();
+ group.logLine.addAll(_logLines);
+ _logLines.clear();
+
+ var request = new pb.FlushRequest()
+ ..logs = group.writeToBuffer();
+
+ // NOTE: We swallow errors here to prevent clients sending error messages
+ // using the logging service -- which would create an infinite error loop.
+ // TODO: We could introduce a local logging mechanism in the future which
+ // we could use to report such errors.
+ return _clientRPCStub.Flush(request).catchError((_) {}).then((_) => null);
+ }
+}
« no previous file with comments | « pkg/appengine/lib/appengine.dart ('k') | pkg/appengine/lib/src/api_impl/modules_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698