src/core/log.cc
author Florian Westphal <fw@strlen.de>
Wed, 03 Sep 2008 23:24:59 +0200
changeset 3595 693faf7f4e9b
parent 3483 7ce1353e63ba
child 5522 0d1a06c5b285
permissions -rw-r--r--
nsc: Fix build problem if gtk config store is disabled gtk config store pulled in libdl.so for us, so things fail to link of the config store isn't enabled. This makes nsc pull in libdl itself when its enabled.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * Copyright (c) 2006,2007 INRIA
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 *
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 *
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * GNU General Public License for more details.
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 *
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
 *
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    19
 */
3483
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
    20
#include "log.h"
1506
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1503
diff changeset
    21
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1503
diff changeset
    22
#ifdef NS3_LOG_ENABLE
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1503
diff changeset
    23
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
#include <list>
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
#include <utility>
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
#include <iostream>
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
#include "assert.h"
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
#include "ns3/core-config.h"
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
#include "fatal-error.h"
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
#ifdef HAVE_STDLIB_H
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
#include <stdlib.h>
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
#endif
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
namespace ns3 {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
    37
LogTimePrinter g_logTimePrinter = 0;
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
    38
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
typedef std::list<std::pair <std::string, LogComponent *> > ComponentList;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
typedef std::list<std::pair <std::string, LogComponent *> >::iterator ComponentListI;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
1861
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    42
static class PrintList
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    43
{
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    44
public:
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    45
  PrintList ();
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    46
} g_printList;
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    47
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
static 
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
ComponentList *GetComponentList (void)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
{
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
  static ComponentList components;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
  return &components;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
1861
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    55
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    56
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    57
PrintList::PrintList ()
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    58
{
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    59
#ifdef HAVE_GETENV
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    60
  char *envVar = getenv("NS_LOG");
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    61
  if (envVar == 0)
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    62
    {
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    63
      return;
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    64
    }
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    65
  std::string env = envVar;
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    66
  std::string::size_type cur = 0;
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    67
  std::string::size_type next = 0;
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    68
  while (next != std::string::npos)
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    69
    {
2982
a7e3e54c7e94 change NS_LOG= syntax and default behavior to be more useful by default.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
    70
      next = env.find_first_of (":", cur);
1861
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    71
      std::string tmp = std::string (env, cur, next-cur);
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    72
      if (tmp == "print-list")
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    73
        {
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    74
          LogComponentPrintList ();
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    75
          exit (0);
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    76
          break;
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    77
        }
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    78
      cur = next + 1;
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    79
    }
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    80
#endif  
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    81
}
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    82
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    83
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    84
LogComponent::LogComponent (char const * name)
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    85
  : m_levels (0), m_name (name)
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
{
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    87
  EnvVarCheck (name);
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    88
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    89
  ComponentList *components = GetComponentList ();
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    90
  for (ComponentListI i = components->begin ();
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    91
       i != components->end ();
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    92
       i++)
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
    {
2809
30e451c21f60 improve warning output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1862
diff changeset
    94
      if (i->first == name)
30e451c21f60 improve warning output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1862
diff changeset
    95
        {
30e451c21f60 improve warning output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1862
diff changeset
    96
          NS_FATAL_ERROR ("Log component \""<<name<<"\" has already been registered once.");
30e451c21f60 improve warning output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1862
diff changeset
    97
        }
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    98
    }
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    99
  components->push_back (std::make_pair (name, this));
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   100
}
1775
5abf6f0d1eca deal with static constructor problem
Craig Dowell <craigdo@ee.washington.edu>
parents: 1773
diff changeset
   101
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   102
void
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   103
LogComponent::EnvVarCheck (char const * name)
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   104
{
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
#ifdef HAVE_GETENV
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
  char *envVar = getenv("NS_LOG");
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
  if (envVar == 0)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
    {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
      return;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
    }
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
  std::string env = envVar;
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   112
  std::string myName = name;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   113
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   114
  std::string::size_type cur = 0;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
  std::string::size_type next = 0;
1862
3627401f90cf simplify the parsing logic and remove buggy comment and code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1861
diff changeset
   116
  while (next != std::string::npos)
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   117
    {
2982
a7e3e54c7e94 change NS_LOG= syntax and default behavior to be more useful by default.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   118
      next = env.find_first_of (":", cur);
1862
3627401f90cf simplify the parsing logic and remove buggy comment and code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1861
diff changeset
   119
      std::string tmp = std::string (env, cur, next-cur);
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   120
      std::string::size_type equal = tmp.find ("=");
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   121
      std::string component;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
      if (equal == std::string::npos)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
        {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   124
          component = tmp;
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   125
          if (component == myName || component == "*")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   126
            {
2982
a7e3e54c7e94 change NS_LOG= syntax and default behavior to be more useful by default.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   127
              int level = LOG_ALL | LOG_PREFIX_TIME | LOG_PREFIX_FUNC;
a7e3e54c7e94 change NS_LOG= syntax and default behavior to be more useful by default.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   128
              Enable ((enum LogLevel)level);
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   129
              return;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   130
            }
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   131
        }
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   132
      else
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   133
        {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   134
          component = tmp.substr (0, equal);
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   135
          if (component == myName || component == "*")
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   136
            {
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   137
              int level = 0;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   138
              std::string::size_type cur_lev;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   139
              std::string::size_type next_lev = equal;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   140
              do
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   141
                {
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   142
                  cur_lev = next_lev + 1;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   143
                  next_lev = tmp.find ("|", cur_lev);
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   144
                  std::string lev = tmp.substr (cur_lev, next_lev - cur_lev);
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   145
                  if (lev == "error")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   146
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   147
                      level |= LOG_ERROR;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   148
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   149
                  else if (lev == "warn")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   150
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   151
                      level |= LOG_WARN;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   152
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   153
                  else if (lev == "debug")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   154
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   155
                      level |= LOG_DEBUG;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   156
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   157
                  else if (lev == "info")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   158
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   159
                      level |= LOG_INFO;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   160
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   161
                  else if (lev == "function")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   162
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   163
                      level |= LOG_FUNCTION;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   164
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   165
                  else if (lev == "logic")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   166
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   167
                      level |= LOG_LOGIC;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   168
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   169
                  else if (lev == "all")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   170
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   171
                      level |= LOG_ALL;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   172
                    }
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   173
                  else if (lev == "prefix_func")
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   174
                    {
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   175
                      level |= LOG_PREFIX_FUNC;
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   176
                    }
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   177
                  else if (lev == "prefix_time")
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   178
                    {
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   179
                      level |= LOG_PREFIX_TIME;
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   180
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   181
                  else if (lev == "level_error")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   182
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   183
                      level |= LOG_LEVEL_ERROR;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   184
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   185
                  else if (lev == "level_warn")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   186
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   187
                      level |= LOG_LEVEL_WARN;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   188
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   189
                  else if (lev == "level_debug")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   190
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   191
                      level |= LOG_LEVEL_DEBUG;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   192
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   193
                  else if (lev == "level_info")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   194
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   195
                      level |= LOG_LEVEL_INFO;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   196
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   197
                  else if (lev == "level_function")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   198
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   199
                      level |= LOG_LEVEL_FUNCTION;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   200
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   201
                  else if (lev == "level_logic")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   202
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   203
                      level |= LOG_LEVEL_LOGIC;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   204
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   205
                  else if (lev == "level_all")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   206
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   207
                      level |= LOG_LEVEL_ALL;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   208
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   209
                } while (next_lev != std::string::npos);
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   210
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   211
              Enable ((enum LogLevel)level);
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   212
            }
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   213
        }
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   214
      cur = next + 1;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   215
    }
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   216
#endif
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   217
}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   218
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   219
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   220
bool 
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   221
LogComponent::IsEnabled (enum LogLevel level) const
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   222
{
1775
5abf6f0d1eca deal with static constructor problem
Craig Dowell <craigdo@ee.washington.edu>
parents: 1773
diff changeset
   223
  //  LogComponentEnableEnvVar ();
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   224
  return (level & m_levels) ? 1 : 0;
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   225
}
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   226
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   227
bool
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   228
LogComponent::IsNoneEnabled (void) const
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   229
{
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   230
  return m_levels == 0;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   231
}
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   232
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   233
void 
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   234
LogComponent::Enable (enum LogLevel level)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   235
{
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   236
  m_levels |= level;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   237
}
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   238
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   239
void 
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   240
LogComponent::Disable (enum LogLevel level)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   241
{
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   242
  m_levels &= ~level;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   243
}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   244
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   245
char const *
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   246
LogComponent::Name (void) const
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   247
{
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   248
  return m_name;
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   249
}
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   250
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   251
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   252
void 
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   253
LogComponentEnable (char const *name, enum LogLevel level)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   254
{
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   255
  ComponentList *components = GetComponentList ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   256
  for (ComponentListI i = components->begin ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   257
       i != components->end ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   258
       i++)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   259
    {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   260
      if (i->first.compare (name) == 0) 
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   261
	{
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   262
	  i->second->Enable (level);
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   263
	  break;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   264
	}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   265
    }  
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   266
}
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   267
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   268
void 
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   269
LogComponentEnableAll (enum LogLevel level)
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   270
{
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   271
  ComponentList *components = GetComponentList ();
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   272
  for (ComponentListI i = components->begin ();
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   273
       i != components->end ();
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   274
       i++)
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   275
    {
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   276
      i->second->Enable (level);
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   277
    }  
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   278
}
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   279
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   280
void 
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   281
LogComponentDisable (char const *name, enum LogLevel level)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   282
{
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   283
  ComponentList *components = GetComponentList ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   284
  for (ComponentListI i = components->begin ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   285
       i != components->end ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   286
       i++)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   287
    {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   288
      if (i->first.compare (name) == 0) 
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   289
	{
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   290
	  i->second->Disable (level);
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   291
	  break;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   292
	}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   293
    }  
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   294
}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   295
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   296
void 
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   297
LogComponentDisableAll (enum LogLevel level)
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   298
{
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   299
  ComponentList *components = GetComponentList ();
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   300
  for (ComponentListI i = components->begin ();
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   301
       i != components->end ();
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   302
       i++)
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   303
    {
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   304
      i->second->Disable (level);
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   305
    }  
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   306
}
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   307
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   308
void 
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   309
LogComponentPrintList (void)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   310
{
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   311
  ComponentList *components = GetComponentList ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   312
  for (ComponentListI i = components->begin ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   313
       i != components->end ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   314
       i++)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   315
    {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   316
      std::cout << i->first << "=";
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   317
      if (i->second->IsNoneEnabled ())
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   318
        {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   319
          std::cout << "0" << std::endl;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   320
          continue;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   321
        }
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   322
      if (i->second->IsEnabled (LOG_ERROR))
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   323
        {
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   324
          std::cout << "error";
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   325
        }
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   326
      if (i->second->IsEnabled (LOG_WARN))
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   327
        {
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   328
          std::cout << "|warn";
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   329
        }
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   330
      if (i->second->IsEnabled (LOG_DEBUG))
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   331
        {
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   332
          std::cout << "|debug";
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   333
        }
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   334
      if (i->second->IsEnabled (LOG_INFO))
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   335
        {
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   336
          std::cout << "|info";
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   337
        }
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   338
      if (i->second->IsEnabled (LOG_FUNCTION))
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   339
        {
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   340
          std::cout << "|function";
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   341
        }
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   342
      if (i->second->IsEnabled (LOG_LOGIC))
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   343
        {
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   344
          std::cout << "|logic";
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   345
        }
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   346
      if (i->second->IsEnabled (LOG_ALL))
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   347
        {
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   348
          std::cout << "|all";
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   349
        }
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   350
      std::cout << std::endl;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   351
    }
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   352
}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   353
3005
cc521f35f033 avoid segfault when setting NS_LOG=*
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2983
diff changeset
   354
void LogSetTimePrinter (LogTimePrinter printer)
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   355
{
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   356
  g_logTimePrinter = printer;
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   357
}
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   358
LogTimePrinter LogGetTimePrinter(void)
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   359
{
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   360
  return g_logTimePrinter;
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   361
}
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   362
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   363
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   364
ParameterLogger::ParameterLogger (std::ostream &os)
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   365
  : m_itemNumber (0),
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   366
    m_os (os)
2976
ee338f8cef49 do not use __PRETTY_PRINT__
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2809
diff changeset
   367
{}
1828
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1783
diff changeset
   368
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   369
} // namespace ns3
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   370
3483
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   371
#else // NS3_LOG_ENABLE
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   372
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   373
namespace ns3 {
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   374
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   375
void 
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   376
LogComponentEnable (char const *name, enum LogLevel level)
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   377
{
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   378
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   379
}
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   380
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   381
void 
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   382
LogComponentEnableAll (enum LogLevel level)
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   383
{
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   384
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   385
}
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   386
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   387
void 
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   388
LogComponentDisable (char const *name, enum LogLevel level)
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   389
{
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   390
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   391
}
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   392
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   393
void 
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   394
LogComponentDisableAll (enum LogLevel level)
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   395
{
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   396
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   397
}
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   398
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   399
} // namespace ns3
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   400
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3005
diff changeset
   401
#endif