log.hpp
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <sstream>
11 #include <ostream>
12 #include <vector>
13 #include <functional>
14 
15 namespace elog {
20  enum level {
21  level_print = -1,
22  level_none = 0,
26  level_info = 4,
29  };
35  int32_t registerInstance(const std::string& _name);
44  void setLevel(const std::string& _name, enum elog::level _level);
50  void setLevel(int32_t _id, enum elog::level _level);
58  void setLevel(enum elog::level _level);
64  int32_t getLevel(int32_t _id);
69  std::vector<std::string> getListInstance();
74  void setColor(bool _status);
79  void setTime(bool _status);
84  void setLine(bool _status);
89  void setFunction(bool _status);
94  void setThreadId(bool _status);
99  void setThreadNameEnable(bool _status);
104  void setLibName(bool _status);
109  void setBackTrace(bool _status);
118  void logChar(int32_t _id, int32_t _level, int32_t _ligne, const char* _funcName, const char* _log);
127  void logStream(int32_t _id, int32_t _level, int32_t _ligne, const char* _funcName, const std::ostream& _log);
134  void logChar1(int32_t _id, int32_t _level, const char* _log);
141  void logStream1(int32_t _id, int32_t _level, const std::ostream& _log);
147  void displayBacktrace(bool _breakAtEnd = false, int32_t _removeElement=0);
156  using callbackLog = std::function<void (const char* _libName, enum elog::level _level, int32_t _ligne, const char* _funcName, const char* _log)>;
161  void setCallbackLog(const elog::callbackLog& _callback);
167  void setLogInFile(const std::string& _filename="");
171  void unsetLogInFile();
172 };
173 
180 #define ELOG_BASE(logId,info,data) \
181  do { \
182  if (info <= elog::getLevel(logId)) { \
183  std::stringbuf sb; \
184  std::ostream tmpStream(&sb); \
185  tmpStream << data; \
186  elog::logStream(logId, info, __LINE__, __PRETTY_FUNCTION__, tmpStream); \
187  } \
188  } while(0)
void setCallbackLog(const elog::callbackLog &_callback)
Set a callback to display all log in an other framework.
void displayBacktrace(bool _breakAtEnd=false, int32_t _removeElement=0)
Display the current backtrace.
void setThreadNameEnable(bool _status)
Set thread name enable or disable.
void setBackTrace(bool _status)
Set back-trace display on Error log enable or disable.
void setLibName(bool _status)
Set library display enable or disable.
void setLogInFile(const std::string &_filename="")
Set log done in a specific file.
Display all logs (removed in release and debug mode)
Definition: log.hpp:28
std::function< void(const char *_libName, enum elog::level _level, int32_t _ligne, const char *_funcName, const char *_log)> callbackLog
function definition of an external log function
Definition: log.hpp:156
Display log critical to information (removed in release mode)
Definition: log.hpp:26
void unsetLogInFile()
Disable log in a file.
void setLine(bool _status)
Set Line display enable or disable.
void setFunction(bool _status)
Set Function display enable or disable.
int32_t getLevel(int32_t _id)
Get the current level of debug for a specific intance.
std::vector< std::string > getListInstance()
Get list of all intance.
int32_t registerInstance(const std::string &_name)
Register an element in the log system.
void setLevel(const std::string &_name, enum elog::level _level)
Set the log level of a specific instance.
void setThreadId(bool _status)
Set thread id enable or disable.
void logChar(int32_t _id, int32_t _level, int32_t _ligne, const char *_funcName, const char *_log)
Call log to display.
void logStream1(int32_t _id, int32_t _level, const std::ostream &_log)
Call log to display.
Display only critical logs (note that critical generally assert with a backtrace (when we can)) ...
Definition: log.hpp:23
Display log critical to warning.
Definition: log.hpp:25
basic print for Help or result (never filtered)
Definition: log.hpp:21
Display log critical to debug (removed in release mode)
Definition: log.hpp:27
no display requested
Definition: log.hpp:22
void logChar1(int32_t _id, int32_t _level, const char *_log)
Call log to display.
void logStream(int32_t _id, int32_t _level, int32_t _ligne, const char *_funcName, const std::ostream &_log)
Call log to display.
level
Log level is a simple list of all log availlable. This enum is used when setting a log and when user ...
Definition: log.hpp:20
basic namespace of the elog library. (it might contain all the elog fuctions without macro) ...
Definition: elog.hpp:14
Display Error and critical logs.
Definition: log.hpp:24
void setColor(bool _status)
Set Color enable or disable.
void setTime(bool _status)
Set Time display enable or disable.