35 template <
int Level>
char const * levelStr();
36 template <>
char const * levelStr<LOG_DEBUG>() {
return "DBG"; }
37 template <>
char const * levelStr<LOG_INFO>() {
return "INF"; }
38 template <>
char const * levelStr<LOG_ERR>() {
return "ERR"; }
39 template <>
char const * levelStr<LOG_CRIT>() {
return "FTL"; }
42 #ifdef JEVOIS_USE_SYNC_LOG
46 std::mutex logOutputMutex;
50 {
LFATAL(
"Cannot set Engine for logs when JeVois has been compiled with -D JEVOIS_USE_SYNC_LOG"); }
52 {
LINFO(
"Terminating Log service"); }
54 #else // JEVOIS_USE_SYNC_LOG
65 LogCore() : itsBuffer(10000), itsRunning(true)
66 #ifdef JEVOIS_LOG_TO_FILE
67 , itsStream(
"jevois.log")
80 itsBuffer.push(
"Terminating Log service");
90 std::string msg = itsBuffer.pop();
91 #ifdef JEVOIS_LOG_TO_FILE
92 itsStream << msg << std::endl;
94 #ifdef JEVOIS_PLATFORM
98 std::cerr << msg <<
'\r' << std::endl;
100 std::cerr << msg << std::endl;
103 if (itsEngine) itsEngine->sendSerial(msg,
true);
111 LINFO(
"Terminating log facility.");
115 volatile bool itsRunning;
116 std::future<void> itsRunFuture;
117 #ifdef JEVOIS_LOG_TO_FILE
118 std::ofstream itsStream;
126 #endif // JEVOIS_USE_SYNC_LOG
134 std::string
const fn(fullFileName);
135 size_t const lastSlashPos = fn.rfind(
'/');
136 size_t const lastDotPos = fn.rfind(
'.');
137 std::string
const partialFileName = fn.substr(lastSlashPos+1, lastDotPos-lastSlashPos-1);
140 itsLogStream << levelStr<Level>() <<
' ' << partialFileName <<
"::" << functionName <<
": ";
146 char const * JEVOIS_UNUSED_PARAM(functionName), std::string * outstr) :
153 #ifdef JEVOIS_USE_SYNC_LOG
158 std::lock_guard<std::mutex> guard(jevois::logOutputMutex);
159 std::string
const msg = itsLogStream.str();
160 std::cerr << msg << std::endl;
161 if (itsOutStr) *itsOutStr = msg;
164 #else // JEVOIS_USE_SYNC_LOG
169 std::string
const msg = itsLogStream.str();
170 LogCore::instance().itsBuffer.push(msg);
171 if (itsOutStr) *itsOutStr = msg;
173 #endif // JEVOIS_USE_SYNC_LOG
179 itsLogStream << static_cast<int>(out_item);
187 itsLogStream << static_cast<int>(out_item);
206 if (prefix.empty() ==
false) pfx = prefix +
": ";
211 catch (std::exception
const & e)
213 LERROR(pfx <<
"Passing through std::exception:");
214 std::vector<std::string> lines =
jevois::split(e.what(),
"\\n");
215 for (std::string
const & li : lines)
LERROR(li);
219 catch (boost::python::error_already_set & e)
221 LERROR(pfx <<
"Received exception from the Python interpreter:");
224 for (std::string
const & li : lines)
LERROR(li);
230 LERROR(pfx <<
"Passing through unknown exception");
239 if (prefix.empty() ==
false) pfx = prefix +
": ";
241 std::vector<std::string> retvec;
246 catch (std::exception
const & e)
248 retvec.emplace_back(pfx +
"Caught std::exception:");
249 std::vector<std::string> lines =
jevois::split(e.what(),
"\\n");
250 for (std::string
const & li : lines) retvec.emplace_back(li);
253 catch (boost::python::error_already_set & e)
255 retvec.emplace_back(pfx +
"Caught exception from the Python interpreter:");
258 for (std::string
const & li : lines) retvec.emplace_back(li);
263 retvec.emplace_back(pfx +
"Caught unknown exception");
268 for (std::string & m : retvec) {
LERROR(m); ret += m +
"\n"; }
275 std::string
const & strval)
277 LERROR(
"Parameter " << descriptor <<
": Provided value [" << strval <<
"] rejected by callback:");
282 catch (std::exception
const & e)
284 throw std::runtime_error(e.what());
287 catch (boost::python::error_already_set & e)
289 LERROR(
"Python exception:");
295 throw std::runtime_error(
"Caught unknown exception");
302 if (videoerrimg.
valid() ==
false) {
LERROR(
"Cannot draw in empty image -- IGNORED");
return; }
319 if (videoerrimg.
width <= 352 || videoerrimg.
height <= 240)
321 else if (videoerrimg.
width <= 640 || videoerrimg.
height <= 480)
326 std::vector<std::string> lines =
jevois::split(errmsg,
"\\n");
327 for (std::string & m : lines)
330 unsigned int nchar = (videoerrimg.
width - 6) / fw;
331 while (m.size() > nchar)
335 m = m.substr(nchar, m.npos);
348 if (itsMutex.try_lock_for(std::chrono::seconds(5)) ==
false)
351 throw std::runtime_error(
"FATAL DEADLOCK ERROR");
357 { itsMutex.unlock(); }