Skip to content

Conversation

@cookjosh
Copy link
Contributor

@cookjosh cookjosh commented Mar 7, 2025

add boilerplate methods to device class similar to synapse-python

* @param end_time_ns End time in nanoseconds since epoch (optional)
* @return std::vector<std::string> containing log entries
*/
[[nodiscard]] auto get_logs(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For both methods, could you return a science::Status -- its our convention for reporting any errors (rather than throwing)

You could either return a tuple [Status, string], or, more c++-like, add arguments at the end of each function's signature for outputs, e.g.
get_logs(const std::string& log_level, ..., std::vector<std::string>* output)

if (since_ms.has_value()) {
request.set_since_ms(since_ms.value());
} else {
if (start_time_ns.has_value()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

while we're here, mind checking that start_time_ns is less than end_time_ns, and if it's not, return an error science::status?

logs.push_back(entry.message());
}
} else {
std::cerr << "Error getting logs: " << status.error_message() << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't print an error (because consumers won't be able to turn these logs off) -- instead report this error message in a returned science::status (and preferably don't capitalize the first string so they're easier to chain)

* @return std::vector<std::string> containing the most recent log entries
*/
[[nodiscard]] auto tail_logs(
const std::string& log_level = "INFO",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a LogLevel enum or use the existing proto one rather than accepting raw strings.

I like the default value!

return logs;
}

auto Device::tail_logs(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm realizing that the gRPC client in this device class is sync, when we probably want async (whoops). Ideally a consumer could keep a 'tail_logs' call open & running while they make other device calls, but with this current implementation that's not possible. I'll add a backlog task to change the client from sync to async -- for now, lets not include this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants