Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Agüero <caguero@openrobotics.org>
  • Loading branch information
caguero committed Aug 16, 2024
1 parent c55f162 commit e598a92
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 1,207 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ set(GZ_MATH_VER ${gz-math8_VERSION_MAJOR})

#--------------------------------------
# Find gz-utils
gz_find_package(gz-utils3 REQUIRED)
gz_find_package(gz-utils3 REQUIRED COMPONENTS log)
set(GZ_UTILS_VER ${gz-utils3_VERSION_MAJOR})

gz_find_package(spdlog REQUIRED)
Expand Down
35 changes: 23 additions & 12 deletions examples/console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,41 @@
* limitations under the License.
*
*/
#include <gz/common/ConsoleNew.hh>
#include <filesystem>
#include <gz/common/Console.hh>

int main(int argc, char **argv)
{
// Default verbosity is 1, only error messages show
gzdbg << "This is a debug message";
gzmsg << "This is an informational message";
gzdbg << "This is a debug message";
gzmsg << "This is an informational message";
gzwarn << "This is a warning";
gzerr << "This is an error";
gzerr << "This is an error";
gzcrit << "This is a critical error";

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

gz::common::ConsoleNew c("gz_tmp");
c.SetLogDestination("/tmp/my_test_log.txt");
auto logger = c.Logger();
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");

gz::common::Console::Init(logDir / "tmp3", logFile);
gzerr << "Error 1";
gzerr << "Error 2";
gzerr << "Directory: " << gz::common::Console::Directory();
gz::common::Console::Close();
gzerr << "Error 3";

return 0;
}
Loading

0 comments on commit e598a92

Please sign in to comment.