src/core/model/log.cc
author Peter D. Barnes, Jr. <barnes26@llnl.gov>
Fri, 19 Dec 2014 14:20:27 -0800
changeset 11134 f0150679fa80
parent 10996 4f369a4a89c1
child 11140 35c2c969d0b2
permissions -rw-r--r--
[Doxygen] Logging
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
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
#include <list>
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
#include <utility>
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
#include <iostream>
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
#include "assert.h"
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
#include "ns3/core-config.h"
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
#include "fatal-error.h"
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
7420
ca9c09839724 Add a couple of includes and rescan core module's bindings
Mitch Watrous <watrous@u.washington.edu>
parents: 7419
diff changeset
    29
#ifdef HAVE_GETENV
9131
fab987059055 Change to C++-style includes in log.cc.
Vedran Miletić <rivanvx@gmail.com>
parents: 9119
diff changeset
    30
#include <cstring>
7420
ca9c09839724 Add a couple of includes and rescan core module's bindings
Mitch Watrous <watrous@u.washington.edu>
parents: 7419
diff changeset
    31
#endif
ca9c09839724 Add a couple of includes and rescan core module's bindings
Mitch Watrous <watrous@u.washington.edu>
parents: 7419
diff changeset
    32
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
#ifdef HAVE_STDLIB_H
9131
fab987059055 Change to C++-style includes in log.cc.
Vedran Miletić <rivanvx@gmail.com>
parents: 9119
diff changeset
    34
#include <cstdlib>
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
#endif
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
11134
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    37
/**
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    38
 * \file
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    39
 * \ingroup logging
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    40
 * Debug message logging implementation.
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    41
 */
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    42
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    43
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
namespace ns3 {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
11134
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    46
/**
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    47
 * \ingroup logging
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    48
 * The LogTimePrinter.
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    49
 */
10676
f13ef6e82364 mark private global variables as static in log.cc
Andrey Mazo <ahippo@yandex.com>
parents: 10626
diff changeset
    50
static LogTimePrinter g_logTimePrinter = 0;
11134
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    51
/**
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    52
 * \ingroup logging
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    53
 * The LogNodePrinter.
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    54
 */
10676
f13ef6e82364 mark private global variables as static in log.cc
Andrey Mazo <ahippo@yandex.com>
parents: 10626
diff changeset
    55
static LogNodePrinter g_logNodePrinter = 0;
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
    56
11134
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    57
/**
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    58
 * \ingroup logging
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    59
 * Handler for \c print-list token in NS_LOG
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    60
 * to print the list of log components.
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    61
 */
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    62
class PrintList
1861
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
public:
11134
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    65
  PrintList ();  //<! Constructor, prints the list and exits.
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    66
};
1861
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    67
11134
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    68
/** Invoke handler for \c print-list in NS_LOG environment variable. */
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    69
static PrintList g_printList;
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    70
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    71
  
10996
4f369a4a89c1 Generate doxygen list of all LogComponents
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10676
diff changeset
    72
/* static */
4f369a4a89c1 Generate doxygen list of all LogComponents
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10676
diff changeset
    73
LogComponent::ComponentList *
4f369a4a89c1 Generate doxygen list of all LogComponents
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10676
diff changeset
    74
LogComponent::GetComponentList (void)
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
{
11134
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
    76
  static LogComponent::ComponentList components;
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
  return &components;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    79
1861
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
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
    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
#ifdef HAVE_GETENV
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
    84
  char *envVar = getenv ("NS_LOG");
1861
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    85
  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
    86
    {
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    87
      return;
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    88
    }
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    89
  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
    90
  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
    91
  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
    92
  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
    93
    {
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
    94
      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
    95
      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
    96
      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
    97
        {
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    98
          LogComponentPrintList ();
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
    99
          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
   100
          break;
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
   101
        }
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
   102
      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
   103
    }
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   104
#endif
1861
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
   105
}
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
   106
5bc0b0d8d620 bug 91: add print-list support to NS_LOG env var.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828
diff changeset
   107
10626
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   108
LogComponent::LogComponent (const std::string & name,
10996
4f369a4a89c1 Generate doxygen list of all LogComponents
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10676
diff changeset
   109
                            const std::string & file,
10626
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   110
                            const enum LogLevel mask /* = 0 */)
10996
4f369a4a89c1 Generate doxygen list of all LogComponents
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10676
diff changeset
   111
  : m_levels (0), m_mask (mask), m_name (name), m_file (file)
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
{
10626
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   113
  EnvVarCheck ();
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   114
11134
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   115
  LogComponent::ComponentList *components = GetComponentList ();
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   116
  for (LogComponent::ComponentList::const_iterator i = components->begin ();
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   117
       i != components->end ();
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   118
       i++)
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
    {
2809
30e451c21f60 improve warning output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1862
diff changeset
   120
      if (i->first == name)
30e451c21f60 improve warning output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1862
diff changeset
   121
        {
30e451c21f60 improve warning output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1862
diff changeset
   122
          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
   123
        }
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   124
    }
10230
cb1431abab4a Print log component list alphabetically.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10229
diff changeset
   125
  components->insert (std::make_pair (name, this));
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   126
}
1775
5abf6f0d1eca deal with static constructor problem
Craig Dowell <craigdo@ee.washington.edu>
parents: 1773
diff changeset
   127
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   128
void
10626
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   129
LogComponent::EnvVarCheck (void)
1783
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
#ifdef HAVE_GETENV
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
   132
  char *envVar = getenv ("NS_LOG");
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   133
  if (envVar == 0)
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
      return;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   136
    }
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   137
  std::string env = envVar;
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   138
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   139
  std::string::size_type cur = 0;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   140
  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
   141
  while (next != std::string::npos)
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   142
    {
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
   143
      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
   144
      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
   145
      std::string::size_type equal = tmp.find ("=");
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   146
      std::string component;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   147
      if (equal == std::string::npos)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   148
        {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   149
          component = tmp;
10626
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   150
          if (component == m_name || component == "*" || component == "***")
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   151
            {
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   152
              int level = LOG_LEVEL_ALL | LOG_PREFIX_ALL;
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
   153
              Enable ((enum LogLevel)level);
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   154
              return;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   155
            }
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
        }
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   157
      else
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   158
        {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   159
          component = tmp.substr (0, equal);
10626
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   160
          if (component == m_name || component == "*")
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   161
            {
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   162
              int level = 0;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   163
              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
   164
              std::string::size_type next_lev = equal;
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   165
              bool pre_pipe = true;  // before the first '|', enables positional 'all', '*'
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   166
              do
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   167
                {
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   168
                  cur_lev = next_lev + 1;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   169
                  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
   170
                  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
   171
                  if (lev == "error")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   172
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   173
                      level |= LOG_ERROR;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   174
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   175
                  else if (lev == "warn")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   176
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   177
                      level |= LOG_WARN;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   178
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   179
                  else if (lev == "debug")
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
                      level |= LOG_DEBUG;
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
                  else if (lev == "info")
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
                      level |= LOG_INFO;
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
                  else if (lev == "function")
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
                      level |= LOG_FUNCTION;
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
                  else if (lev == "logic")
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
                      level |= LOG_LOGIC;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   194
                    }
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   195
                  else if ( pre_pipe && ( (lev == "all") || (lev == "*") ) )
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   196
                    {
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   197
                      level |= LOG_LEVEL_ALL;
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   198
                    }
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   199
                  else if ( (lev == "prefix_func") || (lev == "func") )
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   200
                    {
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   201
                      level |= LOG_PREFIX_FUNC;
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   202
                    }
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   203
                  else if ( (lev == "prefix_time") || (lev == "time") )
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   204
                    {
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   205
                      level |= LOG_PREFIX_TIME;
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   206
                    }
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   207
                  else if ( (lev == "prefix_node") || (lev == "node") )
5522
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   208
                    {
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   209
                      level |= LOG_PREFIX_NODE;
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   210
                    }
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   211
                  else if ( (lev == "prefix_level") || (lev == "level") )
9119
9c0cc3997ece [Bug 1496] Print the LOG_LEVEL (severity) in NS_LOG messages.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   212
                    {
9c0cc3997ece [Bug 1496] Print the LOG_LEVEL (severity) in NS_LOG messages.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   213
                      level |= LOG_PREFIX_LEVEL;
9c0cc3997ece [Bug 1496] Print the LOG_LEVEL (severity) in NS_LOG messages.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   214
                    }
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   215
                  else if ( (lev == "prefix_all") ||
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   216
                            (!pre_pipe && ( (lev == "all") || (lev == "*") ) )
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   217
                            )
9119
9c0cc3997ece [Bug 1496] Print the LOG_LEVEL (severity) in NS_LOG messages.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   218
                    {
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   219
                      level |= LOG_PREFIX_ALL;
9119
9c0cc3997ece [Bug 1496] Print the LOG_LEVEL (severity) in NS_LOG messages.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   220
                    }
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   221
                  else if (lev == "level_error")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   222
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   223
                      level |= LOG_LEVEL_ERROR;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   224
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   225
                  else if (lev == "level_warn")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   226
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   227
                      level |= LOG_LEVEL_WARN;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   228
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   229
                  else if (lev == "level_debug")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   230
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   231
                      level |= LOG_LEVEL_DEBUG;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   232
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   233
                  else if (lev == "level_info")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   234
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   235
                      level |= LOG_LEVEL_INFO;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   236
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   237
                  else if (lev == "level_function")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   238
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   239
                      level |= LOG_LEVEL_FUNCTION;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   240
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   241
                  else if (lev == "level_logic")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   242
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   243
                      level |= LOG_LEVEL_LOGIC;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   244
                    }
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   245
                  else if (lev == "level_all")
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   246
                    {
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   247
                      level |= LOG_LEVEL_ALL;
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   248
                    }
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   249
                  else if (lev == "**")
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   250
                    {
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   251
                      level |= LOG_LEVEL_ALL | LOG_PREFIX_ALL;
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   252
                    }
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   253
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   254
                  pre_pipe = false;
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   255
                } 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
   256
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   257
              Enable ((enum LogLevel)level);
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   258
            }
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
      cur = next + 1;
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
#endif
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   263
}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   264
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   265
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   266
bool 
10626
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   267
LogComponent::IsEnabled (const enum LogLevel level) const
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   268
{
1775
5abf6f0d1eca deal with static constructor problem
Craig Dowell <craigdo@ee.washington.edu>
parents: 1773
diff changeset
   269
  //  LogComponentEnableEnvVar ();
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   270
  return (level & m_levels) ? 1 : 0;
1498
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
bool
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   274
LogComponent::IsNoneEnabled (void) const
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   275
{
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   276
  return m_levels == 0;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   277
}
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   278
10625
c3e9a5530654 [Bug 1792] [Bug 1853] Remove inheritance from std::stream in ParameterLogger
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10399
diff changeset
   279
void
10626
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   280
LogComponent::SetMask (const enum LogLevel level)
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   281
{
10626
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   282
  m_mask |= level;
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   283
}
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   284
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   285
void 
10626
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   286
LogComponent::Enable (const enum LogLevel level)
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   287
{
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   288
  m_levels |= (level & ~m_mask);
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   289
}
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   290
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   291
void 
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   292
LogComponent::Disable (const enum LogLevel level)
1498
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
  m_levels &= ~level;
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
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   297
char const *
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   298
LogComponent::Name (void) const
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   299
{
10228
8244f0b3ff1b [bug 1552] Storing log name inside LogComponent class (NS_LOG) as std::string
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10157
diff changeset
   300
  return m_name.c_str ();
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   301
}
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   302
10996
4f369a4a89c1 Generate doxygen list of all LogComponents
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10676
diff changeset
   303
std::string
4f369a4a89c1 Generate doxygen list of all LogComponents
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10676
diff changeset
   304
LogComponent::File (void) const
4f369a4a89c1 Generate doxygen list of all LogComponents
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10676
diff changeset
   305
{
4f369a4a89c1 Generate doxygen list of all LogComponents
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10676
diff changeset
   306
  return m_file;
4f369a4a89c1 Generate doxygen list of all LogComponents
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10676
diff changeset
   307
}
4f369a4a89c1 Generate doxygen list of all LogComponents
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10676
diff changeset
   308
10626
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   309
/* static */
9119
9c0cc3997ece [Bug 1496] Print the LOG_LEVEL (severity) in NS_LOG messages.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   310
std::string
10626
16bbfc4cb29d [Bug 1862] NS_LOG="Time=*|prefix_time" causes stack overflow
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10625
diff changeset
   311
LogComponent::GetLevelLabel(const enum LogLevel level)
9119
9c0cc3997ece [Bug 1496] Print the LOG_LEVEL (severity) in NS_LOG messages.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   312
{
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   313
  if (level == LOG_ERROR)
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   314
    {
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   315
      return "ERROR";
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   316
    }
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   317
  else if (level == LOG_WARN)
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   318
    {
9692
792f0e8525b8 Backed out changeset e1e45baa7046, adding comment to log.cc to prevent confusion
Vedran Miletić <rivanvx@gmail.com>
parents: 9691
diff changeset
   319
      // whitespace left at the end for aligment
792f0e8525b8 Backed out changeset e1e45baa7046, adding comment to log.cc to prevent confusion
Vedran Miletić <rivanvx@gmail.com>
parents: 9691
diff changeset
   320
      return "WARN ";
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   321
    }
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   322
  else if (level == LOG_DEBUG)
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   323
    {
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   324
      return "DEBUG";
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   325
    }
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   326
  else if (level == LOG_INFO)
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   327
    {
9692
792f0e8525b8 Backed out changeset e1e45baa7046, adding comment to log.cc to prevent confusion
Vedran Miletić <rivanvx@gmail.com>
parents: 9691
diff changeset
   328
      // whitespace left at the end for aligment
792f0e8525b8 Backed out changeset e1e45baa7046, adding comment to log.cc to prevent confusion
Vedran Miletić <rivanvx@gmail.com>
parents: 9691
diff changeset
   329
      return "INFO ";
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   330
    }
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   331
  else if (level == LOG_FUNCTION)
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   332
    {
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   333
      return "FUNCT";
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   334
    }
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   335
  else if (level == LOG_LOGIC)
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   336
    {
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   337
      return "LOGIC";
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   338
    }
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   339
  else
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   340
    {
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   341
      return "unknown";
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   342
    }
9119
9c0cc3997ece [Bug 1496] Print the LOG_LEVEL (severity) in NS_LOG messages.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   343
}
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   344
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   345
void 
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   346
LogComponentEnable (char const *name, enum LogLevel level)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   347
{
11134
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   348
  LogComponent::ComponentList *components = LogComponent::GetComponentList ();
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   349
  LogComponent::ComponentList::const_iterator i;
7413
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   350
  for (i = components->begin (); 
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   351
       i != components->end (); 
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   352
       i++)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   353
    {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   354
      if (i->first.compare (name) == 0) 
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   355
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   356
          i->second->Enable (level);
7413
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   357
          return;
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   358
        }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   359
    }
7413
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   360
    if (i == components->end())
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   361
      {
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   362
	// nothing matched
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   363
        LogComponentPrintList();
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   364
        NS_FATAL_ERROR ("Logging component \"" << name <<
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   365
                        "\" not found. See above for a list of available log components");
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   366
    }
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   367
}
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   368
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   369
void 
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   370
LogComponentEnableAll (enum LogLevel level)
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   371
{
11134
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   372
  LogComponent::ComponentList *components = LogComponent::GetComponentList ();
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   373
  for (LogComponent::ComponentList::const_iterator i = components->begin ();
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   374
       i != components->end ();
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   375
       i++)
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   376
    {
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   377
      i->second->Enable (level);
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   378
    }
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   379
}
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   380
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   381
void 
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   382
LogComponentDisable (char const *name, enum LogLevel level)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   383
{
11134
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   384
  LogComponent::ComponentList *components = LogComponent::GetComponentList ();
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   385
  for (LogComponent::ComponentList::const_iterator i = components->begin ();
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   386
       i != components->end ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   387
       i++)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   388
    {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   389
      if (i->first.compare (name) == 0) 
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   390
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   391
          i->second->Disable (level);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   392
          break;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   393
        }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   394
    }
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   395
}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   396
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   397
void 
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   398
LogComponentDisableAll (enum LogLevel level)
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   399
{
11134
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   400
  LogComponent::ComponentList *components = LogComponent::GetComponentList ();
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   401
  for (LogComponent::ComponentList::const_iterator i = components->begin ();
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   402
       i != components->end ();
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   403
       i++)
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   404
    {
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   405
      i->second->Disable (level);
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   406
    }
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   407
}
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   408
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   409
void 
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   410
LogComponentPrintList (void)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   411
{
11134
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   412
  LogComponent::ComponentList *components = LogComponent::GetComponentList ();
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   413
  for (LogComponent::ComponentList::const_iterator i = components->begin ();
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   414
       i != components->end ();
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   415
       i++)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   416
    {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   417
      std::cout << i->first << "=";
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   418
      if (i->second->IsNoneEnabled ())
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   419
        {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   420
          std::cout << "0" << std::endl;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   421
          continue;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   422
        }
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   423
      if (i->second->IsEnabled (LOG_LEVEL_ALL))
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   424
        {
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   425
          std::cout << "all";
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   426
        }
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   427
      else
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   428
        {
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   429
          if (i->second->IsEnabled (LOG_ERROR))
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   430
            {
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   431
              std::cout << "error";
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   432
            }
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   433
          if (i->second->IsEnabled (LOG_WARN))
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   434
            {
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   435
              std::cout << "|warn";
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   436
            }
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   437
          if (i->second->IsEnabled (LOG_DEBUG))
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   438
            {
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   439
              std::cout << "|debug";
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   440
            }
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   441
          if (i->second->IsEnabled (LOG_INFO))
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   442
            {
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   443
              std::cout << "|info";
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   444
            }
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   445
          if (i->second->IsEnabled (LOG_FUNCTION))
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   446
            {
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   447
              std::cout << "|function";
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   448
            }
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   449
          if (i->second->IsEnabled (LOG_LOGIC))
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   450
            {
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   451
              std::cout << "|logic";
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   452
            }
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   453
        }
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   454
      if (i->second->IsEnabled (LOG_PREFIX_ALL))
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   455
        {
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   456
          std::cout << "|prefix_all";
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   457
        }
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   458
      else
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   459
        {
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   460
          if (i->second->IsEnabled (LOG_PREFIX_FUNC))
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   461
            {
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   462
              std::cout << "|func";
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   463
            }
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   464
          if (i->second->IsEnabled (LOG_PREFIX_TIME))
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   465
            {
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   466
              std::cout << "|time";
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   467
            }
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   468
          if (i->second->IsEnabled (LOG_PREFIX_NODE))
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   469
            {
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   470
              std::cout << "|node";
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   471
            }
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   472
          if (i->second->IsEnabled (LOG_PREFIX_LEVEL))
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   473
            {
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   474
              std::cout << "|level";
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   475
            }
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   476
        }
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   477
      std::cout << std::endl;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   478
    }
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   479
}
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   480
11134
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   481
/**
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   482
 * Check if a log component exists.
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   483
 *
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   484
 * \param componentName The putative log component name.
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   485
 * \returns \c true if \c componentName exists.
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   486
 */
7413
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   487
static bool ComponentExists(std::string componentName) 
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   488
{
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   489
  char const*name=componentName.c_str();
11134
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   490
  LogComponent::ComponentList *components = LogComponent::GetComponentList ();
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   491
  LogComponent::ComponentList::const_iterator i;
7413
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   492
  for (i = components->begin ();
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   493
       i != components->end ();
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   494
       i++)
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   495
     {
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   496
       if (i->first.compare (name) == 0) 
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   497
 	{
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   498
	  return true;
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   499
 	}
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   500
    }
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   501
  NS_ASSERT (i == components->end());
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   502
  // nothing matched 
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   503
  return false;    
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   504
}
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   505
11134
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   506
/**
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   507
 * Parse the \c NS_LOG environment variable.
f0150679fa80 [Doxygen] Logging
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10996
diff changeset
   508
 */
7413
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   509
static void CheckEnvironmentVariables (void)
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   510
{
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   511
#ifdef HAVE_GETENV
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   512
  char *envVar = getenv ("NS_LOG");
9131
fab987059055 Change to C++-style includes in log.cc.
Vedran Miletić <rivanvx@gmail.com>
parents: 9119
diff changeset
   513
  if (envVar == 0 || std::strlen(envVar) == 0)
7413
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   514
    {
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   515
      return;
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   516
    }
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   517
  std::string env = envVar;
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   518
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   519
  std::string::size_type cur = 0;
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   520
  std::string::size_type next = 0;
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   521
  
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   522
  while (next != std::string::npos)
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   523
    {
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   524
      next = env.find_first_of (":", cur);
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   525
      std::string tmp = std::string (env, cur, next-cur);
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   526
      std::string::size_type equal = tmp.find ("=");
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   527
      std::string component;
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   528
      if (equal == std::string::npos)
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   529
        {
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   530
          // ie no '=' characters found 
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   531
          component = tmp;
10229
4da5979086e8 Logging wildcards: allow "***" as synonym for "*=**"
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10228
diff changeset
   532
          if (ComponentExists(component) || component == "*" || component == "***")
7413
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   533
            {
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   534
              return;
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   535
            }
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   536
	  else 
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   537
            {
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   538
	      LogComponentPrintList();
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   539
              NS_FATAL_ERROR("Invalid or unregistered component name \"" << component <<
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   540
                             "\" in env variable NS_LOG, see above for a list of valid components");
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   541
            }
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   542
        }
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   543
      else
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   544
        {
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   545
          component = tmp.substr (0, equal);
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   546
          if (ComponentExists(component) || component == "*")
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   547
            {
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   548
              std::string::size_type cur_lev;
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   549
              std::string::size_type next_lev = equal;
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   550
              do
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   551
                {
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   552
                  cur_lev = next_lev + 1;
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   553
                  next_lev = tmp.find ("|", cur_lev);
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   554
                  std::string lev = tmp.substr (cur_lev, next_lev - cur_lev);
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   555
                  if (lev == "error"
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   556
                      || lev == "warn"
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   557
                      || lev == "debug"
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   558
                      || lev == "info"
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   559
                      || lev == "function"
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   560
                      || lev == "logic"
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   561
                      || lev == "all"
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   562
                      || lev == "prefix_func"
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   563
                      || lev == "func"
7413
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   564
                      || lev == "prefix_time"
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   565
                      || lev == "time"
7413
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   566
                      || lev == "prefix_node"
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   567
                      || lev == "node"
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   568
                      || lev == "prefix_level"
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   569
                      || lev == "level"
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   570
                      || lev == "prefix_all"
7413
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   571
                      || lev == "level_error"
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   572
                      || lev == "level_warn"
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   573
                      || lev == "level_debug"
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   574
                      || lev == "level_info"
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   575
                      || lev == "level_function"
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   576
                      || lev == "level_logic"
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   577
                      || lev == "level_all"
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   578
                      || lev == "*"
9184
065a297f6c9d bug 1531: Crash when using NS_LOG in destructors of static objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9131
diff changeset
   579
                      || lev == "**"
7413
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   580
		     )
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   581
                    {
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   582
                      continue;
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   583
                    }
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   584
		  else
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   585
                    {
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   586
                      NS_FATAL_ERROR("Invalid log level \"" << lev <<
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   587
                                     "\" in env variable NS_LOG for component name " << component);
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   588
                    }
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   589
                } while (next_lev != std::string::npos);
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   590
            }
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   591
          else 
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   592
            {
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   593
              LogComponentPrintList();
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   594
              NS_FATAL_ERROR("Invalid or unregistered component name \"" << component <<
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   595
                             "\" in env variable NS_LOG, see above for a list of valid components");
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   596
            }
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   597
        }
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   598
      cur = next + 1;	// parse next component
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   599
    }
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   600
#endif
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   601
}
3005
cc521f35f033 avoid segfault when setting NS_LOG=*
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2983
diff changeset
   602
void LogSetTimePrinter (LogTimePrinter printer)
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   603
{
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   604
  g_logTimePrinter = printer;
10157
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9692
diff changeset
   605
  /** \internal
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9692
diff changeset
   606
   *  This is the only place where we are more or less sure that all log variables
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9692
diff changeset
   607
   * are registered. See \bugid{1082} for details.
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9692
diff changeset
   608
   */
7413
1e965c4c084b bug 1082: Check that log component names are correct when taken from NS_LOG.
Anirudh Sivaraman <sk.anirudh@gmail.com>
parents: 7256
diff changeset
   609
  CheckEnvironmentVariables(); 
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   610
}
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
   611
LogTimePrinter LogGetTimePrinter (void)
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   612
{
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   613
  return g_logTimePrinter;
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   614
}
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   615
5522
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   616
void LogSetNodePrinter (LogNodePrinter printer)
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   617
{
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   618
  g_logNodePrinter = printer;
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   619
}
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
   620
LogNodePrinter LogGetNodePrinter (void)
5522
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   621
{
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   622
  return g_logNodePrinter;
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   623
}
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 3483
diff changeset
   624
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   625
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   626
ParameterLogger::ParameterLogger (std::ostream &os)
10625
c3e9a5530654 [Bug 1792] [Bug 1853] Remove inheritance from std::stream in ParameterLogger
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10399
diff changeset
   627
  : m_first (true),
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   628
    m_os (os)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   629
{
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   630
}
1828
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1783
diff changeset
   631
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   632
} // namespace ns3