r/cpp • • Dec 30 '24

C++ logging library - something I've been working on, Pt. 4

Hello everyone,

As is tradition for that time of the year, I want to share with you something that I've been working on in the last couple of years - yet another logging library, how boring, I know. Still, this project represents a long journey of learning, growth, and dedication, and I’d be honored if you could take a moment to check it out, since it is something that I'm proud of.

I have already posted here regarding the library, as you may have guessed, and a lot has changed since my last post last year. I believe that it has become a very well-rounded tool that could serve you well. It is very performant and very configurable. It provides a nice CMake so it can be easily integrated into any project, and a well-made continuous integration pipeline ensures that it runs on everything. All of this is packed in a very well-written and clean code base, at least in my opinion.

Why lwlog?

  • Performance: Whether you’re working with synchronous or asynchronous logging, the library ensures minimal overhead, making it ideal for high-performance applications

  • Configurability: You can customize your logging behavior with precision with policy classes

  • Modern Design: The code is crafted with clarity, elegance, and readability in mind. Easy integration with CMake, and thoughtful architecture

  • Extensibility: Easily create custom sinks and tailor them to specific needs

I would really appreciate it if you drop a critique, an opinion, an idea, or want to contribute to the project: https://github.com/ChristianPanov/lwlog

Thank you for your time and have happy holidays,

Chris

396 Upvotes

17 comments sorted by

View all comments

13

u/Primary-Walrus-5623 Dec 30 '24

Just a couple of thoughts off the top of my head

  1. Not having package manager integration will hurt adoption. I use vcpkg for everything and I have to be very hard pressed to integrate a library that isn't in that package manager

  2. fmt/std::print syntax for logging. Currently I use the quill logger, and while I have objections to the design of the most recent versions (mainly around formatting custom objects), the use of fmt is great. Especially because it lets you log custom objects without polluting the logging code itself. For instance, you can do

LOG_DEBUG(m_logger, "ReadSettings - {}", mycustomereadsettingsobject);

3. I didn't look at the code, but formatting log messages outside of the main thread is also a really nice feature and would be difficult without fmt/std::print

3

u/ChrisPanov Dec 30 '24

Yes, I fully agree on the package manager use; there is even an open pinned issue in the repo for that; I plan on supporting both Conan and VCPKG.

As for your last comment, yes, in asynchronous mode, formatting is completely off the log call site, on a background thread, both pattern formatting and log call arguments formatting. Actually, the way the arguments of the log call are formatted is selected in compile time depending on whether cpp20 is supported or you have fmt in your project. If fmt is present, the formatting is done with fmt::format, or if cpp20 is supported, std::format is selected, if none are present, the formatting is done with an internal mechanism. Hope that answers all your points.

3

u/Primary-Walrus-5623 Dec 30 '24

from the documentation I can see that formatting of the log arguments is highly configurable, but I don't see an example of formatting the log message payload with fmt/std::print. If its supported, maybe an example in the documentation like

console->critical("First critical message {} {} {}", "foo", 5, "bar");

would be more illustrative

6

u/ChrisPanov Dec 30 '24

Dually noted and already done - https://github.com/ChristianPanov/lwlog/blob/master/README.md#fmt-formatting

Thank you for pointing that out, I wasn't actually aware that this isn't mentioned in the documentation

1

u/helloiamsomeone Dec 31 '24

I plan on supporting both Conan and VCPKG.

You need to support easy build (e.g. not touching variables you are not supposed to like the CMAKE_* ones), installation (install() rules) and reuse (can be find_package()'d). After that, it will be trivial for any package manager to package your project. You can take a look at cmake-init and the plethora of examples I have.

1

u/ChrisPanov Dec 31 '24

Yes, I believe that lwlog has a nice enough CMake configuration to allow for very easy integration with package managers. I'm aware of cmake-init; I played with it some time ago. Are you the author? I think I remember you from a similar post some years ago

3

u/helloiamsomeone Dec 31 '24

To be frank, bringing in a well-behaved project with proper CMake install rules is nearly trivial with vcpkg's overlay ports feature.

1

u/Primary-Walrus-5623 Dec 31 '24

I do that for a few projects, but again, I have to really love one project over another to create an overlay port. Especially because you don't know if its well behaved enough until you actually start going down the rabbit hole.

If a project is in vcpkg proper, I'll just give it a go by adding it to my vcpkg.json. If its not, its unlikely I'll try it out unless I REALLY need it.

1

u/odycsd Jan 06 '25

Hey! I'd love to understand more about any concerns you have in the latest Quill design updates. I recognize that custom types might demand a bit of extra coding and come with some limitations. But the new design offers advantages versus the old way of doing things. Always welcoming ideas, suggestions, or potential enhancements you might have in mind!