#include <_Log_.h>
void Example() {
_Log_("A great number is: {}", 42);
// Or use any of the other macros of different log levels:
_Error_("Oh noes!");
_Debug_("Debugging...");
// Specify a level (default: trace)
_SetLogLevel_(warn);
// Specify a log file (default: console)
_LogToFile_("my.log");
}A simple logging interface for C++ libraries.
I truly don't care what logging library I'm using.
Just do it. Log the thing. Make it go, please.
Except sometimes I do care.
And in those scenarios, I want to be able to use my own logger. But use the same lazy
_Log_()syntax.As there are only a few really simple macros, it's really easy to completely override them with your own implementation.
_Log_(...)_Trace_(...)_Debug_(...)_Info_(...)_Warn_(...)_Error_(...)_Fatal_(...)_SetLogLevel_(...)_LogToFile_(...)If you only care about the
_Log_macro, your programs can:#include <_Log_/_Log_.h>And that will use the default
spdlogimplementation but the ONLY macro added to your program will be_Log_.And, of course, this makes it really easy to override:
#define _Log_(...) myLogger.log(__VA_ARGS__) #include <_Log_/_Log_.h>
add_repositories("MrowrLib https://github.com/MrowrLib/Packages.git")
add_requires("_Log_")
target("Example")
add_packages("_Log_")add_executable(Example main.cpp)
# Find _Log_ and link it to your target
find_package(_Log_ CONFIG REQUIRED)
target_link_libraries(Example PRIVATE _Log_::_Log_){
"dependencies": ["mrowr-log"]
}And if you want to use spdlog:
{
"dependencies": ["mrowr-log", "spdlog"]
}{
"default-registry": {
"kind": "git",
"repository": "https://github.com/microsoft/vcpkg.git",
"baseline": "670f6dddaafc59c5dfe0587a130d59a35c48ea38"
},
"registries": [
{
"kind": "git",
"repository": "https://github.com/MrowrLib/Packages.git",
"baseline": "6887c023180286b54b805f50ec33eab3f30e4818",
"packages": ["mrowr-log"]
}
]
}Update the default-registry baseline to the latest commit from https://github.com/microsoft/vcpkg
Update the MrowrLib/Packages baseline to the latest commit from https://github.com/MrowrLib/Packages
Searching across GitHub, there are many libraries which...
#include <_Log_.h>or#include <Log.h>- Have a
LoggingorLogclass or namespace - Have a
LogorLOGor_log_or_LOG_function or macro
Because almost all of my libraries use this library, I wanted to make sure that this library's names were very, very unlikely to conflict with other libraries.
Hence #include <_Log_.h> and _Log_ / _LogToFile_.
I couldn't find anyone using _Log_ (camel case) across GitHub.
You can safely use this in your own libraries.
I also don't like to "sign" my own work, so I didn't want something like
<Mrowr/Logging.h>
By default, _Log_ logs using spdlog to console (or file if you specify it).
If you want to disable all logging entirely:
#include <_Log_/Disable.h>Easy.
Just define _Log_ before including any library headers.
If a _Log_ macro is defined, then this library will use it.
Optionally also define
_LogToFile_(defaults to an empty macro)
and whichever log levels you want to implement (etc)
Use however, no attribution required.
BSD Zero Clause License (SPDX: 0BSD)
Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.