Skip to content

Commit

Permalink
Adds EoL to example (#642)
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Agüero <[email protected]>
  • Loading branch information
caguero authored Oct 17, 2024
1 parent 6b19c9e commit db92b43
Showing 1 changed file with 20 additions and 19 deletions.
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;
}

0 comments on commit db92b43

Please sign in to comment.