YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
YarpLogger.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include <iostream>
7#include <cstring>
8#include <string>
9#include <sstream>
10#include <cstdio>
11#include <fstream>
12#include <iterator>
13#include <yarp/os/RpcClient.h>
14#include <yarp/os/SystemClock.h>
16
17using namespace yarp::os;
18using namespace yarp::yarpLogger;
19/*
20const std::string RED ="\033[01;31m";
21const std::string GREEN ="\033[01;32m";
22const std::string YELLOW ="\033[01;33m";
23const std::string BLUE ="\033[01;34m";
24const std::string CLEAR ="\033[00m";
25
26const std::string RED_ERROR = RED+"ERROR"+CLEAR;
27const std::string YELLOW_WARNING = YELLOW+"WARNING"+CLEAR;
28*/
35
37{
38 entry_list_max_size = size;
39 entry_list.reserve(entry_list_max_size);
41}
42
44{
45 entry_list_max_size_enabled=enable;
46}
47
49{
50 if (logInfo.logsize >= entry_list_max_size && entry_list_max_size_enabled)
51 {
52 //printf("WARNING: exceeded entry_list_max_size=%d\n",entry_list_max_size);
53 return false;
54 }
55 entry_list.push_back(entry);
57 return true;
58}
59
61{
62 logsize=0;
63 number_of_traces=0;
64 number_of_debugs=0;
65 number_of_infos=0;
66 number_of_warnings=0;
67 number_of_errors=0;
68 number_of_fatals=0;
69 highest_error=LOGLEVEL_UNDEFINED;
70 last_update=-1;
71}
72
74{
75 return highest_error;
76}
77
79{
80 highest_error=LOGLEVEL_UNDEFINED;
81}
82
84{
85 if (level == LOGLEVEL_TRACE) {
86 number_of_traces++;
87 } else if (level == LOGLEVEL_DEBUG) {
88 number_of_debugs++;
89 } else if (level == LOGLEVEL_INFO) {
90 number_of_infos++;
91 } else if (level == LOGLEVEL_WARNING) {
92 number_of_warnings++;
93 } else if (level == LOGLEVEL_ERROR) {
94 number_of_errors++;
95 } else if (level == LOGLEVEL_FATAL) {
96 number_of_fatals++;
97 }
98 if (level > highest_error) {
99 highest_error = level;
100 }
101}
102
103void LoggerEngine::discover (std::list<std::string>& ports)
104{
105 RpcClient p;
106 std::string logger_portname = log_updater->getPortName();
107 p.open(logger_portname+"/discover");
110 Bottle cmd,response;
111 cmd.addString("bot");
112 cmd.addString("list");
113 p.write(cmd,response);
114 printf ("%s\n\n", response.toString().c_str());
115 int size = response.size();
116 for (int i=1; i<size; i++) //beware: skip i=0 is intentional!
117 {
118 Bottle* n1 = response.get(i).asList();
119 if (n1 && n1->get(0).toString()=="port")
120 {
121 Bottle* n2 = n1->get(1).asList();
122 if (n2 && n2->get(0).toString()=="name")
123 {
124 char* log_off = nullptr;
125 char* yarprun_log_off = nullptr;
126 log_off = std::strstr((char*)(n2->get(1).toString().c_str()), "/log/");
127 if (log_off)
128 {
129 std::string logport = n2->get(1).toString();
130 printf ("%s\n", logport.c_str());
131 ports.push_back(logport);
132 }
133 yarprun_log_off = std::strstr((char*)(n2->get(1).toString().c_str()), "/yarprunlog/");
134 if (yarprun_log_off)
135 {
136 std::string logport = n2->get(1).toString();
137 printf ("%s\n", logport.c_str());
138 ports.push_back(logport);
139 }
140 }
141 }
142 }
143
144 std::list<std::string>::iterator ports_it;
145 for (ports_it=ports.begin(); ports_it!=ports.end(); ports_it++)
146 {
147 LogEntry entry (log_updater->logs_max_lines_enabled, log_updater->logs_max_lines);
148 entry.logInfo.port_complete = (*ports_it);
149 yarp::os::Contact contact = yarp::os::Network::queryName(entry.logInfo.port_complete);
150 if (contact.isValid())
151 {
152 entry.logInfo.ip_address = contact.getHost();
153 }
154 else
155 {
156 printf("ERROR: invalid contact: %s\n", entry.logInfo.port_complete.c_str());
157 }
158 std::istringstream iss(*ports_it);
159 std::string token;
160 getline(iss, token, '/');
161 getline(iss, token, '/');
162 getline(iss, token, '/'); entry.logInfo.port_prefix = "/"+ token;
163 getline(iss, token, '/'); entry.logInfo.process_name = token;
164 getline(iss, token, '/'); entry.logInfo.process_pid = token;
165
166 std::list<LogEntry>::iterator it;
167 this->log_updater->mutex.lock();
168 bool found = false;
169 for (it = this->log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
170 {
171 if (it->logInfo.port_complete==entry.logInfo.port_complete)
172 {
173 found=true; break;
174 }
175 }
176 if (found==false)
177 {
178 log_updater->log_list.push_back(entry);
179 }
180 this->log_updater->mutex.unlock();
181 }
182}
183
184void LoggerEngine::connect (const std::list<std::string>& ports)
185{
187 style.timeout=1.0;
188 style.quiet=true;
189
190 std::list<std::string>::const_iterator it;
191 bool b_connected = true;
192 for (it = ports.begin(); it != ports.end(); it++)
193 {
194 if (yarp::os::Network::exists(*it,style) == true)
195 {
196 b_connected &= yarp::os::Network::connect(*it,this->log_updater->getPortName());
197 }
198 else
199 {
200 //fprintf(stderr,"unable to connect to port %s\n",it->c_str());
201 }
202 }
203}
204
205std::string LoggerEngine::logger_thread::getPortName()
206{
207 return logger_portName;
208}
209
210LoggerEngine::logger_thread::logger_thread (std::string _portname, double _period, int _log_list_max_size, int _logs_max_lines) :
212{
213 logger_portName = _portname;
214 log_list_max_size = _log_list_max_size;
215 log_list_max_size_enabled = true;
216 logs_max_lines = _logs_max_lines;
217 logs_max_lines_enabled = true;
218 unknown_format_received = 0;
219}
220
221void LoggerEngine::logger_thread::run()
222{
223 //yarp::os::SystemClock::delaySystem(0.001);
224
225 //if (logger_port.getInputCount()>0)
226 {
227 int bufferport_size = logger_port.getPendingReads();
228 int processed_events = 0;
229
230 while (bufferport_size>0)
231 {
232 //the following check allows to exit from the run every xxx processed events,
233 //in order to free some CPU and avoid the system to be blocked forever inside the while.
234 if (processed_events > 1000)
235 {
236 fprintf(stderr, "DEBUG: processing log events... Remaining events: %d\n", bufferport_size);
237 return;
238 }
240
241 std::time_t machine_current_time = std::time(nullptr);
242 char machine_current_time_c [50];
243 //strftime(machine_current_time_s, 20, "%Y-%m-%d %H:%M:%S", localtime(&machine_current_time));
247 std::string machine_current_time_s = std::string(machine_current_time_c);
248
249 Bottle *b = logger_port.read(); //this is blocking
250 bufferport_size = logger_port.getPendingReads();
251
252 if (b==nullptr)
253 {
254 fprintf (stderr, "ERROR: something strange happened here, bufferport_size = %d!\n",bufferport_size);
255 return;
256 }
257
258 if (b->size()!=2)
259 {
260 fprintf (stderr, "ERROR: unknown log format [err1]!\n");
261 unknown_format_received++;
262 continue;
263 }
264
265 std::string bottlestring = b->toString();
266 std::string header;
267
268 if (b->get(0).isString())
269 {
270 header = b->get(0).asString();
271 }
272 else
273 {
274 fprintf(stderr, "ERROR: unknown log format! [err2]\n");
275 unknown_format_received++;
276 continue;
277 }
278
279 MessageEntry body;
280
281 char ttstr [20];
282 static int count=0;
283 sprintf(ttstr,"%d",count++);
284 body.yarprun_timestamp = std::string(ttstr);
286
287 std::string s;
288
289 if (b->get(1).isString())
290 {
291 s = b->get(1).asString();
292 }
293 else
294 {
295 fprintf(stderr, "ERROR: unknown log format! [err3]\n");
296 unknown_format_received++;
297 continue;
298 }
299
300 yarp::os::Property p(s.c_str());
301
302 if (p.check("level")) {
303 body.text = p.find("message").toString();
304
305 auto level = p.find("level").toString();
306 if (level == "TRACE") {
307 body.level = LOGLEVEL_TRACE;
308 } else if (level == "DEBUG") {
309 body.level = LOGLEVEL_DEBUG;
310 } else if (level == "INFO") {
311 body.level = LOGLEVEL_INFO;
312 } else if (level == "WARNING") {
313 body.level = LOGLEVEL_WARNING;
314 } else if (level == "ERROR") {
315 body.level = LOGLEVEL_ERROR;
316 } else if (level == "FATAL") {
317 body.level = LOGLEVEL_FATAL;
318 } else {
320 }
321
322 if (p.check("filename")) {
323 body.filename = p.find("filename").asString();
324 } else {
325 body.filename.clear();
326 }
327
328 if (p.check("line")) {
329 body.line = static_cast<uint32_t>(p.find("line").asInt32());
330 } else {
331 body.line = 0;
332 }
333
334 if (p.check("function")) {
335 body.function = p.find("function").asString();
336 } else {
337 body.function.clear();
338 }
339
340 if (p.check("hostname")) {
341 body.hostname = p.find("hostname").asString();
342 } else {
343 body.hostname.clear();
344 }
345
346 if (p.check("pid")) {
347 body.pid = p.find("pid").asInt32();
348 } else {
349 body.pid = 0;
350 }
351
352 if (p.check("cmd")) {
353 body.cmd = p.find("cmd").asString();
354 } else {
355 body.cmd.clear();
356 }
357
358 if (p.check("args")) {
359 body.args = p.find("args").asString();
360 } else {
361 body.args.clear();
362 }
363
364 if (p.check("thread_id")) {
365 body.thread_id = p.find("thread_id").asInt64();
366 } else {
367 body.thread_id = 0;
368 }
369
370 if (p.check("component")) {
371 body.component = p.find("component").asString();
372 } else {
373 body.component.clear();
374 }
375
376 if (p.check("id")) {
377 body.id = p.find("id").asString();
378 } else {
379 body.id.clear();
380 }
381
382 if (p.check("systemtime")) {
383 body.systemtime = p.find("systemtime").asFloat64();
384 } else {
385 body.systemtime = 0.0;
386 }
387
388 if (p.check("networktime")) {
389 body.networktime = p.find("networktime").asFloat64();
390 } else {
391 body.networktime = body.systemtime;
392 body.yarprun_timestamp.clear();
393 }
394
395 if (p.check("externaltime")) {
396 body.externaltime = p.find("externaltime").asFloat64();
397 } else {
398 body.externaltime = 0.0;
399 }
400
401 if (p.check("backtrace")) {
402 body.backtrace = p.find("backtrace").asString();
403 } else {
404 body.backtrace.clear();
405 }
406 } else {
407 // This is plain output forwarded by yarprun
408 // Perhaps at some point yarprun could be formatting it properly
409 // But for now we just try to extract the level information
410 body.text = s;
412
413 size_t str = s.find('[',0);
414 size_t end = s.find(']',0);
415 if (str==std::string::npos || end==std::string::npos )
416 {
418 }
419 else if (str==0)
420 {
421 std::string level = s.substr(str,end+1);
423 if (level.find("TRACE") != std::string::npos) {
424 body.level = LOGLEVEL_TRACE;
425 } else if (level.find("DEBUG") != std::string::npos) {
426 body.level = LOGLEVEL_DEBUG;
427 } else if (level.find("INFO") != std::string::npos) {
428 body.level = LOGLEVEL_INFO;
429 } else if (level.find("WARNING") != std::string::npos) {
430 body.level = LOGLEVEL_WARNING;
431 } else if (level.find("ERROR") != std::string::npos) {
432 body.level = LOGLEVEL_ERROR;
433 } else if (level.find("FATAL") != std::string::npos) {
434 body.level = LOGLEVEL_FATAL;
435 }
436 body.text = s.substr(end+1);
437 }
438 else
439 {
441 }
442 }
443
444 if (body.level == LOGLEVEL_UNDEFINED && listen_to_LOGLEVEL_UNDEFINED == false) {continue;}
445 if (body.level == LOGLEVEL_TRACE && listen_to_LOGLEVEL_TRACE == false) {continue;}
446 if (body.level == LOGLEVEL_DEBUG && listen_to_LOGLEVEL_DEBUG == false) {continue;}
447 if (body.level == LOGLEVEL_INFO && listen_to_LOGLEVEL_INFO == false) {continue;}
448 if (body.level == LOGLEVEL_WARNING && listen_to_LOGLEVEL_WARNING == false) {continue;}
449 if (body.level == LOGLEVEL_ERROR && listen_to_LOGLEVEL_ERROR == false) {continue;}
450 if (body.level == LOGLEVEL_FATAL && listen_to_LOGLEVEL_FATAL == false) {continue;}
451
452 LogEntry entry (this->logs_max_lines_enabled, this->logs_max_lines);
453 entry.logInfo.port_complete = header;
454 entry.logInfo.port_complete.erase(0,1);
455 entry.logInfo.port_complete.erase(entry.logInfo.port_complete.size()-1);
456 std::istringstream iss(header);
457 std::string token;
458 getline(iss, token, '/');
459 getline(iss, token, '/'); entry.logInfo.port_system = token;
460 getline(iss, token, '/'); entry.logInfo.port_prefix = "/"+ token;
461 getline(iss, token, '/'); entry.logInfo.process_name = token;
462 getline(iss, token, '/'); entry.logInfo.process_pid = token.erase(token.size()-1);
463 if (entry.logInfo.port_system == "log" && listen_to_YARP_MESSAGES == false) {
464 continue;
465 }
466 if (entry.logInfo.port_system == "yarprunlog" && listen_to_YARPRUN_MESSAGES == false) {
467 continue;
468 }
469
470 //-------- enter the critical section.
471 // the following variables must be protected: log_list
472 this->mutex.lock();
473 std::list<LogEntry>::iterator it;
474 for (it = log_list.begin(); it != log_list.end(); it++)
475 {
476 if (it->logInfo.port_complete==entry.logInfo.port_complete)
477 {
478 if (it->logging_enabled)
479 {
480 it->logInfo.setNewError(body.level);
481 it->logInfo.last_update=machine_current_time;
482 it->append_logEntry(body);
483 }
484 else
485 {
486 //just skipping this message
487 }
488 break;
489 }
490 }
491 if (it == log_list.end())
492 {
493 if (log_list.size() < log_list_max_size || log_list_max_size_enabled==false )
494 {
495 yarp::os::Contact contact = yarp::os::Network::queryName(entry.logInfo.port_complete);
496 if (contact.isValid())
497 {
498 entry.logInfo.setNewError(body.level);
499 entry.logInfo.ip_address = contact.getHost();
500 }
501 else
502 {
503 printf("ERROR: invalid contact: %s\n", entry.logInfo.port_complete.c_str());
504 };
505 entry.append_logEntry(body);
506 entry.logInfo.last_update=machine_current_time;
507 log_list.push_back(entry);
508 }
509 //else
510 //{
511 // printf("WARNING: exceeded log_list_max_size=%d\n",log_list_max_size);
512 //}
513 }
514 this->mutex.unlock();
515 //-------- end of the critical section.
516 }
517 }
518
519}
520
521//public methods
523{
524 if (logging == true)
525 {
526 fprintf(stderr,"logger is already running, listening on port %s\n", log_updater->getPortName().c_str());
527 return true;
528 }
529
530 if (yarp::os::Network::exists(log_updater->getPortName()))
531 {
532 fprintf(stderr, "Unable to start logger: port %s is unavailable because another instance of the logger is already running (or address conflict)\n", log_updater->getPortName().c_str());
533 return false;
534 }
535
536 if (log_updater->logger_port.open(log_updater->getPortName()))
537 {
538 fprintf(stdout,"Logger successfully started, listening on port %s\n", log_updater->getPortName().c_str());
539 }
540 else
541 {
542 fprintf(stderr,"Unable to start logger: port %s is unavailable\n", log_updater->getPortName().c_str());
543 return false;
544 }
545 log_updater->logger_port.resume();
546 log_updater->logger_port.setStrict();
547 logging=true;
548 log_updater->start();
549 return true;
550}
551
552void LoggerEngine::logger_thread::threadRelease()
553{
554 logger_port.interrupt();
555 logger_port.close();
556}
557
559{
560 if (log_updater == nullptr) {
561 fprintf(stdout, "Logger stop internal error");
562 return false;
563 }
564
565 logging=false;
566 if (log_updater->isRunning() == true) {
567 log_updater->stop();
568 }
569
570 fprintf(stdout, "Logger successfully stopped");
571 return true;
572}
573
575{
576 if (log_updater == nullptr) {
577 fprintf(stdout, "Logger start_discoverry internal error");
578 return;
579 }
580
581 fprintf(stdout, "Logger discovery started");
582 log_updater->start();
583 discovering=true;
584}
585
587{
588 fprintf(stdout, "Logger discovery stopped");
589 discovering=false;
590}
591
592LoggerEngine::LoggerEngine(std::string portName)
593{
594 log_updater=new logger_thread (portName, 0.01);
595 logging = false;
596 discovering = false;
597}
598
600{
601 this->stop_logging();
602 if (log_updater!=nullptr)
603 {
604 delete log_updater;
605 log_updater = nullptr;
606 }
607}
608
610{
611 if (log_updater == nullptr) {
612 return 0;
613 }
614
615 return log_updater->logger_port.getInputCount();
616}
617
618void LoggerEngine::get_infos (std::list<LogEntryInfo>& infos)
619{
620 if (log_updater == nullptr) {
621 return;
622 }
623
624 log_updater->mutex.lock();
625 std::list<LogEntry>::iterator it;
626 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
627 {
628 infos.push_back(it->logInfo);
629 }
630 log_updater->mutex.unlock();
631}
632
633void LoggerEngine::get_messages (std::list<MessageEntry>& messages)
634{
635 if (log_updater == nullptr) {
636 return;
637 }
638
639 log_updater->mutex.lock();
640 std::list<LogEntry>::iterator it;
641 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
642 {
643 messages.insert(messages.end(), it->entry_list.begin(), it->entry_list.end());
644 }
645 log_updater->mutex.unlock();
646}
647
648void LoggerEngine::get_messages_by_port_prefix (std::string port, std::list<MessageEntry>& messages, bool from_beginning)
649{
650 if (log_updater == nullptr) {
651 return;
652 }
653
654 log_updater->mutex.lock();
655 std::list<LogEntry>::iterator it;
656 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
657 {
658 if (it->logInfo.port_prefix == port)
659 {
660 //messages = (it->entry_list);
661 if (it->last_read_message==-1)
662 {
663 from_beginning=true;
664 }
665 if (from_beginning==true)
666 {
667 it->last_read_message = 0;
668 }
669 int i=it->last_read_message;
670 for (; i<(int)it->entry_list.size(); i++)
671 {
672 messages.push_back(it->entry_list[i]);
673 }
674 it->last_read_message=i;
675 break;
676 }
677 }
678 log_updater->mutex.unlock();
679}
680
682{
683 if (log_updater == nullptr) {
684 return;
685 }
686
687 log_updater->mutex.lock();
688 std::list<LogEntry>::iterator it;
689 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
690 {
691 if (it->logInfo.port_complete == port)
692 {
693 it->clear_logEntries();
694 break;
695 }
696 }
697 log_updater->mutex.unlock();
698}
699
700void LoggerEngine::get_messages_by_port_complete (std::string port, std::list<MessageEntry>& messages, bool from_beginning)
701{
702 if (log_updater == nullptr) {
703 return;
704 }
705
706 log_updater->mutex.lock();
707 std::list<LogEntry>::iterator it;
708 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
709 {
710 if (it->logInfo.port_complete == port)
711 {
712 //messages = (it->entry_list);
713 if (it->last_read_message==-1)
714 {
715 from_beginning=true;
716 }
717 if (from_beginning==true)
718 {
719 it->last_read_message = 0;
720 }
721 int i=it->last_read_message;
722 int size = (int)it->entry_list.size();
723 for (; i<size; i++)
724 {
725 messages.push_back(it->entry_list[i]);
726 }
727 it->last_read_message=i;
728 break;
729 }
730 }
731 log_updater->mutex.unlock();
732}
733
734void LoggerEngine::get_messages_by_process (std::string process, std::list<MessageEntry>& messages, bool from_beginning)
735{
736 if (log_updater == nullptr) {
737 return;
738 }
739
740 log_updater->mutex.lock();
741 std::list<LogEntry>::iterator it;
742 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
743 {
744 if (it->logInfo.process_name == process)
745 {
746 //messages = (it->entry_list);
747 if (it->last_read_message==-1)
748 {
749 from_beginning=true;
750 }
751 if (from_beginning==true)
752 {
753 it->last_read_message = 0;
754 }
755 int i=it->last_read_message;
756 for (; i<(int)it->entry_list.size(); i++)
757 {
758 messages.push_back(it->entry_list[i]);
759 }
760 it->last_read_message=i;
761 break;
762 }
763 }
764 log_updater->mutex.unlock();
765}
766
767void LoggerEngine::get_messages_by_pid (std::string pid, std::list<MessageEntry>& messages, bool from_beginning)
768{
769 if (log_updater == nullptr) {
770 return;
771 }
772
773 log_updater->mutex.lock();
774 std::list<LogEntry>::iterator it;
775 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
776 {
777 if (it->logInfo.process_pid == pid)
778 {
779 //messages = (it->entry_list);
780 if (it->last_read_message==-1)
781 {
782 from_beginning=true;
783 }
784 if (from_beginning==true)
785 {
786 it->last_read_message = 0;
787 }
788 int i=it->last_read_message;
789 for (; i<(int)it->entry_list.size(); i++)
790 {
791 messages.push_back(it->entry_list[i]);
792 }
793 it->last_read_message=i;
794 break;
795 }
796 }
797 log_updater->mutex.unlock();
798}
799
800const std::list<MessageEntry> filter_by_level (int level, const std::list<MessageEntry>& messages)
801{
802 std::list<MessageEntry> ret;
803 std::list<MessageEntry>::const_iterator it;
804 for (it = messages.begin(); it != messages.end(); it++)
805 {
806 LogLevel llevel = it->level;
807 if (llevel.toInt() == level) {
808 ret.push_back(*it);
809 }
810 }
811 return ret;
812}
813
815{
816 if (log_updater == nullptr) {
817 return;
818 }
819 log_updater->mutex.lock();
820 if (logLevel == LOGLEVEL_UNDEFINED) {log_updater->listen_to_LOGLEVEL_UNDEFINED=enable;}
821 else if (logLevel == LOGLEVEL_TRACE) {log_updater->listen_to_LOGLEVEL_TRACE=enable;}
822 else if (logLevel == LOGLEVEL_INFO) {log_updater->listen_to_LOGLEVEL_INFO=enable;}
823 else if (logLevel == LOGLEVEL_DEBUG) {log_updater->listen_to_LOGLEVEL_DEBUG=enable;}
824 else if (logLevel == LOGLEVEL_WARNING) {log_updater->listen_to_LOGLEVEL_WARNING=enable;}
825 else if (logLevel == LOGLEVEL_ERROR) {log_updater->listen_to_LOGLEVEL_ERROR=enable;}
826 else if (logLevel == LOGLEVEL_FATAL) {log_updater->listen_to_LOGLEVEL_FATAL=enable;}
827 log_updater->mutex.unlock();
828}
829
831{
832 if (log_updater == nullptr) {
833 return false;
834 }
835 if (logLevel == LOGLEVEL_UNDEFINED) {return log_updater->listen_to_LOGLEVEL_UNDEFINED;}
836 if (logLevel == LOGLEVEL_TRACE) {return log_updater->listen_to_LOGLEVEL_TRACE;}
837 if (logLevel == LOGLEVEL_DEBUG) {return log_updater->listen_to_LOGLEVEL_DEBUG;}
838 if (logLevel == LOGLEVEL_INFO) {return log_updater->listen_to_LOGLEVEL_INFO;}
839 if (logLevel == LOGLEVEL_WARNING) {return log_updater->listen_to_LOGLEVEL_WARNING;}
840 if (logLevel == LOGLEVEL_ERROR) {return log_updater->listen_to_LOGLEVEL_ERROR;}
841 if (logLevel == LOGLEVEL_FATAL) {return log_updater->listen_to_LOGLEVEL_FATAL;}
842 return false;
843}
844
845void LoggerEngine::set_listen_option (std::string option, bool enable)
846{
847 if (log_updater == nullptr) {
848 return;
849 }
850 log_updater->mutex.lock();
851 log_updater->mutex.unlock();
852}
853
855{
856 return false;
857}
858
860{
861 if (log_updater == nullptr) {
862 return;
863 }
864 log_updater->mutex.lock();
865 if (logSystem == LOGSYSTEM_YARP) {log_updater->listen_to_YARP_MESSAGES=enable;}
866 else if (logSystem == LOGSYSTEM_YARPRUN) {log_updater->listen_to_YARPRUN_MESSAGES=enable;}
867 log_updater->mutex.unlock();
868}
869
871{
872 if (log_updater == nullptr) {
873 return false;
874 }
875 if (logSystem == LOGSYSTEM_YARP) {return log_updater->listen_to_YARP_MESSAGES;}
876 if (logSystem == LOGSYSTEM_YARPRUN) {return log_updater->listen_to_YARPRUN_MESSAGES;}
877 return false;
878}
879
881{
882 if (log_updater == nullptr) {
883 return;
884 }
885
886 log_updater->mutex.lock();
887 log_updater->logs_max_lines_enabled = enabled;
888 log_updater->logs_max_lines = new_size;
889
890 std::list<LogEntry>::iterator it;
891 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
892 {
893 it->setLogEntryMaxSize(new_size);
894 it->setLogEntryMaxSizeEnabled(enabled);
895 }
896
897 log_updater->mutex.unlock();
898}
899
900
902{
903 if (log_updater == nullptr) {
904 return;
905 }
906 log_updater->mutex.lock();
907 log_updater->log_list_max_size_enabled = enabled;
908 log_updater->log_list_max_size = new_size;
909 log_updater->mutex.unlock();
910}
911
913{
914 if (log_updater == nullptr) {
915 return;
916 }
917
918 log_updater->mutex.lock();
919 enabled = log_updater->logs_max_lines_enabled;
920 current_size = log_updater->logs_max_lines;
921 log_updater->mutex.unlock();
922}
923
925{
926 if (log_updater == nullptr) {
927 return;
928 }
929 log_updater->mutex.lock();
930 enabled=log_updater->log_list_max_size_enabled;
931 current_size=log_updater->log_list_max_size;
932 log_updater->mutex.unlock();
933}
934
936{
937 if (log_updater == nullptr) {
938 return false;
939 }
940 log_updater->mutex.lock();
941 log_updater->log_list.clear();
942 log_updater->mutex.unlock();
943 return true;
944}
945
946void LoggerEngine::set_log_enable_by_port_complete (std::string port, bool enable)
947{
948 if (log_updater == nullptr) {
949 return;
950 }
951
952 log_updater->mutex.lock();
953 std::list<LogEntry>::iterator it;
954 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
955 {
956 if (it->logInfo.port_complete == port)
957 {
958 it->logging_enabled=enable;
959 break;
960 }
961 }
962 log_updater->mutex.unlock();
963}
964
966{
967 if (log_updater == nullptr) {
968 return false;
969 }
970
971 bool enabled=false;
972 log_updater->mutex.lock();
973 std::list<LogEntry>::iterator it;
974 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
975 {
976 if (it->logInfo.port_complete == port)
977 {
978 enabled=it->logging_enabled;
979 break;
980 }
981 }
982 log_updater->mutex.unlock();
983 return enabled;
984}
bool ret
const std::list< MessageEntry > filter_by_level(int level, const std::list< MessageEntry > &messages)
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:65
size_type size() const
Gets the number of elements in the bottle.
Definition Bottle.cpp:257
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Definition Bottle.cpp:246
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:252
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Definition Bottle.cpp:176
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition Bottle.cpp:217
A mini-server for performing network communication in the background.
int getPendingReads() override
Get the number of objects ready to be read.
Preferences for how to communicate with a contact.
double timeout
Set a timeout for communication (in units of seconds, fractional seconds allowed).
bool quiet
Suppress all outputs and warnings.
Represents how to reach a part of a YARP network.
Definition Contact.h:33
bool isValid() const
Checks if a Contact is tagged as valid.
Definition Contact.cpp:298
std::string getHost() const
Get the host name associated with this Contact for socket communication.
Definition Contact.cpp:228
static std::string getNameServerName()
Get the name of the port associated with the nameserver (usually "/root", but this can be overwritten...
Definition Network.cpp:1345
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
Definition Network.cpp:682
static Contact queryName(const std::string &name)
Find out information about a registered name.
Definition Network.cpp:995
static bool exists(const std::string &port, bool quiet=true, bool checkVer=true)
Check for a port to be ready and responsive.
Definition Network.cpp:746
An abstraction for a periodic thread.
A class for storing options and configuration information.
Definition Property.h:33
A port that is specialized as an RPC client.
Definition RpcClient.h:22
static double nowSystem()
virtual bool isString() const
Checks if value is a string.
Definition Value.cpp:156
virtual Bottle * asList() const
Get list value.
Definition Value.cpp:252
virtual std::string asString() const
Get string value.
Definition Value.cpp:246
void setNewError(LogLevel level)
yarp::yarpLogger::LogEntryInfo logInfo
Definition YarpLogger.h:208
void setLogEntryMaxSizeEnabled(bool enable)
bool append_logEntry(MessageEntry entry)
void setLogEntryMaxSize(int size)
std::vector< MessageEntry > entry_list
Definition YarpLogger.h:187
void set_log_list_max_size(bool enabled, int new_size)
bool get_listen_option(LogLevel logLevel)
void connect(const std::list< std::string > &ports)
void get_log_lines_max_size(bool &enabled, int &current_size)
void get_messages(std::list< MessageEntry > &messages)
bool get_log_enable_by_port_complete(std::string port)
void get_messages_by_port_prefix(std::string port, std::list< MessageEntry > &messages, bool from_beginning=false)
LoggerEngine(std::string portName)
void clear_messages_by_port_complete(std::string port)
void get_messages_by_port_complete(std::string port, std::list< MessageEntry > &messages, bool from_beginning=false)
void set_log_lines_max_size(bool enabled, int new_size)
void get_messages_by_process(std::string process, std::list< MessageEntry > &messages, bool from_beginning=false)
void discover(std::list< std::string > &ports)
void get_log_list_max_size(bool &enabled, int &current_size)
void get_infos(std::list< LogEntryInfo > &infos)
void set_log_enable_by_port_complete(std::string port, bool enable)
void set_listen_option(LogLevel logLevel, bool enable)
void get_messages_by_pid(std::string pid, std::list< MessageEntry > &messages, bool from_beginning=false)
An interface to the operating system, including Port based communication.
ShouldUseSystemClock
Definition Time.h:19