3Hren / blackhole

Yet another logging library.
MIT License
201 stars 57 forks source link

feat: allow to use captured lambdas as args #162

Closed 3Hren closed 7 years ago

3Hren commented 7 years ago

This commit allows to perform lazy argument formatting using lambdas, that accepts std::ostream object. It’s not super-fast, due to usage of std::ostream inside libfmt, but it works!

For example:

logger.log(0, "[::] - esafronov [10/Oct/2000:13:55:36 -0700] 'GET {} HTTP/1.0' 200 2326",
    [&](std::ostream& stream) -> std::ostream& {
        return stream << boost::join(paths, "/");
    }
);

Performance difference:

log.lit[args: 1]        256     256 2668313      3.72516M items/s
log.lit[args: 1 (lazy)] 418     417 1712731      2.28555M items/s

@antmat @karitra PTAL, dragons may be there...

3Hren commented 7 years ago

Since noone reacted (except @shaitan) I'll merge this today when CI lands.

3Hren commented 7 years ago

ABI report: compatible.