OLD | NEW |
(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.api.logging; |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'package:gcloud/service_scope.dart' as ss; |
| 10 |
| 11 class LogLevel { |
| 12 static const LogLevel CRITICAL = const LogLevel._('Critical', 4); |
| 13 static const LogLevel ERROR = const LogLevel._('Error', 3); |
| 14 static const LogLevel WARNING = const LogLevel._('Warning', 2); |
| 15 static const LogLevel INFO = const LogLevel._('Info', 1); |
| 16 static const LogLevel DEBUG = const LogLevel._('Debug', 0); |
| 17 |
| 18 final String name; |
| 19 final int level; |
| 20 |
| 21 const LogLevel._(this.name, this.level); |
| 22 |
| 23 String toString() => name; |
| 24 } |
| 25 |
| 26 abstract class Logging { |
| 27 void critical(String string, {DateTime timestamp}) { |
| 28 log(LogLevel.CRITICAL, string, timestamp: timestamp); |
| 29 } |
| 30 |
| 31 void error(String string, {DateTime timestamp}) { |
| 32 log(LogLevel.ERROR, string, timestamp: timestamp); |
| 33 } |
| 34 |
| 35 void warning(String string, {DateTime timestamp}) { |
| 36 log(LogLevel.WARNING, string, timestamp: timestamp); |
| 37 } |
| 38 |
| 39 void info(String string, {DateTime timestamp}) { |
| 40 log(LogLevel.INFO, string, timestamp: timestamp); |
| 41 } |
| 42 |
| 43 void debug(String string, {DateTime timestamp}) { |
| 44 log(LogLevel.DEBUG, string, timestamp: timestamp); |
| 45 } |
| 46 |
| 47 void log(LogLevel level, String message, {DateTime timestamp}); |
| 48 |
| 49 Future flush(); |
| 50 } |
| 51 |
| 52 /** |
| 53 * Register a new [Logging] object. |
| 54 * |
| 55 * Calling this outside of a service scope or calling it more than once inside |
| 56 * the same service scope will result in an error. |
| 57 * |
| 58 * See the `package:gcloud/service_scope.dart` library for more information. |
| 59 */ |
| 60 void registerLoggingService(Logging service) { |
| 61 ss.register(#_appengine.logging, service); |
| 62 } |
| 63 |
| 64 /** |
| 65 * The logging service. |
| 66 * |
| 67 * Request handlers will be run inside a service scope which contains the |
| 68 * modules service. |
| 69 */ |
| 70 Logging get loggingService => ss.lookup(#_appengine.logging); |
OLD | NEW |