static void CheckEnvironmentVariables()

in simulation/src/core/model/log.cc [528:619]


static void CheckEnvironmentVariables (void)
{
  const char *envVar = std::getenv ("NS_LOG");
  if (envVar == 0 || std::strlen (envVar) == 0)
    {
      return;
    }

  std::string env = envVar;
  std::string::size_type cur = 0;
  std::string::size_type next = 0;

  while (next != std::string::npos)
    {
      next = env.find_first_of (":", cur);
      std::string tmp = std::string (env, cur, next - cur);
      std::string::size_type equal = tmp.find ("=");
      std::string component;
      if (equal == std::string::npos)
        {
          // ie no '=' characters found
          component = tmp;
          if (ComponentExists (component) || component == "*" || component == "***")
            {
              return;
            }
          else
            {
              LogComponentPrintList ();
              NS_FATAL_ERROR ("Invalid or unregistered component name \"" << component <<
                              "\" in env variable NS_LOG, see above for a list of valid components");
            }
        }
      else
        {
          component = tmp.substr (0, equal);
          if (ComponentExists (component) || component == "*")
            {
              std::string::size_type cur_lev;
              std::string::size_type next_lev = equal;
              do
                {
                  cur_lev = next_lev + 1;
                  next_lev = tmp.find ("|", cur_lev);
                  std::string lev = tmp.substr (cur_lev, next_lev - cur_lev);
                  if (lev == "error"
                      || lev == "warn"
                      || lev == "debug"
                      || lev == "info"
                      || lev == "function"
                      || lev == "logic"
                      || lev == "all"
                      || lev == "prefix_func"
                      || lev == "func"
                      || lev == "prefix_time"
                      || lev == "time"
                      || lev == "prefix_node"
                      || lev == "node"
                      || lev == "prefix_level"
                      || lev == "level"
                      || lev == "prefix_all"
                      || lev == "level_error"
                      || lev == "level_warn"
                      || lev == "level_debug"
                      || lev == "level_info"
                      || lev == "level_function"
                      || lev == "level_logic"
                      || lev == "level_all"
                      || lev == "*"
                      || lev == "**"
                      )
                    {
                      continue;
                    }
                  else
                    {
                      NS_FATAL_ERROR ("Invalid log level \"" << lev <<
                                      "\" in env variable NS_LOG for component name " << component);
                    }
                }
              while (next_lev != std::string::npos);
            }
          else
            {
              LogComponentPrintList ();
              NS_FATAL_ERROR ("Invalid or unregistered component name \"" << component <<
                              "\" in env variable NS_LOG, see above for a list of valid components");
            }
        }
      cur = next + 1;   // parse next component
    }
}