Electroneum
misc_log_ex.h File Reference
#include <string>
#include "easylogging++.h"
#include <assert.h>
Include dependency graph for misc_log_ex.h:

Go to the source code of this file.

Namespaces

 epee
 
 epee::debug
 

Macros

#define ELECTRONEUM_DEFAULT_LOG_CATEGORY   "default"
 
#define MAX_LOG_FILE_SIZE   104850000
 
#define MAX_LOG_FILES   50
 
#define MCLOG_TYPE(level, cat, type, x)
 
#define MCLOG(level, cat, x)   MCLOG_TYPE(level, cat, el::base::DispatchAction::NormalLog, x)
 
#define MCLOG_FILE(level, cat, x)   MCLOG_TYPE(level, cat, el::base::DispatchAction::FileOnlyLog, x)
 
#define MCFATAL(cat, x)   MCLOG(el::Level::Fatal,cat, x)
 
#define MCERROR(cat, x)   MCLOG(el::Level::Error,cat, x)
 
#define MCWARNING(cat, x)   MCLOG(el::Level::Warning,cat, x)
 
#define MCINFO(cat, x)   MCLOG(el::Level::Info,cat, x)
 
#define MCDEBUG(cat, x)   MCLOG(el::Level::Debug,cat, x)
 
#define MCTRACE(cat, x)   MCLOG(el::Level::Trace,cat, x)
 
#define MCLOG_COLOR(level, cat, color, x)   MCLOG(level,cat,"\033[1;" color "m" << x << "\033[0m")
 
#define MCLOG_RED(level, cat, x)   MCLOG_COLOR(level,cat,"31",x)
 
#define MCLOG_GREEN(level, cat, x)   MCLOG_COLOR(level,cat,"32",x)
 
#define MCLOG_YELLOW(level, cat, x)   MCLOG_COLOR(level,cat,"33",x)
 
#define MCLOG_BLUE(level, cat, x)   MCLOG_COLOR(level,cat,"34",x)
 
#define MCLOG_MAGENTA(level, cat, x)   MCLOG_COLOR(level,cat,"35",x)
 
#define MCLOG_CYAN(level, cat, x)   MCLOG_COLOR(level,cat,"36",x)
 
#define MLOG_RED(level, x)   MCLOG_RED(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
 
#define MLOG_GREEN(level, x)   MCLOG_GREEN(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
 
#define MLOG_YELLOW(level, x)   MCLOG_YELLOW(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
 
#define MLOG_BLUE(level, x)   MCLOG_BLUE(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
 
#define MLOG_MAGENTA(level, x)   MCLOG_MAGENTA(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
 
#define MLOG_CYAN(level, x)   MCLOG_CYAN(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
 
#define MFATAL(x)   MCFATAL(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
 
#define MERROR(x)   MCERROR(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
 
#define MWARNING(x)   MCWARNING(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
 
#define MINFO(x)   MCINFO(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
 
#define MDEBUG(x)   MCDEBUG(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
 
#define MTRACE(x)   MCTRACE(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
 
#define MLOG(level, x)   MCLOG(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
 
#define MGINFO(x)   MCINFO("global",x)
 
#define MGINFO_RED(x)   MCLOG_RED(el::Level::Info, "global",x)
 
#define MGINFO_GREEN(x)   MCLOG_GREEN(el::Level::Info, "global",x)
 
#define MGINFO_YELLOW(x)   MCLOG_YELLOW(el::Level::Info, "global",x)
 
#define MGINFO_BLUE(x)   MCLOG_BLUE(el::Level::Info, "global",x)
 
#define MGINFO_MAGENTA(x)   MCLOG_MAGENTA(el::Level::Info, "global",x)
 
#define MGINFO_CYAN(x)   MCLOG_CYAN(el::Level::Info, "global",x)
 
#define IFLOG(level, cat, type, init, x)
 
#define MIDEBUG(init, x)   IFLOG(el::Level::Debug, ELECTRONEUM_DEFAULT_LOG_CATEGORY, el::base::DispatchAction::NormalLog, init, x)
 
#define LOG_ERROR(x)   MERROR(x)
 
#define LOG_PRINT_L0(x)   MWARNING(x)
 
#define LOG_PRINT_L1(x)   MINFO(x)
 
#define LOG_PRINT_L2(x)   MDEBUG(x)
 
#define LOG_PRINT_L3(x)   MTRACE(x)
 
#define LOG_PRINT_L4(x)   MTRACE(x)
 
#define _dbg3(x)   MTRACE(x)
 
#define _dbg2(x)   MDEBUG(x)
 
#define _dbg1(x)   MDEBUG(x)
 
#define _info(x)   MINFO(x)
 
#define _note(x)   MDEBUG(x)
 
#define _fact(x)   MDEBUG(x)
 
#define _mark(x)   MDEBUG(x)
 
#define _warn(x)   MWARNING(x)
 
#define _erro(x)   MERROR(x)
 
#define MLOG_SET_THREAD_NAME(x)   el::Helpers::setThreadName(x)
 
#define LOCAL_ASSERT(expr)
 
#define ENDL   std::endl
 
#define TRY_ENTRY()   try {
 
#define CATCH_ENTRY(location, return_val)
 
#define CATCH_ENTRY_L0(lacation, return_val)   CATCH_ENTRY(lacation, return_val)
 
#define CATCH_ENTRY_L1(lacation, return_val)   CATCH_ENTRY(lacation, return_val)
 
#define CATCH_ENTRY_L2(lacation, return_val)   CATCH_ENTRY(lacation, return_val)
 
#define CATCH_ENTRY_L3(lacation, return_val)   CATCH_ENTRY(lacation, return_val)
 
#define CATCH_ENTRY_L4(lacation, return_val)   CATCH_ENTRY(lacation, return_val)
 
#define ASSERT_MES_AND_THROW(message)   {LOG_ERROR(message); std::stringstream ss; ss << message; throw std::runtime_error(ss.str());}
 
#define CHECK_AND_ASSERT_THROW_MES(expr, message)   do {if(!(expr)) ASSERT_MES_AND_THROW(message);} while(0)
 
#define CHECK_AND_ASSERT(expr, fail_ret_val)   do{if(!(expr)){LOCAL_ASSERT(expr); return fail_ret_val;};}while(0)
 
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)   do{if(!(expr)) {LOG_ERROR(message); return fail_ret_val;};}while(0)
 
#define CHECK_AND_NO_ASSERT_MES_L(expr, fail_ret_val, l, message)   do{if(!(expr)) {LOG_PRINT_L##l(message); /*LOCAL_ASSERT(expr);*/ return fail_ret_val;};}while(0)
 
#define CHECK_AND_NO_ASSERT_MES(expr, fail_ret_val, message)   CHECK_AND_NO_ASSERT_MES_L(expr, fail_ret_val, 0, message)
 
#define CHECK_AND_NO_ASSERT_MES_L1(expr, fail_ret_val, message)   CHECK_AND_NO_ASSERT_MES_L(expr, fail_ret_val, 1, message)
 
#define CHECK_AND_ASSERT_MES_NO_RET(expr, message)   do{if(!(expr)) {LOG_ERROR(message); return;};}while(0)
 
#define CHECK_AND_ASSERT_MES2(expr, message)   do{if(!(expr)) {LOG_ERROR(message); };}while(0)
 

Enumerations

enum  epee::console_colors {
  epee::console_color_default , epee::console_color_white , epee::console_color_red , epee::console_color_green ,
  epee::console_color_blue , epee::console_color_cyan , epee::console_color_magenta , epee::console_color_yellow
}
 

Functions

std::string mlog_get_default_log_path (const char *default_filename)
 
void mlog_configure (const std::string &filename_base, bool console, const std::size_t max_log_file_size=MAX_LOG_FILE_SIZE, const std::size_t max_log_files=MAX_LOG_FILES)
 
void mlog_set_categories (const char *categories)
 
std::string mlog_get_categories ()
 
void mlog_set_log_level (int level)
 
void mlog_set_log (const char *log)
 
bool epee::debug::get_set_enable_assert (bool set=false, bool v=false)
 
bool epee::is_stdout_a_tty ()
 
void epee::set_console_color (int color, bool bright)
 
void epee::reset_console_color ()
 

Macro Definition Documentation

◆ _dbg1

#define _dbg1 (   x)    MDEBUG(x)

Definition at line 107 of file misc_log_ex.h.

◆ _dbg2

#define _dbg2 (   x)    MDEBUG(x)

Definition at line 106 of file misc_log_ex.h.

◆ _dbg3

#define _dbg3 (   x)    MTRACE(x)

Definition at line 105 of file misc_log_ex.h.

◆ _erro

#define _erro (   x)    MERROR(x)

Definition at line 113 of file misc_log_ex.h.

◆ _fact

#define _fact (   x)    MDEBUG(x)

Definition at line 110 of file misc_log_ex.h.

◆ _info

#define _info (   x)    MINFO(x)

Definition at line 108 of file misc_log_ex.h.

◆ _mark

#define _mark (   x)    MDEBUG(x)

Definition at line 111 of file misc_log_ex.h.

◆ _note

#define _note (   x)    MDEBUG(x)

Definition at line 109 of file misc_log_ex.h.

◆ _warn

#define _warn (   x)    MWARNING(x)

Definition at line 112 of file misc_log_ex.h.

◆ ASSERT_MES_AND_THROW

#define ASSERT_MES_AND_THROW (   message)    {LOG_ERROR(message); std::stringstream ss; ss << message; throw std::runtime_error(ss.str());}

Definition at line 172 of file misc_log_ex.h.

◆ CATCH_ENTRY

#define CATCH_ENTRY (   location,
  return_val 
)
Value:
} \
catch(const std::exception& ex) \
{ \
(void)(ex); \
LOG_ERROR("Exception at [" << location << "], what=" << ex.what()); \
return return_val; \
}\
catch(...)\
{\
LOG_ERROR("Exception at [" << location << "], generic exception \"...\"");\
return return_val; \
}

Definition at line 152 of file misc_log_ex.h.

◆ CATCH_ENTRY_L0

#define CATCH_ENTRY_L0 (   lacation,
  return_val 
)    CATCH_ENTRY(lacation, return_val)

Definition at line 165 of file misc_log_ex.h.

◆ CATCH_ENTRY_L1

#define CATCH_ENTRY_L1 (   lacation,
  return_val 
)    CATCH_ENTRY(lacation, return_val)

Definition at line 166 of file misc_log_ex.h.

◆ CATCH_ENTRY_L2

#define CATCH_ENTRY_L2 (   lacation,
  return_val 
)    CATCH_ENTRY(lacation, return_val)

Definition at line 167 of file misc_log_ex.h.

◆ CATCH_ENTRY_L3

#define CATCH_ENTRY_L3 (   lacation,
  return_val 
)    CATCH_ENTRY(lacation, return_val)

Definition at line 168 of file misc_log_ex.h.

◆ CATCH_ENTRY_L4

#define CATCH_ENTRY_L4 (   lacation,
  return_val 
)    CATCH_ENTRY(lacation, return_val)

Definition at line 169 of file misc_log_ex.h.

◆ CHECK_AND_ASSERT

#define CHECK_AND_ASSERT (   expr,
  fail_ret_val 
)    do{if(!(expr)){LOCAL_ASSERT(expr); return fail_ret_val;};}while(0)

Definition at line 177 of file misc_log_ex.h.

◆ CHECK_AND_ASSERT_MES

#define CHECK_AND_ASSERT_MES (   expr,
  fail_ret_val,
  message 
)    do{if(!(expr)) {LOG_ERROR(message); return fail_ret_val;};}while(0)

Definition at line 181 of file misc_log_ex.h.

◆ CHECK_AND_ASSERT_MES2

#define CHECK_AND_ASSERT_MES2 (   expr,
  message 
)    do{if(!(expr)) {LOG_ERROR(message); };}while(0)

Definition at line 203 of file misc_log_ex.h.

◆ CHECK_AND_ASSERT_MES_NO_RET

#define CHECK_AND_ASSERT_MES_NO_RET (   expr,
  message 
)    do{if(!(expr)) {LOG_ERROR(message); return;};}while(0)

Definition at line 198 of file misc_log_ex.h.

◆ CHECK_AND_ASSERT_THROW_MES

#define CHECK_AND_ASSERT_THROW_MES (   expr,
  message 
)    do {if(!(expr)) ASSERT_MES_AND_THROW(message);} while(0)

Definition at line 173 of file misc_log_ex.h.

◆ CHECK_AND_NO_ASSERT_MES

#define CHECK_AND_NO_ASSERT_MES (   expr,
  fail_ret_val,
  message 
)    CHECK_AND_NO_ASSERT_MES_L(expr, fail_ret_val, 0, message)

Definition at line 189 of file misc_log_ex.h.

◆ CHECK_AND_NO_ASSERT_MES_L

#define CHECK_AND_NO_ASSERT_MES_L (   expr,
  fail_ret_val,
  l,
  message 
)    do{if(!(expr)) {LOG_PRINT_L##l(message); /*LOCAL_ASSERT(expr);*/ return fail_ret_val;};}while(0)

Definition at line 185 of file misc_log_ex.h.

◆ CHECK_AND_NO_ASSERT_MES_L1

#define CHECK_AND_NO_ASSERT_MES_L1 (   expr,
  fail_ret_val,
  message 
)    CHECK_AND_NO_ASSERT_MES_L(expr, fail_ret_val, 1, message)

Definition at line 193 of file misc_log_ex.h.

◆ ELECTRONEUM_DEFAULT_LOG_CATEGORY

#define ELECTRONEUM_DEFAULT_LOG_CATEGORY   "default"

Definition at line 36 of file misc_log_ex.h.

◆ ENDL

#define ENDL   std::endl

Definition at line 149 of file misc_log_ex.h.

◆ IFLOG

#define IFLOG (   level,
  cat,
  type,
  init,
 
)
Value:
do { \
if (ELPP->vRegistry()->allowed(level, cat)) { \
init; \
el::base::Writer(level, __FILE__, __LINE__, ELPP_FUNC, type).construct(cat) << x; \
} \
} while(0)
#define ELPP_FUNC
#define ELPP

Definition at line 88 of file misc_log_ex.h.

◆ LOCAL_ASSERT

#define LOCAL_ASSERT (   expr)

Definition at line 122 of file misc_log_ex.h.

◆ LOG_ERROR

#define LOG_ERROR (   x)    MERROR(x)

Definition at line 98 of file misc_log_ex.h.

◆ LOG_PRINT_L0

#define LOG_PRINT_L0 (   x)    MWARNING(x)

Definition at line 99 of file misc_log_ex.h.

◆ LOG_PRINT_L1

#define LOG_PRINT_L1 (   x)    MINFO(x)

Definition at line 100 of file misc_log_ex.h.

◆ LOG_PRINT_L2

#define LOG_PRINT_L2 (   x)    MDEBUG(x)

Definition at line 101 of file misc_log_ex.h.

◆ LOG_PRINT_L3

#define LOG_PRINT_L3 (   x)    MTRACE(x)

Definition at line 102 of file misc_log_ex.h.

◆ LOG_PRINT_L4

#define LOG_PRINT_L4 (   x)    MTRACE(x)

Definition at line 103 of file misc_log_ex.h.

◆ MAX_LOG_FILE_SIZE

#define MAX_LOG_FILE_SIZE   104850000

Definition at line 38 of file misc_log_ex.h.

◆ MAX_LOG_FILES

#define MAX_LOG_FILES   50

Definition at line 39 of file misc_log_ex.h.

◆ MCDEBUG

#define MCDEBUG (   cat,
 
)    MCLOG(el::Level::Debug,cat, x)

Definition at line 54 of file misc_log_ex.h.

◆ MCERROR

#define MCERROR (   cat,
 
)    MCLOG(el::Level::Error,cat, x)

Definition at line 51 of file misc_log_ex.h.

◆ MCFATAL

#define MCFATAL (   cat,
 
)    MCLOG(el::Level::Fatal,cat, x)

Definition at line 50 of file misc_log_ex.h.

◆ MCINFO

#define MCINFO (   cat,
 
)    MCLOG(el::Level::Info,cat, x)

Definition at line 53 of file misc_log_ex.h.

◆ MCLOG

#define MCLOG (   level,
  cat,
 
)    MCLOG_TYPE(level, cat, el::base::DispatchAction::NormalLog, x)

Definition at line 47 of file misc_log_ex.h.

◆ MCLOG_BLUE

#define MCLOG_BLUE (   level,
  cat,
 
)    MCLOG_COLOR(level,cat,"34",x)

Definition at line 61 of file misc_log_ex.h.

◆ MCLOG_COLOR

#define MCLOG_COLOR (   level,
  cat,
  color,
 
)    MCLOG(level,cat,"\033[1;" color "m" << x << "\033[0m")

Definition at line 57 of file misc_log_ex.h.

◆ MCLOG_CYAN

#define MCLOG_CYAN (   level,
  cat,
 
)    MCLOG_COLOR(level,cat,"36",x)

Definition at line 63 of file misc_log_ex.h.

◆ MCLOG_FILE

#define MCLOG_FILE (   level,
  cat,
 
)    MCLOG_TYPE(level, cat, el::base::DispatchAction::FileOnlyLog, x)

Definition at line 48 of file misc_log_ex.h.

◆ MCLOG_GREEN

#define MCLOG_GREEN (   level,
  cat,
 
)    MCLOG_COLOR(level,cat,"32",x)

Definition at line 59 of file misc_log_ex.h.

◆ MCLOG_MAGENTA

#define MCLOG_MAGENTA (   level,
  cat,
 
)    MCLOG_COLOR(level,cat,"35",x)

Definition at line 62 of file misc_log_ex.h.

◆ MCLOG_RED

#define MCLOG_RED (   level,
  cat,
 
)    MCLOG_COLOR(level,cat,"31",x)

Definition at line 58 of file misc_log_ex.h.

◆ MCLOG_TYPE

#define MCLOG_TYPE (   level,
  cat,
  type,
 
)
Value:
do { \
if (ELPP->vRegistry()->allowed(level, cat)) { \
el::base::Writer(level, __FILE__, __LINE__, ELPP_FUNC, type).construct(cat) << x; \
} \
} while (0)

Definition at line 41 of file misc_log_ex.h.

◆ MCLOG_YELLOW

#define MCLOG_YELLOW (   level,
  cat,
 
)    MCLOG_COLOR(level,cat,"33",x)

Definition at line 60 of file misc_log_ex.h.

◆ MCTRACE

#define MCTRACE (   cat,
 
)    MCLOG(el::Level::Trace,cat, x)

Definition at line 55 of file misc_log_ex.h.

◆ MCWARNING

#define MCWARNING (   cat,
 
)    MCLOG(el::Level::Warning,cat, x)

Definition at line 52 of file misc_log_ex.h.

◆ MDEBUG

#define MDEBUG (   x)    MCDEBUG(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)

Definition at line 76 of file misc_log_ex.h.

◆ MERROR

#define MERROR (   x)    MCERROR(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)

Definition at line 73 of file misc_log_ex.h.

◆ MFATAL

#define MFATAL (   x)    MCFATAL(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)

Definition at line 72 of file misc_log_ex.h.

◆ MGINFO

#define MGINFO (   x)    MCINFO("global",x)

Definition at line 80 of file misc_log_ex.h.

◆ MGINFO_BLUE

#define MGINFO_BLUE (   x)    MCLOG_BLUE(el::Level::Info, "global",x)

Definition at line 84 of file misc_log_ex.h.

◆ MGINFO_CYAN

#define MGINFO_CYAN (   x)    MCLOG_CYAN(el::Level::Info, "global",x)

Definition at line 86 of file misc_log_ex.h.

◆ MGINFO_GREEN

#define MGINFO_GREEN (   x)    MCLOG_GREEN(el::Level::Info, "global",x)

Definition at line 82 of file misc_log_ex.h.

◆ MGINFO_MAGENTA

#define MGINFO_MAGENTA (   x)    MCLOG_MAGENTA(el::Level::Info, "global",x)

Definition at line 85 of file misc_log_ex.h.

◆ MGINFO_RED

#define MGINFO_RED (   x)    MCLOG_RED(el::Level::Info, "global",x)

Definition at line 81 of file misc_log_ex.h.

◆ MGINFO_YELLOW

#define MGINFO_YELLOW (   x)    MCLOG_YELLOW(el::Level::Info, "global",x)

Definition at line 83 of file misc_log_ex.h.

◆ MIDEBUG

#define MIDEBUG (   init,
 
)    IFLOG(el::Level::Debug, ELECTRONEUM_DEFAULT_LOG_CATEGORY, el::base::DispatchAction::NormalLog, init, x)

Definition at line 95 of file misc_log_ex.h.

◆ MINFO

#define MINFO (   x)    MCINFO(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)

Definition at line 75 of file misc_log_ex.h.

◆ MLOG

#define MLOG (   level,
 
)    MCLOG(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)

Definition at line 78 of file misc_log_ex.h.

◆ MLOG_BLUE

#define MLOG_BLUE (   level,
 
)    MCLOG_BLUE(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)

Definition at line 68 of file misc_log_ex.h.

◆ MLOG_CYAN

#define MLOG_CYAN (   level,
 
)    MCLOG_CYAN(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)

Definition at line 70 of file misc_log_ex.h.

◆ MLOG_GREEN

#define MLOG_GREEN (   level,
 
)    MCLOG_GREEN(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)

Definition at line 66 of file misc_log_ex.h.

◆ MLOG_MAGENTA

#define MLOG_MAGENTA (   level,
 
)    MCLOG_MAGENTA(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)

Definition at line 69 of file misc_log_ex.h.

◆ MLOG_RED

#define MLOG_RED (   level,
 
)    MCLOG_RED(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)

Definition at line 65 of file misc_log_ex.h.

◆ MLOG_SET_THREAD_NAME

#define MLOG_SET_THREAD_NAME (   x)    el::Helpers::setThreadName(x)

Definition at line 115 of file misc_log_ex.h.

◆ MLOG_YELLOW

#define MLOG_YELLOW (   level,
 
)    MCLOG_YELLOW(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)

Definition at line 67 of file misc_log_ex.h.

◆ MTRACE

#define MTRACE (   x)    MCTRACE(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)

Definition at line 77 of file misc_log_ex.h.

◆ MWARNING

#define MWARNING (   x)    MCWARNING(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)

Definition at line 74 of file misc_log_ex.h.

◆ TRY_ENTRY

#define TRY_ENTRY ( )    try {

Definition at line 151 of file misc_log_ex.h.

Function Documentation

◆ mlog_configure()

void mlog_configure ( const std::string &  filename_base,
bool  console,
const std::size_t  max_log_file_size = MAX_LOG_FILE_SIZE,
const std::size_t  max_log_files = MAX_LOG_FILES 
)

Definition at line 148 of file mlog.cpp.

149 {
153  const char *log_format = getenv("ELECTRONEUM_LOG_FORMAT");
154  if (!log_format)
155  log_format = MLOG_BASE_FORMAT;
157  c.setGlobally(el::ConfigurationType::ToStandardOutput, console ? "true" : "false");
160 
166  el::Helpers::installPreRollOutCallback([filename_base, max_log_files](const char *name, size_t){
167  std::string rname = generate_log_filename(filename_base.c_str());
168  int ret = rename(name, rname.c_str());
169  if (ret < 0)
170  {
171  // can't log a failure, but don't do the file removal below
172  return;
173  }
174  if (max_log_files != 0)
175  {
176  std::vector<boost::filesystem::path> found_files;
177  const boost::filesystem::directory_iterator end_itr;
178  const boost::filesystem::path filename_base_path(filename_base);
179  const boost::filesystem::path parent_path = filename_base_path.has_parent_path() ? filename_base_path.parent_path() : ".";
180  for (boost::filesystem::directory_iterator iter(parent_path); iter != end_itr; ++iter)
181  {
182  const std::string filename = iter->path().string();
183  if (filename.size() >= filename_base.size() && std::memcmp(filename.data(), filename_base.data(), filename_base.size()) == 0)
184  {
185  found_files.push_back(iter->path());
186  }
187  }
188  if (found_files.size() >= max_log_files)
189  {
190  std::sort(found_files.begin(), found_files.end(), [](const boost::filesystem::path &a, const boost::filesystem::path &b) {
191  boost::system::error_code ec;
192  std::time_t ta = boost::filesystem::last_write_time(boost::filesystem::path(a), ec);
193  if (ec)
194  {
195  MERROR("Failed to get timestamp from " << a << ": " << ec);
196  ta = std::time(nullptr);
197  }
198  std::time_t tb = boost::filesystem::last_write_time(boost::filesystem::path(b), ec);
199  if (ec)
200  {
201  MERROR("Failed to get timestamp from " << b << ": " << ec);
202  tb = std::time(nullptr);
203  }
204  static_assert(std::is_integral<time_t>(), "bad time_t");
205  return ta < tb;
206  });
207  for (size_t i = 0; i <= found_files.size() - max_log_files; ++i)
208  {
209  try
210  {
211  boost::system::error_code ec;
212  boost::filesystem::remove(found_files[i], ec);
213  if (ec)
214  {
215  MERROR("Failed to remove " << found_files[i] << ": " << ec);
216  }
217  }
218  catch (const std::exception &e)
219  {
220  MERROR("Failed to remove " << found_files[i] << ": " << e.what());
221  }
222  }
223  }
224  }
225  });
226  mlog_set_common_prefix();
227  const char *electroneum_log = getenv("ELECTRONEUM_LOGS");
228  if (!electroneum_log)
229  {
230  electroneum_log = get_default_categories(0);
231  }
232  mlog_set_log(electroneum_log);
233 #ifdef WIN32
234  EnableVTMode();
235 #endif
236 }
else if(0==res)
time_t time
Definition: blockchain.cpp:93
Thread-safe Configuration repository.
void setGlobally(ConfigurationType configurationType, const std::string &value)
Sets configuration for all levels.
static void installPreRollOutCallback(const PreRollOutCallback &callback)
Installs pre rollout callback, this callback is triggered when log file is about to be rolled out (ca...
static void setDefaultConfigurations(const Configurations &configurations, bool reconfigureExistingLoggers=false)
Sets default configurations. This configuration is used for future (and conditionally for existing) l...
static void addFlag(LoggingFlag flag)
Adds logging flag used internally.
#define MERROR(x)
Definition: misc_log_ex.h:73
void mlog_set_log(const char *log)
Definition: mlog.cpp:288
#define MLOG_BASE_FORMAT
Definition: mlog.cpp:49
const char * name
@ CreateLoggerAutomatically
Creates logger automatically when not available.
@ HierarchicalLogging
Enables hierarchical logging.
@ StrictLogFileSizeCheck
Enables strict file rolling.
@ DisableApplicationAbortOnFatalLog
Allows to disable application abortion when logged using FATAL level.
@ ColoredTerminalOutput
Make terminal output colorful for supported terminals.
@ Filename
Determines log file (full path) to write logs to for correponding level and logger.
@ MaxLogFileSize
Specifies log file max size.
@ Format
Determines format of logging corresponding level and logger.
@ ToStandardOutput
Whether or not to write corresponding level and logger log to standard output. By standard output mea...
@ ToFile
Whether or not to write corresponding log to log file.
std::string to_string(t_connection_type type)
::std::string string
Definition: gtest-port.h:1097
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mlog_get_categories()

std::string mlog_get_categories ( )

Definition at line 276 of file mlog.cpp.

277 {
279 }
static std::string getCategories()
Gets current categories.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mlog_get_default_log_path()

std::string mlog_get_default_log_path ( const char *  default_filename)

Definition at line 72 of file mlog.cpp.

73 {
76  std::string default_log_file = process_name;
77  std::string::size_type a = default_log_file.rfind('.');
78  if ( a != std::string::npos )
79  default_log_file.erase( a, default_log_file.size());
80  if ( ! default_log_file.empty() )
81  default_log_file += ".log";
82  else
83  default_log_file = default_filename;
84 
85  return (boost::filesystem::path(default_log_folder) / boost::filesystem::path(default_log_file)).string();
86 }
std::string & get_current_module_name()
Definition: string_tools.h:227
std::string & get_current_module_folder()
Definition: string_tools.h:233
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mlog_set_categories()

void mlog_set_categories ( const char *  categories)

Definition at line 238 of file mlog.cpp.

239 {
240  std::string new_categories;
241  if (*categories)
242  {
243  if (*categories == '+')
244  {
245  ++categories;
246  new_categories = mlog_get_categories();
247  if (*categories)
248  {
249  if (!new_categories.empty())
250  new_categories += ",";
251  new_categories += categories;
252  }
253  }
254  else if (*categories == '-')
255  {
256  ++categories;
257  new_categories = mlog_get_categories();
258  std::vector<std::string> single_categories;
259  boost::split(single_categories, categories, boost::is_any_of(","), boost::token_compress_on);
260  for (const std::string &s: single_categories)
261  {
262  size_t pos = new_categories.find(s);
263  if (pos != std::string::npos)
264  new_categories = new_categories.erase(pos, s.size());
265  }
266  }
267  else
268  {
269  new_categories = categories;
270  }
271  }
272  el::Loggers::setCategories(new_categories.c_str(), true);
273  MLOG_LOG("New log categories: " << el::Loggers::getCategories());
274 }
static void setCategories(const char *categories, bool clear=true)
Sets categories as specified (on the fly)
std::string mlog_get_categories()
Definition: mlog.cpp:276
#define MLOG_LOG(x)
Definition: mlog.cpp:51
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mlog_set_log()

void mlog_set_log ( const char *  log)

Definition at line 288 of file mlog.cpp.

289 {
290  long level;
291  char *ptr = NULL;
292 
293  if (!*log)
294  {
295  mlog_set_categories(log);
296  return;
297  }
298  level = strtol(log, &ptr, 10);
299  if (ptr && *ptr)
300  {
301  // we can have a default level, eg, 2,foo:ERROR
302  if (*ptr == ',') {
303  std::string new_categories = std::string(get_default_categories(level)) + ptr;
304  mlog_set_categories(new_categories.c_str());
305  }
306  else {
307  mlog_set_categories(log);
308  }
309  }
310  else if (level >= 0 && level <= 4)
311  {
312  mlog_set_log_level(level);
313  }
314  else
315  {
316  MERROR("Invalid numerical log level: " << log);
317  }
318 }
void mlog_set_log_level(int level)
Definition: mlog.cpp:282
void mlog_set_categories(const char *categories)
Definition: mlog.cpp:238
Here is the caller graph for this function:

◆ mlog_set_log_level()

void mlog_set_log_level ( int  level)

Definition at line 282 of file mlog.cpp.

283 {
284  const char *categories = get_default_categories(level);
285  mlog_set_categories(categories);
286 }
Here is the caller graph for this function: