src/core/log.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 14 Apr 2008 12:15:05 -0700
changeset 2980 98b75bde4403
parent 2979 3d39dd617b8d
child 2981 982a6f364d2c
permissions -rw-r--r--
add doxygen.
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
 */
1506
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
    20
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
    21
#ifndef __LOG_H__
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
    22
#define __LOG_H__
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
#include <string>
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
#include <iostream>
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
2978
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
    27
#ifdef NS3_LOG_ENABLE
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
    28
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
    29
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
/**
2217
0b4567d545de Doxygen organization
Tom Henderson <tomh@tomh.org>
parents: 1830
diff changeset
    31
 * \ingroup core
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
 * \defgroup logging Logging
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
 * \brief Logging functions and macros
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
 *
2346
ff124e6986a7 Update NS_LOG documentation
Tom Henderson <tomh@tomh.org>
parents: 2294
diff changeset
    35
 * LOG functionality: macros which allow developers to
ff124e6986a7 Update NS_LOG documentation
Tom Henderson <tomh@tomh.org>
parents: 2294
diff changeset
    36
 * send information out on screen. All logging messages 
ff124e6986a7 Update NS_LOG documentation
Tom Henderson <tomh@tomh.org>
parents: 2294
diff changeset
    37
 * are disabled by default. To enable selected logging 
ff124e6986a7 Update NS_LOG documentation
Tom Henderson <tomh@tomh.org>
parents: 2294
diff changeset
    38
 * messages, use the ns3::LogComponentEnable
ff124e6986a7 Update NS_LOG documentation
Tom Henderson <tomh@tomh.org>
parents: 2294
diff changeset
    39
 * function or use the NS_LOG environment variable 
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    40
 *
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    41
 * Use the environment variable NS_LOG to define a ';'-separated list of
2346
ff124e6986a7 Update NS_LOG documentation
Tom Henderson <tomh@tomh.org>
parents: 2294
diff changeset
    42
 * logging components to enable. For example (using bash syntax), 
ff124e6986a7 Update NS_LOG documentation
Tom Henderson <tomh@tomh.org>
parents: 2294
diff changeset
    43
 * NS_LOG="OlsrAgent" would enable one component; 
ff124e6986a7 Update NS_LOG documentation
Tom Henderson <tomh@tomh.org>
parents: 2294
diff changeset
    44
 * NS_LOG="OlsrAgent;Ipv4L3Protocol" would enable two
ff124e6986a7 Update NS_LOG documentation
Tom Henderson <tomh@tomh.org>
parents: 2294
diff changeset
    45
 * components, etc.  NS_LOG="*" will enable all available log components.
ff124e6986a7 Update NS_LOG documentation
Tom Henderson <tomh@tomh.org>
parents: 2294
diff changeset
    46
 * For each component, the "debug" log level is enabled by default.
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    47
 *
2346
ff124e6986a7 Update NS_LOG documentation
Tom Henderson <tomh@tomh.org>
parents: 2294
diff changeset
    48
 * To obtain more components than just debug log level, more components 
ff124e6986a7 Update NS_LOG documentation
Tom Henderson <tomh@tomh.org>
parents: 2294
diff changeset
    49
 * can be enabled selectively with the following
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    50
 * syntax: NS_LOG='Component1=func|param|warn;Component2=error|debug'
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    51
 * This example would enable the 'func', 'param', and 'warn' log
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    52
 * levels for 'Component1' and the 'error' and 'debug' log levels
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    53
 * for 'Component2'.  The wildcard can be used here as well.  For example
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    54
 * NS_LOG='*=level_all|prefix' would enable all log levels and prefix all
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    55
 * prints with the component and function names.
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
    56
 *
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
 */
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
/**
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
 * \ingroup logging
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
 * \param name a string
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
 *
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
 * Define a Log component with a specific name. This macro
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
 * should be used at the top of every file in which you want 
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
 * to use the NS_LOG macro. This macro defines a new
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
 * "log component" which can be later selectively enabled
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
 * or disabled with the ns3::LogComponentEnable and 
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
 * ns3::LogComponentDisable functions or with the NS_LOG
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
 * environment variable.
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
 */
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    71
#define NS_LOG_COMPONENT_DEFINE(name)                           \
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
  static ns3::LogComponent g_log = ns3::LogComponent (name)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    74
#define APPEND_TIME_PREFIX                                      \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    75
  if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME))                   \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    76
    {                                                           \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    77
      LogTimePrinter printer = LogGetTimePrinter ();            \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    78
      if (printer != 0)                                         \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    79
        {                                                       \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    80
          (*printer) (std::clog);                               \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    81
          std::clog << " ";                                     \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    82
        }                                                       \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    83
    }
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    84
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    85
#define APPEND_FUNC_PREFIX                                      \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    86
  if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC))                   \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    87
    {                                                           \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    88
      std::clog << g_log.Name () << ":" <<                      \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    89
        __FUNCTION__ << "(): ";                                 \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    90
    }                                                           \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    91
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
    92
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
/**
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
 * \ingroup logging
1795
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
    95
 * \param level the log level
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
    96
 * \param msg the message to log
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
    97
 *
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
    98
 * This macro allows you to log an arbitrary message at a specific
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
    99
 * log level. The log message is expected to be a C++ ostream
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
   100
 * message such as "my string" << aNumber << "my oth stream".
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
   101
 *
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
   102
 * Typical usage looks like:
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
   103
 * \code
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
   104
 * NS_LOG (LOG_DEBUG, "a number="<<aNumber<<", anotherNumber="<<anotherNumber);
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
   105
 * \endcode
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
   106
 */
1506
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
   107
#define NS_LOG(level, msg)                                      \
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
   108
  do                                                            \
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
   109
    {                                                           \
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
   110
      if (g_log.IsEnabled (level))                              \
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
   111
        {                                                       \
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   112
          APPEND_TIME_PREFIX;                                   \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   113
          APPEND_FUNC_PREFIX;                                   \
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   114
          std::clog << msg << std::endl;                        \
1506
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
   115
        }                                                       \
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
   116
    }                                                           \
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   117
  while (false)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   119
/**
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   120
 * \ingroup logging
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   121
 * \param msg the message to log
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   122
 *
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   123
 * Use \ref NS_LOG to output a message of level LOG_ERROR.
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   124
 */
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   125
#define NS_LOG_ERROR(msg) \
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   126
  NS_LOG(ns3::LOG_ERROR, msg)
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   127
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   128
/**
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   129
 * \ingroup logging
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   130
 * \param msg the message to log
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   131
 *
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   132
 * Use \ref NS_LOG to output a message of level LOG_WARN.
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   133
 */
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   134
#define NS_LOG_WARN(msg) \
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   135
  NS_LOG(ns3::LOG_WARN, msg)
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   136
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   137
/**
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   138
 * \ingroup logging
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   139
 * \param msg the message to log
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   140
 *
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   141
 * Use \ref NS_LOG to output a message of level LOG_DEBUG.
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   142
 */
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   143
#define NS_LOG_DEBUG(msg) \
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   144
  NS_LOG(ns3::LOG_DEBUG, msg)
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   145
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   146
/**
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   147
 * \ingroup logging
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   148
 * \param msg the message to log
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   149
 *
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   150
 * Use \ref NS_LOG to output a message of level LOG_INFO.
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   151
 */
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   152
#define NS_LOG_INFO(msg) \
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   153
  NS_LOG(ns3::LOG_INFO, msg)
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   154
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   155
/**
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   156
 * \ingroup logging
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   157
 *
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   158
 * Output the name of the function.
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   159
 */
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   160
#define NS_LOG_FUNCTION                                         \
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   161
  do                                                            \
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   162
    {                                                           \
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   163
      if (g_log.IsEnabled (ns3::LOG_FUNCTION))                  \
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   164
        {                                                       \
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   165
          APPEND_TIME_PREFIX;                                   \
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   166
          std::clog << g_log.Name () << ":"                     \
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   167
                    << __FUNCTION__ << "()" << std::endl;       \
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   168
        }                                                       \
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   169
    }                                                           \
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1503
diff changeset
   170
  while (false)
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1503
diff changeset
   171
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   172
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   173
/**
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   174
 * \ingroup logging
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   175
 * \param parameters the parameters to output.
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   176
 *
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   177
 * If log level LOG_PARAM is enabled, this macro will output
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   178
 * all input parameters separated by ", ".
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   179
 *
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   180
 * Typical usage looks like:
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   181
 * \code
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   182
 * NS_LOG_PARAMS (aNumber<<anotherNumber);
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   183
 * \endcode
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   184
 * And the output will look like:
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   185
 * \code
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   186
 * Component:Function (aNumber, anotherNumber)
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   187
 * \endcode
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   188
 */
1828
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1795
diff changeset
   189
#define NS_LOG_PARAMS(parameters)                       \
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1795
diff changeset
   190
  do                                                    \
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1795
diff changeset
   191
    {                                                   \
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1795
diff changeset
   192
      if (g_log.IsEnabled (ns3::LOG_PARAM))             \
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1795
diff changeset
   193
        {                                               \
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   194
          APPEND_TIME_PREFIX;                           \
2976
ee338f8cef49 do not use __PRETTY_PRINT__
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   195
          std::clog << g_log.Name () << ":"             \
ee338f8cef49 do not use __PRETTY_PRINT__
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   196
                    << __FUNCTION__ << "(";             \
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   197
          ParameterLogger (std::clog)  << parameters;   \
2976
ee338f8cef49 do not use __PRETTY_PRINT__
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   198
          std::clog << ")" << std::endl;                \
1828
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1795
diff changeset
   199
        }                                               \
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1795
diff changeset
   200
    }                                                   \
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1795
diff changeset
   201
  while (false)
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1795
diff changeset
   202
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1795
diff changeset
   203
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   204
/**
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   205
 * \ingroup logging
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   206
 * \param msg the message to log
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   207
 *
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   208
 * Use \ref NS_LOG to output a message of level LOG_LOGIC
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   209
 */
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   210
#define NS_LOG_LOGIC(msg) \
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   211
  NS_LOG(ns3::LOG_LOGIC, msg)
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   212
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   213
/**
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   214
 * \ingroup logging
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   215
 * \param msg the message to log
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   216
 *
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   217
 * Output the requested message unconditionaly.
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   218
 */
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   219
#define NS_LOG_UNCOND(msg)              \
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   220
  do                                    \
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   221
    {                                   \
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   222
      std::clog << msg << std::endl;    \
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   223
    }                                   \
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   224
  while (false)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   225
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   226
namespace ns3 {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   227
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   228
enum LogLevel {
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   229
  LOG_NONE           = 0x00000000, // no logging
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   230
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   231
  LOG_ERROR          = 0x00000001, // serious error messages only
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   232
  LOG_LEVEL_ERROR    = 0x00000001,
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   233
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   234
  LOG_WARN           = 0x00000002, // warning messages
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   235
  LOG_LEVEL_WARN     = 0x00000003,
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   236
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   237
  LOG_DEBUG          = 0x00000004, // rare ad-hoc debug messages
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   238
  LOG_LEVEL_DEBUG    = 0x00000007,
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   239
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   240
  LOG_INFO           = 0x00000008, // informational messages (e.g., banners)
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   241
  LOG_LEVEL_INFO     = 0x0000000f,
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   242
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   243
  LOG_FUNCTION       = 0x00000010, // function tracing
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   244
  LOG_LEVEL_FUNCTION = 0x0000001f, 
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   245
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   246
  LOG_PARAM          = 0x00000020, // parameters to functions
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   247
  LOG_LEVEL_PARAM    = 0x0000003f,
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   248
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   249
  LOG_LOGIC          = 0x00000040, // control flow tracing within functions
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   250
  LOG_LEVEL_LOGIC    = 0x0000007f,
1507
11a370eecc52 allow discrete levels
Craig Dowell <craigdo@ee.washington.edu>
parents: 1506
diff changeset
   251
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   252
  LOG_ALL            = 0x3fffffff, // print everything
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   253
  LOG_LEVEL_ALL      = LOG_ALL,
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   254
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   255
  LOG_PREFIX_FUNC    = 0x80000000, // prefix all trace prints with function
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   256
  LOG_PREFIX_TIME    = 0x40000000  // prefix all trace prints with simulation time
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   257
};
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
 * \param name a log component name
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   261
 * \param level a logging level
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   262
 * \ingroup logging
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
 * Enable the logging output associated with that log component.
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   265
 * The logging output can be later disabled with a call
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   266
 * to ns3::LogComponentDisable.
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   267
 *
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   268
 * Same as running your program with the NS_LOG environment
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   269
 * variable set as NS_LOG='name=level'
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   270
 */
2978
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   271
void LogComponentEnable (char const *name, enum LogLevel level);
1775
5abf6f0d1eca deal with static constructor problem
Craig Dowell <craigdo@ee.washington.edu>
parents: 1772
diff changeset
   272
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   273
/**
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   274
 * \param level a logging level
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   275
 * \ingroup logging
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   276
 *
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   277
 * Enable the logging output for all registered log components.
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   278
 *
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   279
 * Same as running your program with the NS_LOG environment
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   280
 * variable set as NS_LOG='*=level'
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   281
 */
2978
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   282
void LogComponentEnableAll (enum LogLevel level);
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   283
2978
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   284
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   285
/**
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   286
 * \param name a log component name
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   287
 * \param level a logging level
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   288
 * \ingroup logging
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   289
 *
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   290
 * Disable the logging output associated with that log component.
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   291
 * The logging output can be later re-enabled with a call
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   292
 * to ns3::LogComponentEnable.
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
void LogComponentDisable (char const *name, enum LogLevel level);
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   295
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   296
/**
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   297
 * \param level a logging level
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   298
 * \ingroup logging
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   299
 *
1795
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
   300
 * Disable all logging for all components.
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
void LogComponentDisableAll (enum LogLevel level);
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   303
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   304
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   305
/**
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   306
 * \ingroup logging
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   307
 *
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   308
 * Print the list of logging messages available.
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   309
 * Same as running your program with the NS_LOG environment
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   310
 * variable set as NS_LOG=print-list
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   311
 */
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   312
void LogComponentPrintList (void);
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   313
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   314
typedef void (*LogTimePrinter) (std::ostream &os);
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   315
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   316
void LogRegisterTimePrinter (LogTimePrinter);
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   317
LogTimePrinter LogGetTimePrinter(void);
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   318
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   319
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   320
class LogComponent {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   321
public:
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   322
  LogComponent (char const *name);
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   323
  void EnvVarCheck (char const *name);
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   324
  bool IsEnabled (enum LogLevel level) const;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   325
  bool IsNoneEnabled (void) const;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   326
  void Enable (enum LogLevel level);
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   327
  void Disable (enum LogLevel level);
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   328
  bool Decorate (void) const;
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   329
  char const *Name (void) const;
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   330
private:
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   331
  int32_t     m_levels;
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   332
  char const *m_name;
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   333
  bool        m_decorate;
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   334
};
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   335
2978
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   336
class ParameterLogger : public std::ostream
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   337
{
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   338
  int m_itemNumber;
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   339
  std::ostream &m_os;
2978
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   340
public:
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   341
  ParameterLogger (std::ostream &os);
2978
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   342
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   343
  template<typename T>
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   344
  ParameterLogger& operator<< (T param)
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   345
  {
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   346
    switch (m_itemNumber)
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   347
      {
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   348
      case 0: // first parameter
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   349
        m_os << param;
2978
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   350
        break;
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   351
      default: // parameter following a previous parameter
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   352
        m_os << ", " << param;
2978
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   353
        break;
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   354
      }
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   355
    m_itemNumber++;
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   356
    return *this;
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   357
  }
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   358
};
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   359
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   360
} // namespace ns3
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   361
2978
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   362
#else /* LOG_ENABLE */
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   363
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   364
#define NS_LOG_COMPONENT_DEFINE(component)
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   365
#define NS_LOG(level, msg)
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   366
#define NS_LOG_ERROR(msg)
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   367
#define NS_LOG_WARN(msg)
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   368
#define NS_LOG_DEBUG(msg)
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   369
#define NS_LOG_INFO(msg)
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   370
#define NS_LOG_FUNCTION
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   371
#define NS_LOG_PARAMS(parameters)
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   372
#define NS_LOG_LOGIC(msg)
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   373
#define NS_LOG_UNCOND(msg)
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   374
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   375
#define LogComponentPrintList
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   376
#define LogComponentEnable(name,level)
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   377
#define LogComponentDisable(name,level)
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   378
#define LogComponentEnableAll(level)
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   379
#define LogComponentDisableAll(level)
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   380
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   381
#endif /* LOG_ENABLE */
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   382
1506
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
   383
#endif // __LOG_H__