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 for (it = ports.begin(); it != ports.end(); it++)
192 {
193 if (yarp::os::Network::exists(*it,style) == true)
194 {
195 yarp::os::Network::connect(*it,this->log_updater->getPortName());
196 }
197 else
198 {
199 //fprintf(stderr,"unable to connect to port %s\n",it->c_str());
200 }
201 }
202}
203
204std::string LoggerEngine::logger_thread::getPortName()
205{
206 return logger_portName;
207}
208
209LoggerEngine::logger_thread::logger_thread (std::string _portname, double _period, int _log_list_max_size, int _logs_max_lines) :
211{
212 logger_portName = _portname;
213 log_list_max_size = _log_list_max_size;
214 log_list_max_size_enabled = true;
215 logs_max_lines = _logs_max_lines;
216 logs_max_lines_enabled = true;
217 unknown_format_received = 0;
218}
219
220void LoggerEngine::logger_thread::run()
221{
222 //yarp::os::SystemClock::delaySystem(0.001);
223
224 //if (logger_port.getInputCount()>0)
225 {
226 int bufferport_size = logger_port.getPendingReads();
227 int processed_events = 0;
228
229 while (bufferport_size>0)
230 {
231 //the following check allows to exit from the run every xxx processed events,
232 //in order to free some CPU and avoid the system to be blocked forever inside the while.
233 if (processed_events > 1000)
234 {
235 fprintf(stderr, "DEBUG: processing log events... Remaining events: %d\n", bufferport_size);
236 return;
237 }
239
240 std::time_t machine_current_time = std::time(nullptr);
241 char machine_current_time_c [50];
242 //strftime(machine_current_time_s, 20, "%Y-%m-%d %H:%M:%S", localtime(&machine_current_time));
246 std::string machine_current_time_s = std::string(machine_current_time_c);
247
248 Bottle *b = logger_port.read(); //this is blocking
249 bufferport_size = logger_port.getPendingReads();
250
251 if (b==nullptr)
252 {
253 fprintf (stderr, "ERROR: something strange happened here, bufferport_size = %d!\n",bufferport_size);
254 return;
255 }
256
257 if (b->size()!=2)
258 {
259 fprintf (stderr, "ERROR: unknown log format!\n");
260 unknown_format_received++;
261 continue;
262 }
263
264 std::string bottlestring = b->toString();
265 std::string header;
266
267 if (b->get(0).isString())
268 {
269 header = b->get(0).asString();
270 }
271 else
272 {
273 fprintf(stderr, "ERROR: unknown log format!\n");
274 unknown_format_received++;
275 continue;
276 }
277
278 MessageEntry body;
279
280 char ttstr [20];
281 static int count=0;
282 sprintf(ttstr,"%d",count++);
283 body.yarprun_timestamp = std::string(ttstr);
285
286 std::string s;
287
288 if (b->get(1).isString())
289 {
290 s = b->get(1).asString();
291 }
292 else
293 {
294 fprintf(stderr, "ERROR: unknown log format!\n");
295 unknown_format_received++;
296 continue;
297 }
298
299 yarp::os::Property p(s.c_str());
300
301 if (p.check("level")) {
302 body.text = p.find("message").toString();
303
304 auto level = p.find("level").toString();
305 if (level == "TRACE") {
306 body.level = LOGLEVEL_TRACE;
307 } else if (level == "DEBUG") {
308 body.level = LOGLEVEL_DEBUG;
309 } else if (level == "INFO") {
310 body.level = LOGLEVEL_INFO;
311 } else if (level == "WARNING") {
312 body.level = LOGLEVEL_WARNING;
313 } else if (level == "ERROR") {
314 body.level = LOGLEVEL_ERROR;
315 } else if (level == "FATAL") {
316 body.level = LOGLEVEL_FATAL;
317 } else {
319 }
320
321 if (p.check("filename")) {
322 body.filename = p.find("filename").asString();
323 } else {
324 body.filename.clear();
325 }
326
327 if (p.check("line")) {
328 body.line = static_cast<uint32_t>(p.find("line").asInt32());
329 } else {
330 body.line = 0;
331 }
332
333 if (p.check("function")) {
334 body.function = p.find("function").asString();
335 } else {
336 body.function.clear();
337 }
338
339 if (p.check("hostname")) {
340 body.hostname = p.find("hostname").asString();
341 } else {
342 body.hostname.clear();
343 }
344
345 if (p.check("pid")) {
346 body.pid = p.find("pid").asInt32();
347 } else {
348 body.pid = 0;
349 }
350
351 if (p.check("cmd")) {
352 body.cmd = p.find("cmd").asString();
353 } else {
354 body.cmd.clear();
355 }
356
357 if (p.check("args")) {
358 body.args = p.find("args").asString();
359 } else {
360 body.args.clear();
361 }
362
363 if (p.check("thread_id")) {
364 body.thread_id = p.find("thread_id").asInt64();
365 } else {
366 body.thread_id = 0;
367 }
368
369 if (p.check("component")) {
370 body.component = p.find("component").asString();
371 } else {
372 body.component.clear();
373 }
374
375 if (p.check("id")) {
376 body.id = p.find("id").asString();
377 } else {
378 body.id.clear();
379 }
380
381 if (p.check("systemtime")) {
382 body.systemtime = p.find("systemtime").asFloat64();
383 } else {
384 body.systemtime = 0.0;
385 }
386
387 if (p.check("networktime")) {
388 body.networktime = p.find("networktime").asFloat64();
389 } else {
390 body.networktime = body.systemtime;
391 body.yarprun_timestamp.clear();
392 }
393
394 if (p.check("externaltime")) {
395 body.externaltime = p.find("externaltime").asFloat64();
396 } else {
397 body.externaltime = 0.0;
398 }
399
400 if (p.check("backtrace")) {
401 body.backtrace = p.find("backtrace").asString();
402 } else {
403 body.backtrace.clear();
404 }
405 } else {
406 // This is plain output forwarded by yarprun
407 // Perhaps at some point yarprun could be formatting it properly
408 // But for now we just try to extract the level information
409 body.text = s;
411
412 size_t str = s.find('[',0);
413 size_t end = s.find(']',0);
414 if (str==std::string::npos || end==std::string::npos )
415 {
417 }
418 else if (str==0)
419 {
420 std::string level = s.substr(str,end+1);
422 if (level.find("TRACE") != std::string::npos) {
423 body.level = LOGLEVEL_TRACE;
424 } else if (level.find("DEBUG") != std::string::npos) {
425 body.level = LOGLEVEL_DEBUG;
426 } else if (level.find("INFO") != std::string::npos) {
427 body.level = LOGLEVEL_INFO;
428 } else if (level.find("WARNING") != std::string::npos) {
429 body.level = LOGLEVEL_WARNING;
430 } else if (level.find("ERROR") != std::string::npos) {
431 body.level = LOGLEVEL_ERROR;
432 } else if (level.find("FATAL") != std::string::npos) {
433 body.level = LOGLEVEL_FATAL;
434 }
435 body.text = s.substr(end+1);
436 }
437 else
438 {
440 }
441 }
442
443 if (body.level == LOGLEVEL_UNDEFINED && listen_to_LOGLEVEL_UNDEFINED == false) {continue;}
444 if (body.level == LOGLEVEL_TRACE && listen_to_LOGLEVEL_TRACE == false) {continue;}
445 if (body.level == LOGLEVEL_DEBUG && listen_to_LOGLEVEL_DEBUG == false) {continue;}
446 if (body.level == LOGLEVEL_INFO && listen_to_LOGLEVEL_INFO == false) {continue;}
447 if (body.level == LOGLEVEL_WARNING && listen_to_LOGLEVEL_WARNING == false) {continue;}
448 if (body.level == LOGLEVEL_ERROR && listen_to_LOGLEVEL_ERROR == false) {continue;}
449 if (body.level == LOGLEVEL_FATAL && listen_to_LOGLEVEL_FATAL == false) {continue;}
450
451 LogEntry entry (this->logs_max_lines_enabled, this->logs_max_lines);
452 entry.logInfo.port_complete = header;
453 entry.logInfo.port_complete.erase(0,1);
454 entry.logInfo.port_complete.erase(entry.logInfo.port_complete.size()-1);
455 std::istringstream iss(header);
456 std::string token;
457 getline(iss, token, '/');
458 getline(iss, token, '/'); entry.logInfo.port_system = token;
459 getline(iss, token, '/'); entry.logInfo.port_prefix = "/"+ token;
460 getline(iss, token, '/'); entry.logInfo.process_name = token;
461 getline(iss, token, '/'); entry.logInfo.process_pid = token.erase(token.size()-1);
462 if (entry.logInfo.port_system == "log" && listen_to_YARP_MESSAGES == false) {
463 continue;
464 }
465 if (entry.logInfo.port_system == "yarprunlog" && listen_to_YARPRUN_MESSAGES == false) {
466 continue;
467 }
468
469 //-------- enter the critical section.
470 // the following variables must be protected: log_list
471 this->mutex.lock();
472 std::list<LogEntry>::iterator it;
473 for (it = log_list.begin(); it != log_list.end(); it++)
474 {
475 if (it->logInfo.port_complete==entry.logInfo.port_complete)
476 {
477 if (it->logging_enabled)
478 {
479 it->logInfo.setNewError(body.level);
480 it->logInfo.last_update=machine_current_time;
481 it->append_logEntry(body);
482 }
483 else
484 {
485 //just skipping this message
486 }
487 break;
488 }
489 }
490 if (it == log_list.end())
491 {
492 if (log_list.size() < log_list_max_size || log_list_max_size_enabled==false )
493 {
494 yarp::os::Contact contact = yarp::os::Network::queryName(entry.logInfo.port_complete);
495 if (contact.isValid())
496 {
497 entry.logInfo.setNewError(body.level);
498 entry.logInfo.ip_address = contact.getHost();
499 }
500 else
501 {
502 printf("ERROR: invalid contact: %s\n", entry.logInfo.port_complete.c_str());
503 };
504 entry.append_logEntry(body);
505 entry.logInfo.last_update=machine_current_time;
506 log_list.push_back(entry);
507 }
508 //else
509 //{
510 // printf("WARNING: exceeded log_list_max_size=%d\n",log_list_max_size);
511 //}
512 }
513 this->mutex.unlock();
514 //-------- end of the critical section.
515 }
516 }
517
518}
519
520//public methods
522{
523 if (logging == true)
524 {
525 fprintf(stderr,"logger is already running, listening on port %s\n", log_updater->getPortName().c_str());
526 return true;
527 }
528
529 if (yarp::os::Network::exists(log_updater->getPortName()))
530 {
531 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());
532 return false;
533 }
534
535 if (log_updater->logger_port.open(log_updater->getPortName()))
536 {
537 fprintf(stdout,"Logger successfully started, listening on port %s\n", log_updater->getPortName().c_str());
538 }
539 else
540 {
541 fprintf(stderr,"Unable to start logger: port %s is unavailable\n", log_updater->getPortName().c_str());
542 return false;
543 }
544 log_updater->logger_port.resume();
545 log_updater->logger_port.setStrict();
546 logging=true;
547 log_updater->start();
548 return true;
549}
550
551void LoggerEngine::logger_thread::threadRelease()
552{
553 logger_port.interrupt();
554 logger_port.close();
555}
556
558{
559 if (log_updater == nullptr) {
560 fprintf(stdout, "Logger stop internal error");
561 return false;
562 }
563
564 logging=false;
565 if (log_updater->isRunning() == true) {
566 log_updater->stop();
567 }
568
569 fprintf(stdout, "Logger successfully stopped");
570 return true;
571}
572
574{
575 if (log_updater == nullptr) {
576 fprintf(stdout, "Logger start_discoverry internal error");
577 return;
578 }
579
580 fprintf(stdout, "Logger discovery started");
581 log_updater->start();
582 discovering=true;
583}
584
586{
587 fprintf(stdout, "Logger discovery stopped");
588 discovering=false;
589}
590
591LoggerEngine::LoggerEngine(std::string portName)
592{
593 log_updater=new logger_thread (portName, 0.01);
594 logging = false;
595 discovering = false;
596}
597
599{
600 this->stop_logging();
601 if (log_updater!=nullptr)
602 {
603 delete log_updater;
604 log_updater = nullptr;
605 }
606}
607
609{
610 if (log_updater == nullptr) {
611 return 0;
612 }
613
614 return log_updater->logger_port.getInputCount();
615}
616
617void LoggerEngine::get_infos (std::list<LogEntryInfo>& infos)
618{
619 if (log_updater == nullptr) {
620 return;
621 }
622
623 log_updater->mutex.lock();
624 std::list<LogEntry>::iterator it;
625 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
626 {
627 infos.push_back(it->logInfo);
628 }
629 log_updater->mutex.unlock();
630}
631
632void LoggerEngine::get_messages (std::list<MessageEntry>& messages)
633{
634 if (log_updater == nullptr) {
635 return;
636 }
637
638 log_updater->mutex.lock();
639 std::list<LogEntry>::iterator it;
640 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
641 {
642 messages.insert(messages.end(), it->entry_list.begin(), it->entry_list.end());
643 }
644 log_updater->mutex.unlock();
645}
646
647void LoggerEngine::get_messages_by_port_prefix (std::string port, std::list<MessageEntry>& messages, bool from_beginning)
648{
649 if (log_updater == nullptr) {
650 return;
651 }
652
653 log_updater->mutex.lock();
654 std::list<LogEntry>::iterator it;
655 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
656 {
657 if (it->logInfo.port_prefix == port)
658 {
659 //messages = (it->entry_list);
660 if (it->last_read_message==-1)
661 {
662 from_beginning=true;
663 }
664 if (from_beginning==true)
665 {
666 it->last_read_message = 0;
667 }
668 int i=it->last_read_message;
669 for (; i<(int)it->entry_list.size(); i++)
670 {
671 messages.push_back(it->entry_list[i]);
672 }
673 it->last_read_message=i;
674 break;
675 }
676 }
677 log_updater->mutex.unlock();
678}
679
681{
682 if (log_updater == nullptr) {
683 return;
684 }
685
686 log_updater->mutex.lock();
687 std::list<LogEntry>::iterator it;
688 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
689 {
690 if (it->logInfo.port_complete == port)
691 {
692 it->clear_logEntries();
693 break;
694 }
695 }
696 log_updater->mutex.unlock();
697}
698
699void LoggerEngine::get_messages_by_port_complete (std::string port, std::list<MessageEntry>& messages, bool from_beginning)
700{
701 if (log_updater == nullptr) {
702 return;
703 }
704
705 log_updater->mutex.lock();
706 std::list<LogEntry>::iterator it;
707 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
708 {
709 if (it->logInfo.port_complete == port)
710 {
711 //messages = (it->entry_list);
712 if (it->last_read_message==-1)
713 {
714 from_beginning=true;
715 }
716 if (from_beginning==true)
717 {
718 it->last_read_message = 0;
719 }
720 int i=it->last_read_message;
721 int size = (int)it->entry_list.size();
722 for (; i<size; i++)
723 {
724 messages.push_back(it->entry_list[i]);
725 }
726 it->last_read_message=i;
727 break;
728 }
729 }
730 log_updater->mutex.unlock();
731}
732
733void LoggerEngine::get_messages_by_process (std::string process, std::list<MessageEntry>& messages, bool from_beginning)
734{
735 if (log_updater == nullptr) {
736 return;
737 }
738
739 log_updater->mutex.lock();
740 std::list<LogEntry>::iterator it;
741 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
742 {
743 if (it->logInfo.process_name == process)
744 {
745 //messages = (it->entry_list);
746 if (it->last_read_message==-1)
747 {
748 from_beginning=true;
749 }
750 if (from_beginning==true)
751 {
752 it->last_read_message = 0;
753 }
754 int i=it->last_read_message;
755 for (; i<(int)it->entry_list.size(); i++)
756 {
757 messages.push_back(it->entry_list[i]);
758 }
759 it->last_read_message=i;
760 break;
761 }
762 }
763 log_updater->mutex.unlock();
764}
765
766void LoggerEngine::get_messages_by_pid (std::string pid, std::list<MessageEntry>& messages, bool from_beginning)
767{
768 if (log_updater == nullptr) {
769 return;
770 }
771
772 log_updater->mutex.lock();
773 std::list<LogEntry>::iterator it;
774 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
775 {
776 if (it->logInfo.process_pid == pid)
777 {
778 //messages = (it->entry_list);
779 if (it->last_read_message==-1)
780 {
781 from_beginning=true;
782 }
783 if (from_beginning==true)
784 {
785 it->last_read_message = 0;
786 }
787 int i=it->last_read_message;
788 for (; i<(int)it->entry_list.size(); i++)
789 {
790 messages.push_back(it->entry_list[i]);
791 }
792 it->last_read_message=i;
793 break;
794 }
795 }
796 log_updater->mutex.unlock();
797}
798
799const std::list<MessageEntry> filter_by_level (int level, const std::list<MessageEntry>& messages)
800{
801 std::list<MessageEntry> ret;
802 std::list<MessageEntry>::const_iterator it;
803 for (it = messages.begin(); it != messages.end(); it++)
804 {
805 LogLevel llevel = it->level;
806 if (llevel.toInt() == level) {
807 ret.push_back(*it);
808 }
809 }
810 return ret;
811}
812
814{
815 if (log_updater == nullptr) {
816 return;
817 }
818 log_updater->mutex.lock();
819 if (logLevel == LOGLEVEL_UNDEFINED) {log_updater->listen_to_LOGLEVEL_UNDEFINED=enable;}
820 else if (logLevel == LOGLEVEL_TRACE) {log_updater->listen_to_LOGLEVEL_TRACE=enable;}
821 else if (logLevel == LOGLEVEL_INFO) {log_updater->listen_to_LOGLEVEL_INFO=enable;}
822 else if (logLevel == LOGLEVEL_DEBUG) {log_updater->listen_to_LOGLEVEL_DEBUG=enable;}
823 else if (logLevel == LOGLEVEL_WARNING) {log_updater->listen_to_LOGLEVEL_WARNING=enable;}
824 else if (logLevel == LOGLEVEL_ERROR) {log_updater->listen_to_LOGLEVEL_ERROR=enable;}
825 else if (logLevel == LOGLEVEL_FATAL) {log_updater->listen_to_LOGLEVEL_FATAL=enable;}
826 log_updater->mutex.unlock();
827}
828
830{
831 if (log_updater == nullptr) {
832 return false;
833 }
834 if (logLevel == LOGLEVEL_UNDEFINED) {return log_updater->listen_to_LOGLEVEL_UNDEFINED;}
835 if (logLevel == LOGLEVEL_TRACE) {return log_updater->listen_to_LOGLEVEL_TRACE;}
836 if (logLevel == LOGLEVEL_DEBUG) {return log_updater->listen_to_LOGLEVEL_DEBUG;}
837 if (logLevel == LOGLEVEL_INFO) {return log_updater->listen_to_LOGLEVEL_INFO;}
838 if (logLevel == LOGLEVEL_WARNING) {return log_updater->listen_to_LOGLEVEL_WARNING;}
839 if (logLevel == LOGLEVEL_ERROR) {return log_updater->listen_to_LOGLEVEL_ERROR;}
840 if (logLevel == LOGLEVEL_FATAL) {return log_updater->listen_to_LOGLEVEL_FATAL;}
841 return false;
842}
843
844void LoggerEngine::set_listen_option (std::string option, bool enable)
845{
846 if (log_updater == nullptr) {
847 return;
848 }
849 log_updater->mutex.lock();
850 log_updater->mutex.unlock();
851}
852
854{
855 return false;
856}
857
859{
860 if (log_updater == nullptr) {
861 return;
862 }
863 log_updater->mutex.lock();
864 if (logSystem == LOGSYSTEM_YARP) {log_updater->listen_to_YARP_MESSAGES=enable;}
865 else if (logSystem == LOGSYSTEM_YARPRUN) {log_updater->listen_to_YARPRUN_MESSAGES=enable;}
866 log_updater->mutex.unlock();
867}
868
870{
871 if (log_updater == nullptr) {
872 return false;
873 }
874 if (logSystem == LOGSYSTEM_YARP) {return log_updater->listen_to_YARP_MESSAGES;}
875 if (logSystem == LOGSYSTEM_YARPRUN) {return log_updater->listen_to_YARPRUN_MESSAGES;}
876 return false;
877}
878
880{
881 if (log_updater == nullptr) {
882 return;
883 }
884
885 log_updater->mutex.lock();
886 log_updater->logs_max_lines_enabled = enabled;
887 log_updater->logs_max_lines = new_size;
888
889 std::list<LogEntry>::iterator it;
890 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
891 {
892 it->setLogEntryMaxSize(new_size);
893 it->setLogEntryMaxSizeEnabled(enabled);
894 }
895
896 log_updater->mutex.unlock();
897}
898
899
901{
902 if (log_updater == nullptr) {
903 return;
904 }
905 log_updater->mutex.lock();
906 log_updater->log_list_max_size_enabled = enabled;
907 log_updater->log_list_max_size = new_size;
908 log_updater->mutex.unlock();
909}
910
912{
913 if (log_updater == nullptr) {
914 return;
915 }
916
917 log_updater->mutex.lock();
918 enabled = log_updater->logs_max_lines_enabled;
919 current_size = log_updater->logs_max_lines;
920 log_updater->mutex.unlock();
921}
922
924{
925 if (log_updater == nullptr) {
926 return;
927 }
928 log_updater->mutex.lock();
929 enabled=log_updater->log_list_max_size_enabled;
930 current_size=log_updater->log_list_max_size;
931 log_updater->mutex.unlock();
932}
933
935{
936 if (log_updater == nullptr) {
937 return false;
938 }
939 log_updater->mutex.lock();
940 log_updater->log_list.clear();
941 log_updater->mutex.unlock();
942 return true;
943}
944
945void LoggerEngine::set_log_enable_by_port_complete (std::string port, bool enable)
946{
947 if (log_updater == nullptr) {
948 return;
949 }
950
951 log_updater->mutex.lock();
952 std::list<LogEntry>::iterator it;
953 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
954 {
955 if (it->logInfo.port_complete == port)
956 {
957 it->logging_enabled=enable;
958 break;
959 }
960 }
961 log_updater->mutex.unlock();
962}
963
965{
966 if (log_updater == nullptr) {
967 return false;
968 }
969
970 bool enabled=false;
971 log_updater->mutex.lock();
972 std::list<LogEntry>::iterator it;
973 for (it = log_updater->log_list.begin(); it != log_updater->log_list.end(); it++)
974 {
975 if (it->logInfo.port_complete == port)
976 {
977 enabled=it->logging_enabled;
978 break;
979 }
980 }
981 log_updater->mutex.unlock();
982 return enabled;
983}
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:64
size_type size() const
Gets the number of elements in the bottle.
Definition Bottle.cpp:251
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Definition Bottle.cpp:240
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:246
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Definition Bottle.cpp:170
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition Bottle.cpp:211
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:240
virtual std::string asString() const
Get string value.
Definition Value.cpp:234
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