Skip to content

Commit

Permalink
Make the log example show file source location
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Agüero <[email protected]>
  • Loading branch information
caguero committed Sep 26, 2024
1 parent a70e742 commit 59e54e5
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions examples/log/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <filesystem>
#include <gz/utils/log/Logger.hh>

#define sourceLocation {__FILE__, __LINE__, ""}

//////////////////////////////////////////////////
int main(int argc, char** argv)
{
Expand All @@ -27,11 +29,12 @@ int main(int argc, char** argv)
std::filesystem::path logDir = std::filesystem::temp_directory_path();
std::filesystem::path logFile = "my_log.txt";
std::filesystem::path logPath = logDir / logFile;

logger.SetLogDestination(logPath);
logger.RawLogger().trace("trace\n");
logger.RawLogger().info("info\n");
logger.RawLogger().warn("warn\n");
logger.RawLogger().error("error\n");
logger.RawLogger().critical("critical\n");

logger.RawLogger().log(sourceLocation, spdlog::level::trace, "trace\n");
logger.RawLogger().log(sourceLocation, spdlog::level::debug, "debug\n");
logger.RawLogger().log(sourceLocation, spdlog::level::info, "info\n");
logger.RawLogger().log(sourceLocation, spdlog::level::warn, "warn\n");
logger.RawLogger().log(sourceLocation, spdlog::level::err, "error\n");
logger.RawLogger().log(sourceLocation, spdlog::level::critical, "critical\n");
}

0 comments on commit 59e54e5

Please sign in to comment.