Skip to content

chore: polishing. put basic usage info to stdout using one call to a void messing lines #5019

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

Merged
merged 2 commits into from
Apr 28, 2025

Conversation

vyavdoshenko
Copy link
Contributor

@vyavdoshenko vyavdoshenko commented Apr 28, 2025

Sometimes we can see the lines being messed with at the start. This change fixes that.

The example from Grafana log:
Screenshot 2025-04-28 at 16 17 35

for (const auto& dir : google::GetLoggingDirectories()) {
const string_view maybe_slash = absl::EndsWith(dir, "/") ? "" : "/";
std::cout << dir << maybe_slash << "dragonfly.*\n";
output += std::string(dir) + std::string(maybe_slash) + "dragonfly.*\n";
Copy link
Contributor

Choose a reason for hiding this comment

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

absl::StrCat

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

std::cout << " @@ \n";
std::cout << " .. \n";
std::cout << "* Logs will be written to the first available of the following paths:\n";
std::string output =
Copy link
Contributor

Choose a reason for hiding this comment

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

string_view

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It changes below.

Copy link
Contributor

Choose a reason for hiding this comment

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

it's fine to use std::string. Who cares 🤷 Same for absl:: variants. Just commented them for completeness

for (const auto& dir : google::GetLoggingDirectories()) {
const string_view maybe_slash = absl::EndsWith(dir, "/") ? "" : "/";
std::cout << dir << maybe_slash << "dragonfly.*\n";
output += std::string(dir) + std::string(maybe_slash) + "dragonfly.*\n";
Copy link
Contributor

Choose a reason for hiding this comment

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

There is also absl::StrCat or absl::StrAppend

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

"* For the available flags type dragonfly [--help | --helpfull]\n"
"* Documentation can be found at: https://www.dragonflydb.io/docs\n";

std::cout << output;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
std::cout << output;
std::cout << output << 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.

better flush the output buffer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to avoid more than one <<. This is the main idea of this change.

Copy link
Contributor

Choose a reason for hiding this comment

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

But if you don't flush the internal io buffer, how do you know it gets printed ? cout uses buffered io so unless you flush with std::endl you don't know if it actually reached the output/terminal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added explicit flush. It solves the instant write. But the main idea was to avoid breaking lines and messing them up.

@kostasrim
Copy link
Contributor

Can you plz elaborate:

Sometimes we can see the lines being messed with at the start. This change fixes that.

@vyavdoshenko
Copy link
Contributor Author

Can you plz elaborate:

I updated the description with the provided example.

@vyavdoshenko vyavdoshenko merged commit 23d310b into main Apr 28, 2025
10 checks passed
@vyavdoshenko vyavdoshenko deleted the bobik/dflogo_basic_usage_one_chunk branch April 28, 2025 14:45
@vyavdoshenko vyavdoshenko self-assigned this May 9, 2025
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