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

Experimenting with spdlog #615

Merged
merged 38 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
74cb85b
Experimenting with spdlog
mjcarroll Jul 2, 2024
53e9436
Additional local changes
mjcarroll Jul 3, 2024
578ede7
Tweaks
caguero Jul 3, 2024
55fa79d
Merge
caguero Jul 3, 2024
d24b2cb
Tweaks
caguero Jul 5, 2024
644f81b
Tweaks
caguero Jul 5, 2024
9a318b6
Tests
caguero Jul 12, 2024
e5e2228
package.xml
caguero Jul 12, 2024
4a85d7f
Tweak
caguero Jul 12, 2024
7d7ea1f
CI
caguero Jul 12, 2024
c55f162
More API functions
caguero Jul 29, 2024
e598a92
Refactor
caguero Aug 16, 2024
215e1d2
Restore example
caguero Aug 16, 2024
28f70ad
Tweak example
caguero Aug 16, 2024
92470e8
Tweak
caguero Aug 16, 2024
bdb737f
Merge branch 'main' into mjcarroll/spdlog
caguero Aug 16, 2024
8ee5852
Tweak
caguero Aug 16, 2024
7f8b982
Merge branch 'mjcarroll/spdlog' of github.com:gazebosim/gz-common int…
caguero Aug 16, 2024
cb8c022
Tweak
caguero Aug 21, 2024
627172c
Tests
caguero Aug 21, 2024
6250d2b
Merge branch 'main' into mjcarroll/spdlog
caguero Aug 21, 2024
7ee49ba
Tests
caguero Aug 21, 2024
a5a6a3f
Test tweak
caguero Aug 22, 2024
bde8c03
Fix test
caguero Aug 22, 2024
b7bb983
utils3-log
caguero Aug 23, 2024
d905f2a
One more test
caguero Aug 23, 2024
1489a1f
One more test
caguero Aug 23, 2024
624aa35
Win
caguero Aug 23, 2024
f520b6d
windows test
caguero Aug 23, 2024
0b479c3
Test
caguero Aug 26, 2024
b105faa
Tweak
caguero Aug 26, 2024
f1db533
Remove libgts
caguero Aug 26, 2024
27633b7
Migration
caguero Aug 26, 2024
94d0cba
Merge branch 'main' into mjcarroll/spdlog
caguero Aug 28, 2024
f0887d2
Use new SetConsoleSinkLevel API
azeey Aug 28, 2024
f3d168c
Restore defaults
caguero Aug 28, 2024
ab269e8
Note about removeAll on Windows
caguero Aug 28, 2024
12a8d61
Remove flushes and fix tests (#627)
azeey Aug 28, 2024
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
2 changes: 2 additions & 0 deletions .github/ci/packages.apt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ libgdal-dev
libgz-cmake4-dev
libgz-math8-dev
libgz-utils3-dev
libgz-utils3-log-dev
libspdlog-dev
libswscale-dev
libtinyxml2-dev
pkg-config
Expand Down
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})

#--------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ release will remove the deprecated code.

### Modifications

1. Logging has been heavily modified as we're relying on
[spdlog](https://github.com/gabime/spdlog). See
[example1](https://github.com/gazebosim/gz-utils/blob/gz-utils3/examples/log/main.cc)
and [example2]((https://github.com/gazebosim/gz-common/blob/gz-common6/examples/console.cc))
to learn how to access the internal spdlog logger and the global options.

The `gzdbg`, `gzmsg`, `gzlog`, `gzwarn` and `gzerr` macros should work the
same as previous versions but you now have two extra macros: `gzcrit` and
`gztrace` for logging critical errors and traces respectively.

`Console::SetVerbosity` only accepts values between 0 (critical errors only)
and 5 (all log messages). Other values don't have any effect.

1. Removed the `graphics` component's dependency on the GTS
(GNU Triangulated Surface) library which was used for doing triangulation
and CSG Boolean operation by the `MeshManager`. The Delaunay triangulation
Expand Down
45 changes: 33 additions & 12 deletions examples/console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,43 @@
* limitations under the License.
*
*/
#include <gz/common.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" << std::endl;
gzmsg << "This is an informational message" << std::endl;
gzwarn << "This is a warning" << std::endl;
gzerr << "This is an error" << std::endl;
// 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";

// Change verbosity to level 4, all messages show
gz::common::Console::SetVerbosity(4);
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;
// Change verbosity to level 5, 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";

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
Loading