当前位置: 首页>>代码示例>>C++>>正文


C++ LogEntry::append_logEntry方法代码示例

本文整理汇总了C++中LogEntry::append_logEntry方法的典型用法代码示例。如果您正苦于以下问题:C++ LogEntry::append_logEntry方法的具体用法?C++ LogEntry::append_logEntry怎么用?C++ LogEntry::append_logEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LogEntry的用法示例。


在下文中一共展示了LogEntry::append_logEntry方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if


//.........这里部分代码省略.........
            char ttstr [20];
            static int count=0;
            sprintf(ttstr,"%d",count++);
            body.yarprun_timestamp = string(ttstr);
            body.local_timestamp   = machine_current_time_s;
            body.level = LOGLEVEL_UNDEFINED;

            size_t str = s.find('[',0);
            size_t end = s.find(']',0);
            if (str==std::string::npos || end==std::string::npos )
            {
                body.level = LOGLEVEL_UNDEFINED;
            }
            else if (str==0)
            {
                std::string level = s.substr(str,end+1);
                body.level = LOGLEVEL_UNDEFINED;
                if      (level.find("TRACE")!=std::string::npos)   body.level = LOGLEVEL_TRACE;
                else if (level.find("DEBUG")!=std::string::npos)   body.level = LOGLEVEL_DEBUG;
                else if (level.find("INFO")!=std::string::npos)    body.level = LOGLEVEL_INFO;
                else if (level.find("WARNING")!=std::string::npos) body.level = LOGLEVEL_WARNING;
                else if (level.find("ERROR")!=std::string::npos)   body.level = LOGLEVEL_ERROR;
                else if (level.find("FATAL")!=std::string::npos)   body.level = LOGLEVEL_FATAL;
                body.text = s.substr(end+1);
            }
            else
            {
                body.level = LOGLEVEL_UNDEFINED;
            }

            if (body.level == LOGLEVEL_UNDEFINED && listen_to_LOGLEVEL_UNDEFINED == false) {continue;}
            if (body.level == LOGLEVEL_TRACE     && listen_to_LOGLEVEL_TRACE     == false) {continue;}
            if (body.level == LOGLEVEL_DEBUG     && listen_to_LOGLEVEL_DEBUG     == false) {continue;}
            if (body.level == LOGLEVEL_INFO      && listen_to_LOGLEVEL_INFO      == false) {continue;}
            if (body.level == LOGLEVEL_WARNING   && listen_to_LOGLEVEL_WARNING   == false) {continue;}
            if (body.level == LOGLEVEL_ERROR     && listen_to_LOGLEVEL_ERROR     == false) {continue;}
            if (body.level == LOGLEVEL_FATAL     && listen_to_LOGLEVEL_FATAL     == false) {continue;}

            this->mutex.lock();
            LogEntry entry;
            entry.logInfo.port_complete = header;
            entry.logInfo.port_complete.erase(0,1);
            entry.logInfo.port_complete.erase(entry.logInfo.port_complete.size()-1);
            std::istringstream iss(header);
            std::string token;
            getline(iss, token, '/');
            getline(iss, token, '/'); entry.logInfo.port_system  = token;
            getline(iss, token, '/'); entry.logInfo.port_prefix  = "/"+ token;
            getline(iss, token, '/'); entry.logInfo.process_name = token;
            getline(iss, token, '/'); entry.logInfo.process_pid  = token.erase(token.size()-1);
            if (entry.logInfo.port_system == "log" && listen_to_YARP_MESSAGES==false)    continue;
            if (entry.logInfo.port_system == "yarprunlog" && listen_to_YARPRUN_MESSAGES==false) continue;

            std::list<LogEntry>::iterator it;
            for (it = log_list.begin(); it != log_list.end(); it++)
            {
                if (it->logInfo.port_complete==entry.logInfo.port_complete)
                {
                    if (it->logging_enabled)
                    {
                        it->logInfo.setNewError(body.level);
                        it->logInfo.last_update=machine_current_time;
                        it->append_logEntry(body);
                    }
                    else
                    {
                        //just skipping this message
                    }
                    break;
                }
            }
            if (it == log_list.end())
            {
                if (log_list.size() < log_list_max_size || log_list_max_size_enabled==false )
                {
                    yarp::os::Contact contact = yarp::os::Network::queryName(entry.logInfo.port_complete);
                    if (contact.isValid())
                    {
                        entry.logInfo.setNewError(body.level);
                        entry.logInfo.ip_address = contact.getHost();
                    }
                    else
                    {
                        printf("ERROR: invalid contact: %s\n", entry.logInfo.port_complete.c_str());
                    };
                    entry.append_logEntry(body);
                    entry.logInfo.last_update=machine_current_time;
                    log_list.push_back(entry);
                }
                //else
                //{
                //    printf("WARNING: exceeded log_list_max_size=%d\n",log_list_max_size);
                //}
            }

            this->mutex.unlock();
        }
    }

}
开发者ID:claudiofantacci,项目名称:yarp,代码行数:101,代码来源:YarpLogger.cpp


注:本文中的LogEntry::append_logEntry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。