aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/src/mlog.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-05-27 14:15:04 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-09-24 15:47:31 +0000
commit89339551a23659153dcd839ab4546e4fb87f5294 (patch)
treee4292e2f3ce5b77908bea51fd7113015078c312e /contrib/epee/src/mlog.cpp
parentMerge pull request #5916 (diff)
downloadmonero-89339551a23659153dcd839ab4546e4fb87f5294.tar.xz
epee: misc_log_ex.h can now be used in C code
use mfatal/merror/mwarning/minfo/mdebug/mtrace
Diffstat (limited to '')
-rw-r--r--contrib/epee/src/mlog.cpp36
1 files changed, 25 insertions, 11 deletions
diff --git a/contrib/epee/src/mlog.cpp b/contrib/epee/src/mlog.cpp
index 0cf579840..66dfabcdf 100644
--- a/contrib/epee/src/mlog.cpp
+++ b/contrib/epee/src/mlog.cpp
@@ -472,40 +472,54 @@ void reset_console_color() {
}
-static void mlog(el::Level level, const char *category, const char *format, va_list ap)
+static bool mlog(el::Level level, const char *category, const char *format, va_list ap) noexcept
{
int size = 0;
char *p = NULL;
va_list apc;
+ bool ret = true;
/* Determine required size */
va_copy(apc, ap);
size = vsnprintf(p, size, format, apc);
va_end(apc);
if (size < 0)
- return;
+ return false;
size++; /* For '\0' */
p = (char*)malloc(size);
if (p == NULL)
- return;
+ return false;
size = vsnprintf(p, size, format, ap);
if (size < 0)
{
free(p);
- return;
+ return false;
}
- MCLOG(level, category, el::Color::Default, p);
+ try
+ {
+ MCLOG(level, category, el::Color::Default, p);
+ }
+ catch(...)
+ {
+ ret = false;
+ }
free(p);
+
+ return ret;
}
-void mfatal(const char *category, const char *fmt, ...) { va_list ap; va_start(ap, fmt); mlog(el::Level::Fatal, category, fmt, ap); va_end(ap); }
-void merror(const char *category, const char *fmt, ...) { va_list ap; va_start(ap, fmt); mlog(el::Level::Error, category, fmt, ap); va_end(ap); }
-void mwarning(const char *category, const char *fmt, ...) { va_list ap; va_start(ap, fmt); mlog(el::Level::Warning, category, fmt, ap); va_end(ap); }
-void minfo(const char *category, const char *fmt, ...) { va_list ap; va_start(ap, fmt); mlog(el::Level::Info, category, fmt, ap); va_end(ap); }
-void mdebug(const char *category, const char *fmt, ...) { va_list ap; va_start(ap, fmt); mlog(el::Level::Debug, category, fmt, ap); va_end(ap); }
-void mtrace(const char *category, const char *fmt, ...) { va_list ap; va_start(ap, fmt); mlog(el::Level::Trace, category, fmt, ap); va_end(ap); }
+#define DEFLOG(fun,lev) \
+ bool m##fun(const char *category, const char *fmt, ...) { va_list ap; va_start(ap, fmt); bool ret = mlog(el::Level::lev, category, fmt, ap); va_end(ap); return ret; }
+
+DEFLOG(error, Error)
+DEFLOG(warning, Warning)
+DEFLOG(info, Info)
+DEFLOG(debug, Debug)
+DEFLOG(trace, Trace)
+
+#undef DEFLOG
#endif //_MLOG_H_