2016-12-12 18:13:33 +00:00
|
|
|
#include <boost/log/core.hpp>
|
|
|
|
#include <boost/log/trivial.hpp>
|
|
|
|
#include <boost/log/expressions.hpp>
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2017-03-03 13:38:25 +00:00
|
|
|
static boost::log::trivial::severity_level logSeverity = boost::log::trivial::error;
|
2016-12-12 18:13:33 +00:00
|
|
|
|
|
|
|
void set_logging_level(unsigned int level)
|
|
|
|
{
|
|
|
|
switch (level) {
|
2017-03-03 11:53:05 +00:00
|
|
|
// Report fatal errors only.
|
2016-12-12 18:13:33 +00:00
|
|
|
case 0: logSeverity = boost::log::trivial::fatal; break;
|
2017-03-03 11:53:05 +00:00
|
|
|
// Report fatal errors and errors.
|
2016-12-12 18:13:33 +00:00
|
|
|
case 1: logSeverity = boost::log::trivial::error; break;
|
2017-03-03 11:53:05 +00:00
|
|
|
// Report fatal errors, errors and warnings.
|
2016-12-12 18:13:33 +00:00
|
|
|
case 2: logSeverity = boost::log::trivial::warning; break;
|
2017-03-03 11:53:05 +00:00
|
|
|
// Report all errors, warnings and infos.
|
2016-12-12 18:13:33 +00:00
|
|
|
case 3: logSeverity = boost::log::trivial::info; break;
|
2017-03-03 11:53:05 +00:00
|
|
|
// Report all errors, warnings, infos and debugging.
|
2016-12-12 18:13:33 +00:00
|
|
|
case 4: logSeverity = boost::log::trivial::debug; break;
|
2017-03-03 11:53:05 +00:00
|
|
|
// Report everyting including fine level tracing information.
|
2016-12-12 18:13:33 +00:00
|
|
|
default: logSeverity = boost::log::trivial::trace; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::log::core::get()->set_filter
|
|
|
|
(
|
|
|
|
boost::log::trivial::severity >= logSeverity
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-03-03 13:38:25 +00:00
|
|
|
// Force set_logging_level(<=error) after loading of the DLL.
|
|
|
|
static struct SetLoggingLevelOnInit {
|
|
|
|
SetLoggingLevelOnInit() { set_logging_level(1); }
|
|
|
|
} g_SetLoggingLevelOnInit;
|
|
|
|
|
2017-03-03 11:53:05 +00:00
|
|
|
void trace(unsigned int level, const char *message)
|
|
|
|
{
|
|
|
|
boost::log::trivial::severity_level severity = boost::log::trivial::trace;
|
|
|
|
switch (level) {
|
|
|
|
// Report fatal errors only.
|
|
|
|
case 0: severity = boost::log::trivial::fatal; break;
|
|
|
|
// Report fatal errors and errors.
|
|
|
|
case 1: severity = boost::log::trivial::error; break;
|
|
|
|
// Report fatal errors, errors and warnings.
|
|
|
|
case 2: severity = boost::log::trivial::warning; break;
|
|
|
|
// Report all errors, warnings and infos.
|
|
|
|
case 3: severity = boost::log::trivial::info; break;
|
|
|
|
// Report all errors, warnings, infos and debugging.
|
|
|
|
case 4: severity = boost::log::trivial::debug; break;
|
|
|
|
// Report everyting including fine level tracing information.
|
|
|
|
default: severity = boost::log::trivial::trace; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_LOG_STREAM_WITH_PARAMS(::boost::log::trivial::logger::get(),\
|
|
|
|
(::boost::log::keywords::severity = severity)) << message;
|
|
|
|
}
|
|
|
|
|
2016-12-12 18:13:33 +00:00
|
|
|
} // namespace Slic3r
|
|
|
|
|
2016-11-08 09:49:32 +00:00
|
|
|
#ifdef SLIC3R_HAS_BROKEN_CROAK
|
|
|
|
|
|
|
|
// Some Strawberry Perl builds (mainly the latest 64bit builds) have a broken mechanism
|
|
|
|
// for emiting Perl exception after handling a C++ exception. Perl interpreter
|
|
|
|
// simply hangs. Better to show a message box in that case and stop the application.
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2016-11-08 09:59:43 +00:00
|
|
|
#include <string.h>
|
2016-11-08 09:49:32 +00:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
#include <Windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void confess_at(const char *file, int line, const char *func, const char *format, ...)
|
|
|
|
{
|
|
|
|
char dest[1024*8];
|
|
|
|
va_list argptr;
|
|
|
|
va_start(argptr, format);
|
|
|
|
vsprintf(dest, format, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
|
2016-11-08 10:15:09 +00:00
|
|
|
char filelinefunc[1024*8];
|
|
|
|
sprintf(filelinefunc, "\r\nin function: %s\r\nfile: %s\r\nline: %d\r\n", func, file, line);
|
|
|
|
strcat(dest, filelinefunc);
|
2016-11-08 09:49:32 +00:00
|
|
|
strcat(dest, "\r\n Closing the application.\r\n");
|
|
|
|
#ifdef WIN32
|
|
|
|
::MessageBoxA(NULL, dest, "Slic3r Prusa Edition", MB_OK | MB_ICONERROR);
|
2016-11-08 09:59:43 +00:00
|
|
|
#endif
|
2016-11-08 09:49:32 +00:00
|
|
|
|
|
|
|
// Give up.
|
|
|
|
printf(dest);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
#include <xsinit.h>
|
2013-09-09 19:40:57 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
confess_at(const char *file, int line, const char *func,
|
|
|
|
const char *pat, ...)
|
|
|
|
{
|
2013-09-13 12:48:40 +00:00
|
|
|
#ifdef SLIC3RXS
|
2013-09-09 19:40:57 +00:00
|
|
|
va_list args;
|
|
|
|
SV *error_sv = newSVpvf("Error in function %s at %s:%d: ", func,
|
|
|
|
file, line);
|
|
|
|
|
|
|
|
va_start(args, pat);
|
|
|
|
sv_vcatpvf(error_sv, pat, &args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
sv_catpvn(error_sv, "\n\t", 2);
|
|
|
|
|
|
|
|
dSP;
|
|
|
|
ENTER;
|
|
|
|
SAVETMPS;
|
|
|
|
PUSHMARK(SP);
|
|
|
|
XPUSHs( sv_2mortal(error_sv) );
|
|
|
|
PUTBACK;
|
|
|
|
call_pv("Carp::confess", G_DISCARD);
|
|
|
|
FREETMPS;
|
|
|
|
LEAVE;
|
2013-09-13 12:48:40 +00:00
|
|
|
#endif
|
2013-09-09 19:40:57 +00:00
|
|
|
}
|
2016-11-08 09:49:32 +00:00
|
|
|
|
|
|
|
#endif
|