Library for creating log files in C++ projects, licensed under zlib license. Tested with GCC, Clang and MSVC on Linux, BSD, Solaris and Windows operating systems.
You can use Logutil simply by copying logutil
directory to your desired location. Then in your project include the file logutil.hpp
with line pointing to its correct path, similar to this one:
#include "logutil/logutil.hpp"
Makefile is included in the repository and command make install
copies file logutil.hpp
to /usr/local/include/
directory and renames it to logutil
by default. Install path can be changed by editing variable DEST_PATH
in Makefile. It is done this way so Logutil can be used in projects by including it directly without specific path:
#include <logutil>
For opening file use function file_open
, then you are able to write strings to specified file with write
function.
Function file_close
closes the filehandle at the end.
Example:
logutil::file_open("filename.log");
logutil::write("Hello, World!");
logutil::file_close();
Alternatively, you can use only one function write_to_file
which takes care of opening and closing the filehandle automatically:
logutil::write_to_file("Hello, World!", "filename.log");
Logutil uses one filehandle for file operations: static std::fstream filehandle{};
. You can check whether this filehandle is open or not with function is_file_open
which returns either true or false.
If you need more detailed debugging and logging, you can use built-in function check_function
.
Example:
logutil::check_function(__FUNCTION__, __FILE__, __LINE__, "filename.log");
which should produce output similar to this one:
Error in Function __testfunc in file: test.cpp on line 20
If you need to clear the log file completely, you can use function:
logutil::file_clear("filename.log");
Current version of Logutil is set in various macros:
#define LOGUTIL_VERSION_MAJOR (int)
#define LOGUTIL_VERSION_MINOR (int)
#define LOGUTIL_VERSION_PATCH (int)
#define LOGUTIL_VERSION_STRING (str)
#define LOGUTIL_VERSION_MAKE (int)