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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library appengine.logging_impl;
6
7 import 'dart:async';
8
9 import 'package:fixnum/fixnum.dart';
10 import 'package:appengine/api/logging.dart';
11
12 import '../protobuf_api/rpc/rpc_service.dart';
13 import '../protobuf_api/logging_service.dart';
14 import '../protobuf_api/internal/log_service.pb.dart' as pb;
15
16 class LoggingRpcImpl extends Logging {
17 final LoggingServiceClientRPCStub _clientRPCStub;
18 final List<pb.UserAppLogLine> _logLines = <pb.UserAppLogLine>[];
19
20 LoggingRpcImpl(RPCService rpcService, String ticket)
21 : _clientRPCStub = new LoggingServiceClientRPCStub(rpcService, ticket);
22
23 void log(LogLevel level, String message, {DateTime timestamp}) {
24 if (timestamp == null) {
25 timestamp = new DateTime.now();
26 }
27
28 // Issue 15747158.
29 print('$timestamp: ApplicationLog | $level: ${message.trim()}');
30
31 _logLines.add(_createLogLine(level, message, timestamp));
32 }
33
34 pb.UserAppLogLine _createLogLine(
35 LogLevel level, String message, DateTime timestamp) {
36 var timestampUsec = timestamp.toUtc().millisecondsSinceEpoch * 1000;
37 return new pb.UserAppLogLine()
38 ..timestampUsec = new Int64(timestampUsec)
39 ..level = new Int64(level.level)
40 ..message = message;
41 }
42
43 Future flush() {
44 if (_logLines.isEmpty) {
45 return new Future.value();
46 }
47
48 var group = new pb.UserAppLogGroup();
49 group.logLine.addAll(_logLines);
50 _logLines.clear();
51
52 var request = new pb.FlushRequest()
53 ..logs = group.writeToBuffer();
54
55 // NOTE: We swallow errors here to prevent clients sending error messages
56 // using the logging service -- which would create an infinite error loop.
57 // TODO: We could introduce a local logging mechanism in the future which
58 // we could use to report such errors.
59 return _clientRPCStub.Flush(request).catchError((_) {}).then((_) => null);
60 }
61 }
OLDNEW
« 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