GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing cpp.libhunt.com — easyloggingpp Alternatives - C++ Logging | LibHunt easyloggingppC++ logging library. It is powerful, supports asynchronous low latency, extendable, light-weight, fast performing, thread and type safe and consists of many built-in features. It provides ability to write logs in your own customized format. It also provide support for logging your classes, third-party libraries, STL and third-party containers etc.
DISCONTINUED.
You can find some alternatives below.
Take the C++ Developer Survey
- About 6 minutes on the tools, libraries and AI you use with C++. You get the results by email.
Take the survey »
Popularity
8.0
Stable
Activity
5.4
Declining
Stars
3,881
Watchers
188
Forks
941
Last Commit
DescriptionTO MERGE : that lib is the same of Easylogging++
Code Quality Rank:
L3
Programming language: C++
License: MIT License
Tags:
Logging
Latest version: v9.97.0
easyloggingpp alternatives and similar libraries
Based on the "Logging" category.
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
Promo
www.saashub.com
* Code Quality Rankings and insights are calculated and provided by Lumnify.
Do you think we are missing an alternative of easyloggingpp or a related project? README﷽
Looking for maintainers!!Quick LinksTable of ContentsOverview Why yet another library Features at a glance Getting Started Download Quick Start Install (Optional) Setting Application Arguments Configuration Level Configure Using Configuration File Using el::Configurations Class Using In line Configurations Default Configurations Global Configurations Logging Format Specifiers Date/Time Format Specifiers Custom Format Specifiers Logging Flags Application Arguments Configuration Macros Reading Configurations Logging Basic Conditional Logging Occasional Logging printf Like Logging Network Logging Verbose Logging Basic Conditional and Occasional Verbose Level Check If Verbose Logging Is On VModule Registering New Loggers Unregister Loggers Populating Existing Logger IDs Sharing Logging Repository Extra Features Performance Tracking Conditional Performance Tracking Make Use of Performance Tracking Data Log File Rotating Crash Handling Installing Custom Crash Handlers Stacktrace Multi-threading CHECK Macros Logging perror() Using Syslog STL Logging Supported Templates Qt Logging Boost Logging wxWidgets Logging Extending Library Logging Your Own Class Logging Third-party Class Manually Flushing and Rolling Log Files Log Dispatch Callback Logger Registration Callback Asynchronous Logging Helper Classes Contribution Submitting Patches Reporting a Bug Compatibility Build Matrix Licence Disclaimer OverviewEasylogging++ is single header efficient logging library for C++ applications. It is extremely powerful, highly extendable and configurable to user's requirements. It provides ability to write your own sinks (via featured referred as This manual is for Easylogging++ v9.96.7. For other versions please refer to corresponding release on github.
Why yet another libraryIf you are working on a small utility or large project in C++, this library can be handy. Its based on single header and only requires to link to single source file. (Originally it was header-only and was changed to use source file in issue #445. You can still use header-only in v9.89). This library has been designed with various thoughts in mind (i.e, portability, performance, usability, features and easy to setup). Why yet another library? Well, answer is pretty straight forward, use it as you wrote it so you can fix issues (if any) as you go or raise them on github. In addition to that, I personally have not seen any logging library based on single-header with such a design where you can configure on the go, extend it to your needs and get fast performance. I have seen other single-header logging libraries for C++ but either they use external libraries, e.g, boost or Qt to support certain features like threading, regular expression or date etc. This library has everything built-in to prevent usage of external libraries, not that I don't like those libraries, in fact I love them, but because not all projects use these libraries, I couldn't take risk of depending on them. Features at a glanceEasylogging++ is feature-rich containing many features that both typical and advanced developer will require while writing a software;
Getting StartedDownloadDownload latest version from Latest Release For other releases, please visit releases page. If you application does not support C++11, please consider using v8.91. This is stable version for C++98 and C++03, just lack some features. Quick StartIn order to get started with Easylogging++, you can follow three easy steps:
Now compile using
That simple! Please note that Install (Optional)If you want to install this header system-wide, you can do so via:
Following options are supported by Easylogging++ cmake and you can turn these options on using
With that said, you will still need Alternatively, you can download and install easyloggingpp using the vcpkg dependency manager:
The easyloggingpp port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository. Setting Application ArgumentsIt is always recommended to pass application arguments to Easylogging++. Some features of Easylogging++ require you to set application arguments, e.g, verbose logging to set verbose level or vmodules (explained later). In order to do that you can use helper macro or helper class;
ConfigurationLevelIn order to start configuring your logging library, you must understand severity levels. Easylogging++ deliberately does not use hierarchical logging in order to fully control what's enabled and what's not. That being said, there is still option to use hierarchical logging using
ConfigureEasylogging++ is easy to configure. There are three possible ways to do so,
Using Configuration FileConfiguration can be done by file that is loaded at runtime by
Level name starts with a star (*) and ends with colon (:). It is highly recommended to start your configuration file with
Please do not use double-quotes anywhere in comment, you might end up in unexpected behaviour. Sample Configuration File
ExplanationConfiguration file contents in above sample is straightforward. We start with Usage
Using el::Configurations ClassYou can set configurations or reset configurations;
Using In line ConfigurationsInline configuration means you can set configurations in
Default ConfigurationsIf you wish to have a configuration for existing and future loggers, you can use Global Configurations
Logger ID starts with two dashes. Once you have written your global configuration file you can configure your all loggers (and register new ones) using single function;
Please note, it is not possible to register new logger using global configuration without defining its configuration. You must define at least single configuration. Other ways to register loggers are discussed in Logging section below. Logging Format SpecifiersYou can customize format of logging using following specifiers:
Date/Time Format SpecifiersYou can customize date/time format using following specifiers
Please note, date/time is limited to Custom Format SpecifiersYou can also specify your own format specifiers. In order to do that you can use
Logging FlagsForm some parts of logging you can set logging flags; here are flags supported:
You can set/unset these flags by using static
Application ArgumentsFollowing table will explain all command line arguments that you may use to define certain behaviour; You will need to initialize application arguments by using
Configuration MacrosSome of logging options can be set by macros, this is a thoughtful decision, for example if we have NOTE: All the macros can be defined in one of the following ways:
Reading ConfigurationsIf you wish to read configurations of certain logger, you can do so by using
LoggingLogging in easylogging++ is done using collection of macros. This is to make it easier for user and to prevent them knowing about unnecessary greater details of how things are done. BasicYou are provided with two basic macros that you can use in order to write logs:
There is another way to use same macro i.e, A quick example is here
Conditional LoggingEasylogging++ provides certain aspects of logging, one these aspects is conditional logging, i.e, log will be written only if certain condition fulfils. This comes very handy in some situations. Helper macros end with _IF;
Some examples:
Same macros are available for verbose logging with Occasional LoggingOccasional logging is another useful aspect of logging with Easylogging++. This means a log will be written if it's hit certain times or part of certain times, e.g, every 10th hit or 100th hit or 2nd hit.
Helper macros end with
Other Hit Counts Based LoggingThere are some other ways of logging as well based on hit counts. These useful macros are
Some examples:
|
| Macro Name | Description |
|---|---|
ELPP_DISABLE_PERFORMANCE_TRACKING |
Disables performance tracking |
ELPP_PERFORMANCE_MICROSECONDS |
Track up-to microseconds (this includes initializing of el::base::PerformanceTracker as well so might time not be 100% accurate) |
Notes:
Performance tracking uses performance logger (INFO level) by default unless el::base::PerformanceTracker is constructed manually (not using macro - not recommended). When configuring other loggers, make sure you configure this one as well.
In above examples, timerObj and timerBlkObj is of type el::base::type::PerformanceTrackerPtr. The checkpoint() routine of the el::base::PerformanceTracker can be accessed by timerObj->checkpoint() but not recommended as this will override behaviour of using macros, behaviour like location of checkpoint.
In order to access el::base::type::PerformanceTrackerPtr while in TIMED_BLOCK, you can use timerObj.timer
TIMED_BLOCK macro resolves to a single-looped for-loop, so be careful where you define TIMED_BLOCK, if for-loop is allowed in the line where you use it, you should have no errors.
You may be interested in python script to parse performance logs
If you want to enable performance tracking for certain conditions only, e.g. based on a certain verbosity level, you can use the variants TIMED_FUNC_IF or TIMED_SCOPE_IF.
A verbosity level example is given below
void performHeavyTask(int iter) {
// enable performance tracking for verbosity level 4 or higher
TIMED_FUNC_IF( timerObj, VLOG_IS_ON(4) );
// Some more heavy tasks
}
If you wish to capture performance tracking data right after it is finished, you can do so by extending el::PerformanceTrackingCallback.
In order to install this handler, use void Helpers::installPerformanceTrackingCallback<T>(const std::string& id). Where T is type of your handler. If you wish to uninstall a callback, you can do so by using Helpers::uninstallPerformanceTrackingCallback<T>(const std::string& id). See samples for details
DO NOT TRACK PERFORMANCE IN THIS HANDLER OR YOU WILL END UP IN INFINITE-LOOP
Easylogging++ has ability to roll out (or throw away / rotate) log files if they reach certain limit. You can configure this by setting Max_Log_File_Size. See Configuration section above.
Rollout checking happens when Easylogging++ flushes the log file, or, if you have added the flag el::LoggingFlags::StrictLogFileSizeCheck, at each log output.
This feature has its own section in this reference manual because you can do stuffs with the file being thrown away. This is useful, for example if you wish to back this file up etc.
This can be done by using el::Helpers::installPreRollOutCallback(const PreRollOutCallback& handler) where PreRollOutCallback is typedef of type std::function<void(const char*, std::size_t)>. Please note following if you are using this feature
There is a sample available that you can use as basis.
You should not log anything in this function. This is because logger would already be locked in multi-threaded application and you can run into dead lock conditions. If you are sure that you are not going to log to same file and not using same logger, feel free to give it a try.
Prerequisite: Define macro ELPP_FEATURE_CRASH_LOG
Easylogging++ provides ability to handle unexpected crashes for GCC compilers. This is active by default and can be disabled by defining macro ELPP_DISABLE_DEFAULT_CRASH_HANDLING. By doing so you are telling library not to handle any crashes. Later on if you wish to handle crash yourself, you can assign crash handler of type void func(int) where int is signal caught.
Following signals are handled;
ELPP_HANDLE_SIGABRT macro is defined)Stacktraces are not printed by default, in order to do so define macro ELPP_FEATURE_CRASH_LOG. Remember, stack trace is only available for GCC compiler.
Default handler and stack trace uses
defaultlogger.
Following are some useful macros that you can define to change the behaviour
| Macro Name | Description |
|---|---|
ELPP_DISABLE_DEFAULT_CRASH_HANDLING |
Disables default crash handling. |
ELPP_HANDLE_SIGABRT |
Enables handling SIGABRT. This is disabled by default to prevent annoying CTRL + C behaviour when you wish to abort. |
You can use your own crash handler by using el::Helpers::setCrashHandler(const el::base::debug::CrashHandler::Handler&);.
Make sure to abort application at the end of your crash handler using
el::Helpers::crashAbort(int). If you fail to do so, you will get into endless loop of crashes.
Here is a good example of your own handler
#include "easylogging++.h"
INITIALIZE_EASYLOGGINGPP
void myCrashHandler(int sig) {
LOG(ERROR) << "Woops! Crashed!";
// FOLLOWING LINE IS ABSOLUTELY NEEDED AT THE END IN ORDER TO ABORT APPLICATION
el::Helpers::crashAbort(sig);
}
int main(void) {
el::Helpers::setCrashHandler(myCrashHandler);
LOG(INFO) << "My crash handler!";
int* i;
*i = 0; // Crash!
return 0;
}
If you wish to log reason for crash you can do so by using
el::Helpers::logCrashReason(int, bool, const el::Level&, const char*). Following are default parameters for this function:bool stackTraceIfAvailable = false const el::Level& level = el::Level::Fatal const char* logger = "default"
Prerequisite: Define macro ELPP_FEATURE_CRASH_LOG
Easylogging++ supports stack trace printing for GCC compilers. You can print stack trace at anytime by calling el::base::debug::StackTrace(), formatting will be done automatically. Note, if you are using non-GCC compiler, you will end-up getting empty output.
Prerequisite: Define macro ELPP_THREAD_SAFE
Easylogging++ is thread-safe. By default thread-safety is disabled. You can enable it by defining ELPP_THREAD_SAFE otherwise you will see unexpected results. This is intentional to make library efficient for single threaded application.
Easylogging++ supports CHECK macros, with these macros you can quickly check whether certain condition fulfills or not. If not Easylogging++ writes FATAL log, causing application to stop (unless defined macro to prevent stopping application on fatal).
| CHECK Name | Notes + Example |
|---|---|
CHECK(condition) |
Checks for condition e.g, CHECK(isLoggedIn()) << "Not logged in"; |
CHECK_EQ(a, b) |
Equality check e.g, CHECK_EQ(getId(), getLoggedOnId()) << "Invalid user logged in"; |
CHECK_NE(a, b) |
Inequality check e.g, CHECK_NE(isUserBlocked(userId), false) << "User is blocked"; |
CHECK_LT(a, b) |
Less than e.g, CHECK_LT(1, 2) << "How 1 is not less than 2"; |
CHECK_GT(a, b) |
Greater than e.g, CHECK_GT(2, 1) << "How 2 is not greater than 1?"; |
CHECK_LE(a, b) |
Less than or equal e.g, CHECK_LE(1, 1) << "1 is not equal or less than 1"; |
CHECK_GE(a, b) |
Greater than or equal e.g, CHECK_GE(1, 1) << "1 is not equal or greater than 1"; |
CHECK_NOTNULL(pointer) |
Ensures pointer is not null. This function does not return anything |
CHECK_STREQ(str1, str2) |
C-string equality (case-sensitive) e.g, CHECK_STREQ(argv[1], "0") << "First arg cannot be 0"; |
CHECK_STRNE(str1, str2) |
C-string inequality (case-sensitive) e.g, CHECK_STRNE(username1, username2) << "Usernames cannot be same"; |
CHECK_STRCASEEQ(str1, str2) |
C-string inequality (case-insensitive) e.g, CHECK_CASESTREQ(argv[1], "Z") << "First arg cannot be 'z' or 'Z'"; |
CHECK_STRCASENE(str1, str2) |
C-string inequality (case-insensitive) e.g, CHECK_STRCASENE(username1, username2) << "Same username not allowed"; |
CHECK_BOUNDS(val, min, max) |
Checks that val falls under the min and max range e.g, CHECK_BOUNDS(i, 0, list.size() - 1) << "Index out of bounds"; |
Same versions of macros are available for
DEBUGonly mode, these macros start withD(for debug) followed by the same name. e.g,DCHECKto check only in debug mode (i.e, when_DEBUGis defined orNDEBUGis undefined)
Easylogging++ supports perror() styled logging using PLOG(LEVEL), PLOG_IF(Condition, LEVEL), and PCHECK() using default logger; and for custom logger use CPLOG(LEVEL, LoggerId), CPLOG_IF(Condition, LEVEL, LoggerId). This will append : log-error [errno] in the end of log line.
Prerequisite: Define macro ELPP_SYSLOG
Easylogging++ supports syslog for platforms that have syslog.h header. If your platform does not have syslog.h, make sure you do not define this macro or you will end up in errors. Once you are ready to use syslog, you can do so by using one of SYSLOG(LEVEL), SYSLOG_IF(Condition, LEVEL), SYSLOG_EVERY_N(n, LEVEL) and uses logger ID: syslog. If you want to use custom logger you can do so by using CSYSLOG(LEVEL, loggerId) or CSYSLOG_IF(Condition, LEVEL, loggerId) or CSYSLOG_EVERY_N(n, LEVEL, loggerId)
Syslog in Easylogging++ supports C++ styled streams logging, following example;
#include "easylogging++.h"
INITIALIZE_EASYLOGGINGPP
int main(void) {
ELPP_INITIALIZE_SYSLOG("my_proc", LOG_PID | LOG_CONS | LOG_PERROR, LOG_USER) // This is optional, you may not add it if you dont want to specify options
// Alternatively you may do
// el::SysLogInitializer elSyslogInit("my_proc", LOG_PID | LOG_CONS | LOG_PERROR, LOG_USER);
SYSLOG(INFO) << "This is syslog - read it from /var/log/syslog"
return 0;
}
Syslog support for Easylogging++ only supports following levels; each level is corresponded with syslog priority as following
Following levels are not supported and correspond to LOG_NOTICE: TRACE, whereas VERBOSE level is completely not supported
Prerequisite: Define macro ELPP_STL_LOGGING
As mentioned earlier, with easylogging++, you can log your STL templates including most containers. In order to do so you will need to define ELPP_STL_LOGGING macro. This enables including all the necessary headers and defines all necessary functions.
For performance, containers are limited to log maximum of 100 entries. This behaviour can be changed by changed header file (base::consts::kMaxLogPerContainer) but not recommended as in order to log, writer has to go through each entry causing potential delays. But if you are not really concerned with performance, you may change this value.
Following templates are supported as part of STL Logging; note: basic and primitive types e.g, std::string or long are not listed as they is supported anyway, following list only contains non-basic types e.g, containers or bitset etc.
| * | * | * | * |
|---|---|---|---|
| std::vector | std::list | std::deque | std::queue |
| std::stack | std::priority_queue | std::set | std::multiset |
| std::pair | std::bitset | std::map | std::multimap |
Some C++11 specific templates are supported by further explicit macro definitions; note these also need ELPP_STL_LOGGING
| Template | Macro Needed |
|---|---|
| std::array | ELPP_LOG_STD_ARRAY |
| std::unordered_map | ELPP_LOG_UNORDERED_MAP |
| std::unordered_multimap | ELPP_LOG_UNORDERED_MAP |
| std::unordered_set | ELPP_LOG_UNORDERED_SET |
| std::unordered_multiset | ELPP_LOG_UNORDERED_SET |
Standard manipulators are also supported, in addition std::stringstream is also supported.
Prerequisite: Define macro ELPP_QT_LOGGING
Easylogging++ has complete logging support for Qt core library. When enabled, this will include all the headers supported Qt logging. Once you did that, you should be good to go.
Following Qt classes and containers are supported by Easylogging++ v9.0+
| * | * | * | * | * | * |
|---|---|---|---|---|---|
QString |
QByteArray |
QLatin |
QList |
QVector |
QQueue |
QSet |
QPair |
QMap |
QMultiMap |
QHash |
QMultiHash |
QLinkedList |
QStack |
QChar |
q[u]int[64] |
Similar to STL logging, Qt containers are also limit to log 100 entries per log, you can change this behaviour by changing base::consts::kMaxLogPerContainer from header but this is not recommended as this was done for performance purposes.
Also note, if you are logging a container that contains custom class, make sure you have read Extending Library section below.
Prerequisite: Define macro ELPP_BOOST_LOGGING
Easylogging++ supports some of boost templates. Following table shows the templates supported.
| * | * |
|---|---|
boost::container::vector |
boost::container::stable_vector |
boost::container::map |
boost::container::flat_map |
boost::container::set |
boost::container::flat_set |
boost::container::deque |
boost::container::list |
boost::container::string |
Prerequisite: Define macro ELPP_WXWIDGETS_LOGGING
Easylogging++ supports some of wxWidgets templates.
Following table shows the templates supported.
| * | * | * | * | * | * |
|---|---|---|---|---|---|
wxString |
wxVector |
wxList |
wxString |
wxHashSet |
wxHashMap |
wxWidgets has its own way of declaring and defining some templates e.g, wxList where you use WX_DECLARE_LIST macro to declare a list.
In order to setup a container for logging that holds pointers to object, use ELPP_WX_PTR_ENABLED, otherwise if container holds actual object e.g, wxHashSet use ELPP_WX_ENABLED. For containers like wxHashMap because it contains value and pair, use ELPP_WX_HASH_MAP_ENABLED macro.
// wxList example
WX_DECLARE_LIST(int, MyList);
WX_DEFINE_LIST(MyList);
// Following line does the trick
ELPP_WX_PTR_ENABLED(MyList);
// wxHashSet example
WX_DECLARE_HASH_SET(int, wxIntegerHash, wxIntegerEqual, IntHashSet);
// Following line does the trick!
ELPP_WX_ENABLED(IntHashSet)
// wxHashMap example
WX_DECLARE_STRING_HASH_MAP(wxString, MyHashMap);
// Following line does the trick
ELPP_WX_HASH_MAP_ENABLED(MyHashMap)
You may also have a look at wxWidgets sample
You can extend this library using various callback handlers and inheritable classes.
A perfect example of using these features is the logging server built with this library. It's called Residue that is feature rich. In fact, you may be interested in using that instead of this library for your medium to large sized projects.
You can log your own classes by extending el::Loggable class and implementing pure-virtual function void log(std::ostream& os) const. Following example shows a good way to extend a class.
#include "easylogging++.h"
INITIALIZE_EASYLOGGINGPP
class Integer : public el::Loggable {
public:
Integer(int i) : m_underlyingInt(i) {
}
Integer& operator=(const Integer& integer) {
m_underlyingInt = integer.m_underlyingInt;
return *this;
}
// Following line does the trick!
// Note: el::base::type::ostream_t is either std::wostream or std::ostream depending on unicode enabled or not
virtual void log(el::base::type::ostream_t& os) const {
os << m_underlyingInt;
}
private:
int m_underlyingInt;
};
int main(void) {
Integer count = 5;
LOG(INFO) << count;
return 0;
}
Let's say you have third-party class that you don't have access to make changes to, and it's not yet loggable. In order to make it loggable, you can use MAKE_LOGGABLE(ClassType, ClassInstance, OutputStreamInstance) to make it Easylogging++ friendly.
Following sample shows a good usage:
#include "easylogging++.h"
INITIALIZE_EASYLOGGINGPP
class Integer {
public:
Integer(int i) : m_underlyingInt(i) {
}
Integer& operator=(const Integer& integer) {
m_underlyingInt = integer.m_underlyingInt;
return *this;
}
int getInt(void) const { return m_underlyingInt; }
private:
int m_underlyingInt;
};
// Following line does the trick!
inline MAKE_LOGGABLE(Integer, integer, os) {
os << integer.getInt();
return os;
}
int main(void) {
Integer count = 5;
LOG(INFO) << count;
return 0;
}
Another very nice example (to log std::chrono::system_clock::time_point)
inline MAKE_LOGGABLE(std::chrono::system_clock::time_point, when, os) {
time_t t = std::chrono::system_clock::to_time_t(when);
auto tm = std::localtime(&t);
char buf[1024];
strftime(buf,sizeof(buf), "%F %T (%Z)", tm);
os << buf;
return os;
}
This may not be practically best implementation but you get the point.
Just be careful with this as having a time-consuming overloading of
log(el::base::type::ostream_t& os)andMAKE_LOGGABLE, they get called everytime class is being logged.
You can manually flush log files using el::Logger::flush() (to flush single logger with all referencing log files) or el::Loggers::flushAll() (to flush all log files for all levels).
If you have not set flag LoggingFlag::StrictLogFileSizeCheck for some reason, you can manually check for log files that need rolling; by using el::Helpers::validateFileRolling(el::Logger*, const el::Level&).
If you wish to capture log message right after it is dispatched, you can do so by having a class that extends el::LogDispatchCallback and implement the pure-virtual functions, then install it at anytime using el::Helpers::installLogDispatchCallback<T>(const std::string&). If you wish to uninstall a pre-installed handler with same ID, you can do so by using el::Helpers::uninstallLogDispatchCallback<T>(const std::string&)
You can use this feature to send it to custom destinations e.g, log stash or TCP client etc.
You can also look at send-to-network sample for practical usage of this.
// samples/send-to-network/network-logger.cpp
#include "easylogging++.h"
#include <boost/asio.hpp>
INITIALIZE_EASYLOGGINGPP
class Client
{
boost::asio::io_service* io_service;
boost::asio::ip::tcp::socket socket;
public:
Client(boost::asio::io_service* svc, const std::string& host, const std::string& port)
: io_service(svc), socket(*io_service)
{
boost::asio::ip::tcp::resolver resolver(*io_service);
boost::asio::ip::tcp::resolver::iterator endpoint = resolver.resolve(boost::asio::ip::tcp::resolver::query(host, port));
boost::asio::connect(this->socket, endpoint);
};
void send(std::string const& message) {
socket.send(boost::asio::buffer(message));
}
};
class NetworkDispatcher : public el::LogDispatchCallback
{
public:
void updateServer(const std::string& host, int port) {
m_client = std::unique_ptr<Client>(new Client(&m_svc, host, std::to_string(port)));
}
protected:
void handle(const el::LogDispatchData* data) noexcept override {
m_data = data;
// Dispatch using default log builder of logger
dispatch(m_data->logMessage()->logger()->logBuilder()->build(m_data->logMessage(),
m_data->dispatchAction() == el::base::DispatchAction::NormalLog));
}
private:
const el::LogDispatchData* m_data;
boost::asio::io_service m_svc;
std::unique_ptr<Client> m_client;
void dispatch(el::base::type::string_t&& logLine) noexcept
{
m_client->send(logLine);
}
};
int main() {
el::Helpers::installLogDispatchCallback<NetworkDispatcher>("NetworkDispatcher");
// you can uninstall default one by
// el::Helpers::uninstallLogDispatchCallback<el::base::DefaultLogDispatchCallback>("DefaultLogDispatchCallback");
// Set server params
NetworkDispatcher* dispatcher = el::Helpers::logDispatchCallback<NetworkDispatcher>("NetworkDispatcher");
dispatcher->setEnabled(true);
dispatcher->updateServer("127.0.0.1", 9090);
// Start logging and normal program...
LOG(INFO) << "First network log";
// You can even use a different logger, say "network" and send using a different log pattern
}
DO NOT LOG ANYTHING IN THIS HANDLER OR YOU WILL END UP IN INFINITE-LOOP
If you wish to capture event of logger registration (and potentially want to reconfigure this logger without changing default configuration) you can use el::LoggerRegistrationCallback. The syntax is similar to other callbacks. You can use this sample as basis.
DO NOT LOG ANYTHING IN THIS HANDLER
Prerequisite: Define macro ELPP_EXPERIMENTAL_ASYNC
Asynchronous logging is in experimental stages and they are not widely promoted. You may enable and test this feature by defining macro ELPP_EXPERIMENTAL_ASYNC and if you find some issue with the feature please report in this issue. Reporting issues always help for constant improvements.
Please note:
std::thread)std::this_thread::sleep_for. This restriction may (or may not) be removed in future (stable) version of asynchronous logging.There are static helper classes available to make it easy to do stuffs;
el::Helpersel::LoggersYou can do various cool stuffs using functions in these classes, see this issue for instance.
You can submit patches to develop branch and we will try and merge them. Since it's based on single header, it can be sometimes difficult to merge without having merge conflicts.
If you have found a bug and wish to report it, feel free to do so at github issue tracker. I will try to look at it as soon as possible. Some information should be provided to make it easy to reproduce;
Try to provide as much information as possible. Any bug with no clear information will be ignored and closed.
Easylogging++ requires a decent C++0x compliant compiler. Some compilers known to work with v9.0+ are shown in table below, for older versions please refer to readme on corresponding release at github
| ***** | Compiler/Platform | Notes |
|---|---|---|
| GCC 4.6.4+ | Stack trace logging. Very close to support GCC 4.6.0 if it had supported strong enum types casting to underlying type. It causes internal compiler error. | |
| Clang++ 3.1+ | Stack trace logging only with gcc compliant. | |
| Intel C++ 13.0+ | Workarounds to support: Use if instead of switch on strong enum type. No final keyword etc. Stack trace logging only with gcc compliant |
|
| Visual C++ 11.0+ | Tested with VS2012, VS2013; Use of argument templates instead of variadic templates. CRT warnings control. No stack trace logging. | |
| MinGW | (gcc version 4.7+) Workarounds to support: Mutex wrapper, no stack trace logging. No thread ID on windows | |
| TDM-GCC 4.7.1 | Tested with TDM-GCC 4.7.1 32 and 64 bit compilers | |
| Cygwin | Tested with gcc version 4.8+ | |
| Dev C++ 5.4+ | Tested with Dev-C++ 5.4.2 using TDM-GCC 4.7.1 32 & 64-bit compilers |
Operating systems that have been tested are shown in table below. Easylogging++ should work on other major operating systems that are not in the list.
| ***** | Operating System | Notes |
|---|---|---|
| Windows 10 | Tested on 64-bit, should also work on 32-bit | |
| Windows 8 | Tested on 64-bit, should also work on 32-bit | |
| Windows 7 | Tested on 64-bit, should also work on 32-bit | |
| Windows XP | Tested on 32-bit, should also work on 64-bit | |
| Mac OSX | Clang++ 3.1, g++ (You need -std=c++11 -stdlib=libc++ to successfully compile) |
|
| Scientific Linux 6.2 | Tested using Intel C++ 13.1.3 (gcc version 4.4.6 compatibility) | |
| Linux Mint 14 | 64-bit, mainly developed on this machine using all compatible linux compilers | |
| Fedora 19 | 64-bit, using g++ 4.8.1 | |
| Ubuntu 13.04 | 64-bit, using g++ 4.7.3 (libstdc++6-4.7-dev) | |
| FreeBSD | (from github user) | |
| Android | Tested with C4droid (g++) on Galaxy Tab 2 | |
| RaspberryPi 7.6 | Tested with 7.6.2-1.1 (gcc version 4.9.1 (Raspbian 4.9.1-1)) by contributor | |
| Solaris i86 | Tested by contributor | |
| IBM AIX | Support added by contributor |
Easylogging++ has also been tested with following C++ libraries;
| ***** | Library | Notes |
|---|---|---|
| Qt | Tested with Qt 4.6.2, Qt 5 and Qt 5.5 (with C++0x and C++11) | |
| Boost | Tested with boost 1.51 | |
| wxWidgets | Tested with wxWidgets 2.9.4 | |
| gtkmm | Tested with gtkmm 2.4 |
## Build Matrix
| Branch | Platform | Build Status |
| -------- |:------------:|:------------:|
| develop | GNU/Linux 4.4 / Ubuntu 4.8.4 64-bit / clang++ | |
|
develop | GNU/Linux 4.4 / Ubuntu 4.8.4 64-bit / g++-4.9 | |
|
develop | GNU/Linux 4.4 / Ubuntu 4.8.4 64-bit / g++-5 | |
|
develop | GNU/Linux 4.4 / Ubuntu 4.8.4 64-bit / g++-6 | |
|
develop | GNU/Linux 4.4 / Ubuntu 4.8.4 64-bit / g++-7 | |
|
master | GNU/Linux 4.4 / Ubuntu 4.8.4 64-bit / clang++ | |
|
master | GNU/Linux 4.4 / Ubuntu 4.8.4 64-bit / g++-4.9 | |
|
master | GNU/Linux 4.4 / Ubuntu 4.8.4 64-bit / g++-5 | |
|
master | GNU/Linux 4.4 / Ubuntu 4.8.4 64-bit / g++-6 | |
|
master | GNU/Linux 4.4 / Ubuntu 4.8.4 64-bit / g++-7 | |
The MIT License (MIT)
Copyright (c) 2012-2018 Amrayn Web Services
Copyright (c) 2012-2018 @abumusamq
https://github.com/amrayn/
https://amrayn.com
https://muflihun.com
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Icons used in this manual (in compatibility section) are solely for information readability purposes. I do not own these icons. If anyone has issues with usage of these icon, please feel free to contact me via company's email and I will look for an alternative. Company's email address is required so that I can verify the ownership, any other email address for this purpose will be ignored.
"Pencil +" icon is Easylogging++ logo and should only be used where giving credit to Easylogging++ library.
*Note that all licence references and agreements mentioned in the easyloggingpp README section above
are relevant to that project's source code only.
Do not miss the trending, libraries, news and articles with our weekly report.