Skip to content
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

Adds EoL to console example #642

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions examples/console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,39 @@

int main(int argc, char **argv)
{
// Default verbosity is 3 (critical, error, warn and info messages show).
gztrace << "This is a trace message";
gzdbg << "This is a debug message";
gzmsg << "This is an informational message";
gzwarn << "This is a warning";
gzerr << "This is an error";
gzcrit << "This is a critical error";
// Default verbosity is level 1 (err).
gztrace << "This is a trace message" << std::endl;
gzdbg << "This is a debug message" << std::endl;
gzmsg << "This is an informational message" << std::endl;
gzwarn << "This is a warning" << std::endl;
gzerr << "This is an error" << std::endl;
gzcrit << "This is a critical error" << std::endl;

// Change verbosity to level 5, all messages show.
// Change verbosity to level 5 (trace), all messages show.
gz::common::Console::SetVerbosity(5);
gz::common::Console::SetPrefix("My prefix. ");
gztrace << "This is a trace message";
gzdbg << "This is a debug message";
gzmsg << "This is an informational message";
gzwarn << "This is a warning";
gzerr << "This is an error";
gzcrit << "This is a critical error";
gztrace << "This is a trace message" << std::endl;
gzdbg << "This is a debug message" << std::endl;
gzmsg << "This is an informational message" << std::endl;
gzwarn << "This is a warning" << std::endl;
gzerr << "This is an error" << std::endl;
gzcrit << "This is a critical error" << std::endl;

std::filesystem::path logDir = std::filesystem::temp_directory_path();
std::filesystem::path logFile = "my_log.txt";

gz::common::Console c("gz_tmp");
c.SetLogDestination(logDir / "tmp2" / logFile);
auto logger = c.RawLogger();
logger.log(spdlog::level::err, "Hello");
logger.log(spdlog::level::err, "Hello\n");

gz::common::Console::Init(logDir / "tmp3", logFile);
gzerr << "Error 1";
gzerr << "Error 2";
gzerr << "Directory: " << gz::common::Console::Directory();
gzerr << "Error 1" << std::endl;
gzerr << "Error 2" << std::endl;
gzerr << "Directory: " << gz::common::Console::Directory() << std::endl;
gz::common::Console::Close();
gzerr << "Error 3";
// We shouldn't see this line in the log.
gzerr << "Error 3" << std::endl;

return 0;
}
Loading