https://github.com/hoytech/logdefer-cxx
Log::Defer C++11 implementation
https://github.com/hoytech/logdefer-cxx
Last synced: 3 months ago
JSON representation
Log::Defer C++11 implementation
- Host: GitHub
- URL: https://github.com/hoytech/logdefer-cxx
- Owner: hoytech
- License: bsd-2-clause
- Created: 2014-05-22T05:34:27.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-01-12T21:26:01.000Z (over 10 years ago)
- Last Synced: 2025-01-25T05:42:49.278Z (5 months ago)
- Language: C++
- Homepage:
- Size: 165 KB
- Stars: 0
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
LogDefer-CXX
============Description
-----------Log::Defer C++11 implementation
This is a logger implementation of the [Log::Defer](https://metacpan.org/pod/Log::Defer) format in C++11.
It uses Kazuho Oku's [picojson](https://github.com/kazuho/picojson/) library to serialise messages.
Usage
-----The usage tries to be as similar as possible to the reference Perl implementation (although it assumes JSON where the perl one doesn't).
The basic usage is to create a new `LogDefer` object. The constructor requires one argument: A lambda callback function. This callback will be invoked when the `LogDefer` object's destructor is called. That is, when it goes out of scope or when the last reference to it has been destroyed.
Here is a simple example:
{
LogDefer logger([](const std::string &json) {
// Normally we'd write this to a file/syslog/etc
std::cout << json << std::endl;
});logger.info("Processed some stuff");
logger.warn("some warning!");} // <-- logger goes out of scope so callback is invoked now
Todo
----* Timers (will need to use weak pointers)
* Data (will need to expose picojson interface)
* Make sure that the desctructor can't throw exceptionsSee Also
--------The [Log::Defer](https://metacpan.org/pod/Log::Defer) perl reference implementation
Michael Pucyk's [LogDefer Python module](https://github.com/mikep/LogDefer)
One way to display these logs is the [log-defer-viz](https://metacpan.org/pod/log-defer-viz) visualisation tool
Author and Copyright
--------------------Copyright (c) 2014 Doug Hoyte
This library is distributed under the 2-clause BSD license so you can basically do whatever you want with it.