Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analysis.logger; | 5 library analysis.logger; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/engine.dart'; | 7 import 'package:analyzer/src/generated/engine.dart'; |
| 8 import 'package:analyzer/src/generated/java_engine.dart'; | 8 import 'package:analyzer/src/generated/java_engine.dart'; |
| 9 import 'package:logging/logging.dart' as logging; | 9 import 'package:logging/logging.dart' as logging; |
| 10 | 10 |
| 11 typedef LogMessageHandler(String message, CaughtException exception); | |
| 12 | |
| 11 /** | 13 /** |
| 12 * Instances of the class [AnalysisLogger] translate from the analysis engine's | 14 * Instances of the class [AnalysisLogger] translate from the analysis engine's |
| 13 * API to the logging package's API. | 15 * API to the logging package's API. |
| 14 */ | 16 */ |
| 15 class AnalysisLogger implements Logger { | 17 class AnalysisLogger implements Logger { |
| 16 /** | 18 /** |
| 17 * The underlying logger that is being wrapped. | 19 * The underlying logger that is being wrapped. |
| 18 */ | 20 */ |
| 19 final logging.Logger baseLogger = new logging.Logger('analysis.server'); | 21 final logging.Logger baseLogger = new logging.Logger('analysis.server'); |
| 20 | 22 |
| 21 AnalysisLogger() { | 23 /** |
| 24 * This handler is invoked for every [logError] invocation. | |
| 25 */ | |
| 26 final LogMessageHandler onError; | |
| 27 | |
| 28 AnalysisLogger({this.onError}) { | |
|
Brian Wilkerson
2015/11/12 14:52:51
I'm not sure we need this level of flexibility. Se
scheglov
2015/11/12 16:15:56
Done.
| |
| 22 logging.Logger.root.onRecord.listen((logging.LogRecord record) { | 29 logging.Logger.root.onRecord.listen((logging.LogRecord record) { |
| 23 AnalysisEngine.instance.instrumentationService.logLogEntry( | 30 AnalysisEngine.instance.instrumentationService.logLogEntry( |
| 24 record.level.name, | 31 record.level.name, |
| 25 record.time, | 32 record.time, |
| 26 record.message, | 33 record.message, |
| 27 record.error, | 34 record.error, |
| 28 record.stackTrace); | 35 record.stackTrace); |
| 29 }); | 36 }); |
| 30 } | 37 } |
| 31 | 38 |
| 32 @override | 39 @override |
| 33 void logError(String message, [CaughtException exception]) { | 40 void logError(String message, [CaughtException exception]) { |
| 41 if (onError != null) { | |
| 42 onError(message, exception); | |
| 43 } | |
| 34 if (exception == null) { | 44 if (exception == null) { |
| 35 baseLogger.severe(message); | 45 baseLogger.severe(message); |
| 36 } else { | 46 } else { |
| 37 baseLogger.severe(message, exception.exception, exception.stackTrace); | 47 baseLogger.severe(message, exception.exception, exception.stackTrace); |
| 38 } | 48 } |
| 39 } | 49 } |
| 40 | 50 |
| 41 @override | 51 @override |
| 42 void logError2(String message, Object exception) { | 52 void logError2(String message, Object exception) { |
| 43 baseLogger.severe(message, exception); | 53 baseLogger.severe(message, exception); |
| 44 } | 54 } |
| 45 | 55 |
| 46 @override | 56 @override |
| 47 void logInformation(String message, [CaughtException exception]) { | 57 void logInformation(String message, [CaughtException exception]) { |
| 48 if (exception == null) { | 58 if (exception == null) { |
| 49 baseLogger.info(message); | 59 baseLogger.info(message); |
| 50 } else { | 60 } else { |
| 51 baseLogger.info(message, exception.exception, exception.stackTrace); | 61 baseLogger.info(message, exception.exception, exception.stackTrace); |
| 52 } | 62 } |
| 53 } | 63 } |
| 54 | 64 |
| 55 @override | 65 @override |
| 56 void logInformation2(String message, Object exception) { | 66 void logInformation2(String message, Object exception) { |
| 57 baseLogger.info(message, exception); | 67 baseLogger.info(message, exception); |
| 58 } | 68 } |
| 59 } | 69 } |
| OLD | NEW |