Google Cloud Logging for Dart
NOTE: This is a community-supported project, meaning there is no official level of support. The code is not covered by any SLA or deprecation policy.
Feel free to open issues for bugs and feature requests.
A lightweight logging package for creating formatted logs suitable for Google Cloud Platform, specifically tailored for Google Cloud structured logging.
Usage
Using the StructuredLogger directly
import 'package:google_cloud_logging/google_cloud_logging.dart';
const _logger = StructuredLogger();
void main() {
_logger.info({'message': 'Processing item.', 'itemId': 'A-987'});
try {
throw Exception('Failed to connect to DB');
} catch (error, stack) {
_logger.error('Database connection failure - $error', stackTrace: stack);
}
}
Using StructuredLogger with package:logging
import 'package:google_cloud_logging/google_cloud_logging.dart';
import 'package:logging/logging.dart';
final _logger = Logger('my-service');
void main() {
// Configure the standard logger with StructuredLogger.
Logger.root.onRecord.listen(const StructuredLogger().handleLogRecord);
Logger.root.level = Level.ALL;
_logger.info('Processing item.', {'itemId': 'A-987'});
try {
throw Exception('Failed to connect to DB');
} catch (error, stack) {
_logger.severe('Database connection failure - $error', error, stack);
}
}
Libraries
- google_cloud_logging
- General Google Cloud Logging.
- interop
- A library that allows framework developers to interoperate with Google Cloud Logging.