2012-10-18 07:35:09 +02:00
EXAMPLE USAGE OF G2LOG
=======================
2012-10-18 07:44:53 +02:00
Optional to use either streaming or printf-like syntax
2012-10-18 15:52:08 +02:00
LOG(INFO) << "As Easy as ABC or " << 123;
2012-10-18 07:35:09 +02:00
or
LOGF(WARNING, "Printf-style syntax is also %s", "available");
Conditional logging
int less = 1; int more = 2
2012-10-18 15:52:08 +02:00
LOG_IF(INFO, (less<more)) <<"If [true], then this text will be logged";
// or with printf-like syntax
2012-10-18 07:35:09 +02:00
LOGF_IF(INFO, (less<more), "if %d<%d then this text will be logged", less,more);
Design-by-Contract
2012-10-18 15:52:08 +02:00
CHECK(false) will trigger a "fatal" message. It will be logged, and then the
application will exit.
CHECK(less != more); // not FATAL
CHECK(less > more) << "CHECK(false) triggers a FATAL message");
2012-10-18 07:35:09 +02:00
WHAT IS G2LOG?
====================
2012-10-18 07:39:21 +02:00
In depth information can be found at
http://www.codeproject.com/Articles/288827/g2log-An-efficient-asynchronous-logger-using-Cplus
2012-10-18 07:35:09 +02:00
Or just read the short summary below:
-------------------------------------
2012-10-18 07:39:21 +02:00
G2log is an asynchronous, "crash safe" logger and design-by-contract library.
What this means in practice is that
2012-10-18 07:35:09 +02:00
2012-10-18 07:39:21 +02:00
1. All the slow I/O disk access is done in a background thread. This ensures that the
2012-10-18 15:52:08 +02:00
other parts of the software can immediately continue with their work after making a
log entry.
2012-10-18 07:39:21 +02:00
2. g2log provides logging, Design-by-Contract [#CHECK], and flush of log to file at
shutdown. Buffered logs will be written to file before the application shuts down.
2012-10-18 07:35:09 +02:00
3. It is thread safe, so using it from multiple threads is completely fine.
2012-10-18 15:52:08 +02:00
4. It is CRAsH SAFE, in that it will catch certain fatal signals, so if your application crashes due to, say a segmentation fault, SIGSEGV, or some other fatal
signals it will log and save to file this crash and all previously buffered log
entries before exiting.
2012-10-18 07:39:21 +02:00
2012-10-18 07:35:09 +02:00
2012-10-18 15:52:08 +02:00
5. It is cross platform. For now, tested on Windows7 and Ubuntu
2012-10-18 07:35:09 +02:00
2012-10-18 15:52:08 +02:00
6. On Ubuntu a caught fatal signal will generate a stack dump to the log. This is
not yet available on Windows due to the platforms complexity when traversing the
stack. Stack dump on Windows will be released later and a beta is available on
request.
2012-10-18 07:35:09 +02:00
2012-10-18 07:39:21 +02:00
7. G2log is used in commercial products as well as hobby projects since early 2011.
2012-10-18 15:52:08 +02:00
The code is given for free as public domain. This gives the option to change, use,
and do whatever with it, no strings attached.
2012-10-18 07:35:09 +02:00
8. The stable version of g2log is available at https://bitbucket.org/KjellKod/g2log
The in-development g2log where new features are tried out is available at
2012-10-18 15:52:08 +02:00
https://bitbucket.org/KjellKod/g2log-dev ongoing and released features can be
seen at https://bitbucket.org/KjellKod/g2log-dev/wiki/Home
2012-10-18 07:35:09 +02:00
2012-10-14 01:54:56 +02:00
LATEST CHANGES
=====================
2012, Oct 14th
2012-10-18 07:40:49 +02:00
* Complete threadsafe use of localtime for timestamp. (see code: g2time)
* Runtime change of filename, request of filename. (see code g2logwoker g2future)
* Tested on
x86 Windows7: Visual Studio 2012 Desktop Express
x86 Ubuntu 11.04: gcc 4.7.3
x64 Ubuntu 12...: gcc 4.7.2
x64 Windows7: Visual Studio 2012 Professional
2012-10-18 15:52:08 +02:00
NOTE: It does NOT work with "Visual Studio 11 Beta" (not as C++11 compliant
as VS2012)
2012-10-14 01:54:56 +02:00
2011-11-05 17:36:07 +01:00
HOW TO BUILD
===================
This g2log is a snapshot from KjellKod repository.
It contains what is needed to build example, unit test and performance test of g2log.
2012-06-02 22:04:28 +02:00
justthread C++11 thread library is no longer needed.
2012-10-18 15:52:08 +02:00
* On Windows it is enough to use Visual Studio 11 (2012).
* On Linux it is enough to use gcc4.7.2.
2012-06-02 22:04:28 +02:00
2012-10-18 15:52:08 +02:00
The CMakeFile.txt is updated to reflect that, the justthread parts is commented
away in case someone still needs that.
If you want to integrate g2log in your own software you need the files under
g2log/src
2012-06-02 22:04:28 +02:00
2011-11-05 17:36:07 +01:00
2011-11-17 11:47:52 +01:00
BUILDING g2log:
2011-11-05 17:36:07 +01:00
-----------
2012-06-02 22:04:28 +02:00
The default is to build an example binary 'g2log-FATAL'
2011-11-17 11:47:52 +01:00
I suggest you start with that, run it and view the created log also.
If you are interested in the performance or unit tests then you can
2012-10-18 15:52:08 +02:00
enable the creation of them in the g2log/CMakeLists.txt file. See that file for
more details
2011-11-17 11:47:52 +01:00
2011-11-17 11:57:37 +01:00
--- Building on Linux ---
2011-11-05 17:36:07 +01:00
cd g2log
mkdir build
cd build
cmake ..
make
2011-11-17 11:57:37 +01:00
--- Building on Windows ---
2012-06-02 22:04:28 +02:00
Please use the Visual Studio 11 (2012) command prompt "Developer command prompt"
2011-11-17 11:57:37 +01:00
cd g2log
mkdir build
cd build
2012-06-02 22:04:28 +02:00
cmake -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 11" ..
msbuild g2log_by_kjellkod.sln /p:Configuration=Release
Release\g2log-FATAL.exe
2011-11-05 17:36:07 +01:00
CONTENTS
===========================
3rdParty -- gtest, glog.
-----------------------
Both are needed to compile the unit test and the logger comparison tests
2011-11-22 00:04:02 +01:00
Gtest must be unpacked before used, but it IS included by the CMake and you don't need to do install or compile it in any other way than through the g2log cmake setup.
2011-11-05 17:36:07 +01:00
glog is not included and must be installed if you want to run the comparison tests
2011-11-17 11:47:52 +01:00
About the Active Object
2011-11-05 17:36:07 +01:00
--------------------
2012-10-18 15:52:08 +02:00
Is made with standard C++ components with the help of the latest C++11 and std::thread features (thanks to justthread). For more details see
www.kjellkod.cc/active-object-with-cpp0x.
An example is provided. Other examples on pre C++0x Active Objects can also be
found at www.kjellkod.cc (code page)
2011-11-05 17:36:07 +01:00
2012-10-18 15:52:08 +02:00
If you like it (or not) it would be nice with some feedback. That way I can
improve g2log and it is also nice to see if someone is using it. If you have
ANY questions or problems please do not hesitate in contacting me on my blog
http://kjellkod.wordpress.com/2011/11/17/kjellkods-g2log-vs-googles-glog-are-asynchronous-loggers-taking-over/
2011-11-17 22:58:40 +01:00
or at <Hedstrom at KjellKod dot cc>
2011-11-05 17:36:07 +01:00
2011-11-17 11:57:37 +01:00
Good luck :)
2011-11-05 17:36:07 +01:00
2011-11-17 11:57:37 +01:00
Cheers
Kjell (a.k.a. KjellKod)