-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RSDK-7769, RSDK-7770 Add AppRobotClient and LogOutput dial option #233
Changes from 3 commits
8f81f8e
7025d37
e507d01
a5dd1db
a9db4d7
bb5b07e
61af6a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:logger/logger.dart'; | ||
import 'package:viam_sdk/src/gen/google/protobuf/timestamp.pb.dart'; | ||
|
||
import '../gen/app/v1/robot.pbgrpc.dart'; | ||
import '../gen/common/v1/common.pb.dart'; | ||
|
||
const flutterSdkLoggerName = 'flutter-sdk'; | ||
|
||
/// gRPC client for connecting to app's RobotService. | ||
/// | ||
/// All calls must be authenticated. | ||
class AppRobotClient { | ||
final RobotServiceClient _client; | ||
|
||
AppRobotClient(this._client); | ||
|
||
/// Log the OutputEvent to app with the given partId. | ||
Future<void> log(String partId, OutputEvent event) async { | ||
late String level; | ||
switch (event.level) { | ||
case Level.debug: | ||
level = 'debug'; | ||
case Level.warning: | ||
level = 'warning'; | ||
case Level.error: | ||
level = 'error'; | ||
default: | ||
// Assume info level if none of the above. | ||
level = 'info'; | ||
} | ||
|
||
// Assume log was just output (OutputEvent has no timestamp field). | ||
final Timestamp protoTs = Timestamp.fromDateTime(DateTime.now()); | ||
|
||
// Join lines with '\n' and suffix with '\n'. | ||
final String message = '${event.lines.join('\n')}\n'; | ||
|
||
final LogEntry entry = | ||
LogEntry(host: '$partId-$flutterSdkLoggerName', level: level, time: protoTs, loggerName: flutterSdkLoggerName, message: message); | ||
final request = LogRequest(id: partId, logs: [entry]); | ||
await _client.log(request); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,13 @@ import '../utils.dart'; | |
import 'grpc/grpc_or_grpcweb_channel.dart'; | ||
import 'web_rtc/web_rtc_client.dart'; | ||
|
||
final _logger = Logger(printer: PrettyPrinter(printTime: true)); | ||
Logger newDialLogger(LogOutput? output) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you make this private as well please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. |
||
// Use a SimplePrinter, as flutter dial logs from the RC app are sent to app.viam.com, | ||
// and pretty-printed logs are overly formatted. | ||
return Logger(output: output, printer: SimplePrinter(colors: false)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're curious what the logs look like on app. For connection success (latest->oldest):
For connection failure (latest->oldest):
|
||
} | ||
|
||
var _logger = newDialLogger(null); | ||
|
||
/// Describes the behavior for connecting to a robot | ||
class DialOptions { | ||
|
@@ -56,6 +62,9 @@ class DialOptions { | |
|
||
/// Timeout is the timeout for dial. | ||
Duration timeout = Duration(seconds: 10); | ||
|
||
/// If specified, a custom log output for dial logs. | ||
LogOutput? logOutput; | ||
} | ||
|
||
/// The credentials used for connecting to the robot | ||
|
@@ -113,9 +122,11 @@ class DialWebRtcOptions { | |
|
||
/// Connect to a robot at the provided address with the given options | ||
Future<ClientChannelBase> dial(String address, DialOptions? options, String Function() sessionCallback) async { | ||
final opts = options ?? DialOptions(); | ||
_logger = newDialLogger(opts.logOutput); | ||
|
||
final dialSW = Stopwatch()..start(); | ||
_logger.i('Connecting to address $address'); | ||
final opts = options ?? DialOptions(); | ||
|
||
if (opts.attemptMdns) { | ||
final mdnsSW = Stopwatch()..start(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we allow the host/loggerName to be user defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah probably a good idea 👍🏻 .