src/core/log.cc
author Guillaume Seguin <guillaume@segu.in>
Sat, 14 Nov 2009 17:47:05 +0100
changeset 5522 0d1a06c5b285
parent 3483 7ce1353e63ba
permissions -rw-r--r--
Print node context in log messages
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;
5522
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
    38
LogNodePrinter g_logNodePrinter = 0;
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
    39
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
typedef std::list<std::pair <std::string, LogComponent *> > ComponentList;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
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
    42
1861
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    43
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
    44
{
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    45
public:
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    46
  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
} 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
    48
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
static 
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
ComponentList *GetComponentList (void)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
{
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
  static ComponentList components;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
  return &components;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
1861
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
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    58
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
    59
{
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    60
#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
    61
  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
    62
  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
    63
    {
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    64
      return;
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    65
    }
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 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
    67
  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
    68
  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
    69
  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
    70
    {
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
    71
      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
    72
      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
    73
      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
    74
        {
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    75
          LogComponentPrintList ();
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    76
          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
    77
          break;
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    78
        }
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    79
      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
    80
    }
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    81
#endif  
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
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    84
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    85
LogComponent::LogComponent (char const * name)
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    86
  : m_levels (0), m_name (name)
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    87
{
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    88
  EnvVarCheck (name);
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    89
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    90
  ComponentList *components = GetComponentList ();
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    91
  for (ComponentListI i = components->begin ();
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    92
       i != components->end ();
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    93
       i++)
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
    {
2809
30e451c21f60 improve warning output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1862
diff changeset
    95
      if (i->first == name)
30e451c21f60 improve warning output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1862
diff changeset
    96
        {
30e451c21f60 improve warning output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1862
diff changeset
    97
          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
    98
        }
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    99
    }
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   100
  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
   101
}
1775
5abf6f0d1eca deal with static constructor problem
Craig Dowell <craigdo@ee.washington.edu>
parents: 1773
diff changeset
   102
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   103
void
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   104
LogComponent::EnvVarCheck (char const * name)
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   105
{
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
#ifdef HAVE_GETENV
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
  char *envVar = getenv("NS_LOG");
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
  if (envVar == 0)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
    {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
      return;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
    }
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
  std::string env = envVar;
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   113
  std::string myName = name;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   114
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
  std::string::size_type cur = 0;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   116
  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
   117
  while (next != std::string::npos)
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
    {
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
   119
      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
   120
      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
   121
      std::string::size_type equal = tmp.find ("=");
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
      std::string component;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
      if (equal == std::string::npos)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   124
        {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   125
          component = tmp;
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   126
          if (component == myName || component == "*")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   127
            {
5522
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   128
              int level = LOG_ALL | LOG_PREFIX_TIME | LOG_PREFIX_FUNC | LOG_PREFIX_NODE;
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
   129
              Enable ((enum LogLevel)level);
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   130
              return;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   131
            }
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   132
        }
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   133
      else
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   134
        {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   135
          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
   136
          if (component == myName || component == "*")
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   137
            {
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   138
              int level = 0;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   139
              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
   140
              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
   141
              do
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   142
                {
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   143
                  cur_lev = next_lev + 1;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   144
                  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
   145
                  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
   146
                  if (lev == "error")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   147
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   148
                      level |= LOG_ERROR;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   149
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   150
                  else if (lev == "warn")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   151
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   152
                      level |= LOG_WARN;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   153
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   154
                  else if (lev == "debug")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   155
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   156
                      level |= LOG_DEBUG;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   157
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   158
                  else if (lev == "info")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   159
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   160
                      level |= LOG_INFO;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   161
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   162
                  else if (lev == "function")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   163
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   164
                      level |= LOG_FUNCTION;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   165
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   166
                  else if (lev == "logic")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   167
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   168
                      level |= LOG_LOGIC;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   169
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   170
                  else if (lev == "all")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   171
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   172
                      level |= LOG_ALL;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   173
                    }
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   174
                  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
   175
                    {
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   176
                      level |= LOG_PREFIX_FUNC;
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   177
                    }
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   178
                  else if (lev == "prefix_time")
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   179
                    {
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   180
                      level |= LOG_PREFIX_TIME;
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   181
                    }
5522
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   182
                  else if (lev == "prefix_node")
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   183
                    {
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   184
                      level |= LOG_PREFIX_NODE;
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   185
                    }
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   186
                  else if (lev == "level_error")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   187
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   188
                      level |= LOG_LEVEL_ERROR;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   189
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   190
                  else if (lev == "level_warn")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   191
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   192
                      level |= LOG_LEVEL_WARN;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   193
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   194
                  else if (lev == "level_debug")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   195
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   196
                      level |= LOG_LEVEL_DEBUG;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   197
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   198
                  else if (lev == "level_info")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   199
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   200
                      level |= LOG_LEVEL_INFO;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   201
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   202
                  else if (lev == "level_function")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   203
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   204
                      level |= LOG_LEVEL_FUNCTION;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   205
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   206
                  else if (lev == "level_logic")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   207
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   208
                      level |= LOG_LEVEL_LOGIC;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   209
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   210
                  else if (lev == "level_all")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   211
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   212
                      level |= LOG_LEVEL_ALL;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   213
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   214
                } 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
   215
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   216
              Enable ((enum LogLevel)level);
1498
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
        }
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   219
      cur = next + 1;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   220
    }
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   221
#endif
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   222
}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   223
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   224
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   225
bool 
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   226
LogComponent::IsEnabled (enum LogLevel level) const
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   227
{
1775
5abf6f0d1eca deal with static constructor problem
Craig Dowell <craigdo@ee.washington.edu>
parents: 1773
diff changeset
   228
  //  LogComponentEnableEnvVar ();
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   229
  return (level & m_levels) ? 1 : 0;
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   230
}
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   231
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   232
bool
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   233
LogComponent::IsNoneEnabled (void) const
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   234
{
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   235
  return m_levels == 0;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   236
}
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   237
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   238
void 
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   239
LogComponent::Enable (enum LogLevel level)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   240
{
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   241
  m_levels |= level;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   242
}
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   243
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   244
void 
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   245
LogComponent::Disable (enum LogLevel level)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   246
{
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   247
  m_levels &= ~level;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   248
}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   249
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   250
char const *
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   251
LogComponent::Name (void) const
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   252
{
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   253
  return m_name;
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   254
}
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   255
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   256
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   257
void 
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   258
LogComponentEnable (char const *name, enum LogLevel level)
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
  ComponentList *components = GetComponentList ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   261
  for (ComponentListI i = components->begin ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   262
       i != components->end ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   263
       i++)
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
      if (i->first.compare (name) == 0) 
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   266
	{
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   267
	  i->second->Enable (level);
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   268
	  break;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   269
	}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   270
    }  
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   271
}
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   272
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   273
void 
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   274
LogComponentEnableAll (enum LogLevel level)
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
  ComponentList *components = GetComponentList ();
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   277
  for (ComponentListI i = components->begin ();
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   278
       i != components->end ();
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   279
       i++)
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   280
    {
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   281
      i->second->Enable (level);
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   282
    }  
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   283
}
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   284
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   285
void 
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   286
LogComponentDisable (char const *name, enum LogLevel level)
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
  ComponentList *components = GetComponentList ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   289
  for (ComponentListI i = components->begin ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   290
       i != components->end ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   291
       i++)
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
      if (i->first.compare (name) == 0) 
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
	  i->second->Disable (level);
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   296
	  break;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   297
	}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   298
    }  
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   299
}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   300
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   301
void 
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   302
LogComponentDisableAll (enum LogLevel level)
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
  ComponentList *components = GetComponentList ();
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   305
  for (ComponentListI i = components->begin ();
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   306
       i != components->end ();
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   307
       i++)
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   308
    {
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   309
      i->second->Disable (level);
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   310
    }  
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   311
}
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   312
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   313
void 
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   314
LogComponentPrintList (void)
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
  ComponentList *components = GetComponentList ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   317
  for (ComponentListI i = components->begin ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   318
       i != components->end ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   319
       i++)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   320
    {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   321
      std::cout << i->first << "=";
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   322
      if (i->second->IsNoneEnabled ())
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   323
        {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   324
          std::cout << "0" << std::endl;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   325
          continue;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   326
        }
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   327
      if (i->second->IsEnabled (LOG_ERROR))
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   328
        {
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   329
          std::cout << "error";
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   330
        }
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   331
      if (i->second->IsEnabled (LOG_WARN))
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   332
        {
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   333
          std::cout << "|warn";
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   334
        }
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   335
      if (i->second->IsEnabled (LOG_DEBUG))
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   336
        {
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   337
          std::cout << "|debug";
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   338
        }
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   339
      if (i->second->IsEnabled (LOG_INFO))
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   340
        {
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   341
          std::cout << "|info";
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   342
        }
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   343
      if (i->second->IsEnabled (LOG_FUNCTION))
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   344
        {
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   345
          std::cout << "|function";
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   346
        }
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   347
      if (i->second->IsEnabled (LOG_LOGIC))
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   348
        {
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   349
          std::cout << "|logic";
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   350
        }
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   351
      if (i->second->IsEnabled (LOG_ALL))
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   352
        {
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   353
          std::cout << "|all";
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   354
        }
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   355
      std::cout << std::endl;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   356
    }
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   357
}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   358
3005
cc521f35f033 avoid segfault when setting NS_LOG=*
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2983
diff changeset
   359
void LogSetTimePrinter (LogTimePrinter printer)
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   360
{
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   361
  g_logTimePrinter = printer;
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
LogTimePrinter LogGetTimePrinter(void)
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   364
{
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   365
  return g_logTimePrinter;
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   366
}
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   367
5522
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   368
void LogSetNodePrinter (LogNodePrinter printer)
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   369
{
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   370
  g_logNodePrinter = printer;
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   371
}
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   372
LogNodePrinter LogGetNodePrinter(void)
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   373
{
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   374
  return g_logNodePrinter;
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   375
}
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   376
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   377
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   378
ParameterLogger::ParameterLogger (std::ostream &os)
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   379
  : m_itemNumber (0),
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   380
    m_os (os)
2976
ee338f8cef49 do not use __PRETTY_PRINT__
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2809
diff changeset
   381
{}
1828
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1783
diff changeset
   382
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   383
} // namespace ns3
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   384
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
   385
#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
   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
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
   388
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
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
   390
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
   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
}
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
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
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
   396
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
   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
}
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
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
   402
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
   403
{
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
   404
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
   405
}
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
   406
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
   407
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
   408
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
   409
{
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
   410
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
   411
}
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
   412
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
   413
} // 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
   414
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
   415
#endif