logEvent method
Implementation
Future<void> logEvent({
String? message,
Map<String, Object?>? args,
GoogleLoggerSeverity? severity = GoogleLoggerSeverity.DEFAULT,
Map<String, String>? labels,
LogEntryOperation? operation,
String? functionName,
String? fileName,
}) async {
try {
final Map<String, Object> params = {};
if (message is String) {
params['message'] = message;
}
if (args is Map<String, Object?>) {
args.forEach((key, value) {
if (value != null) {
params[key] = value.toString();
}
});
}
final logEntry = LogEntry(
logName: 'projects/$projectId/logs/flutter-log',
jsonPayload: params,
severity: severity.toString().split('.').last,
operation: operation,
sourceLocation: LogEntrySourceLocation(
function: functionName,
file: fileName,
),
resource: MonitoredResource(type: 'global'),
labels: labels);
final req = WriteLogEntriesRequest(entries: [logEntry]);
_logger?.entries.write(req);
} catch (err) {
debugPrint(err.toString());
}
}