diff --git a/examples/console.cc b/examples/console.cc index f86e2e0a..bc2a7143 100644 --- a/examples/console.cc +++ b/examples/console.cc @@ -19,23 +19,23 @@ 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"; @@ -43,14 +43,15 @@ int main(int argc, char **argv) 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; }