src/core/model/log.h
author Peter D. Barnes, Jr. <barnes26@llnl.gov>
Mon, 20 Aug 2012 11:54:03 -0700
changeset 8995 b86c8ccff7a6
parent 7424 dec79131f5f8
child 9119 9c0cc3997ece
permissions -rw-r--r--
Document preferred usage of NS_LOG_FUNCTION() and NS_LOG_FUNCTION_NOARGS()
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
7353
09fccf6195ea bug 1203: Inconsistently named ifndef/define macros in ns-3 headers
Vedran Miletic <rivanvx@gmail.com>
parents: 7256
diff changeset
    21
#ifndef LOG_H
09fccf6195ea bug 1203: Inconsistently named ifndef/define macros in ns-3 headers
Vedran Miletic <rivanvx@gmail.com>
parents: 7256
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>
4353
596eb8034443 bug 552: build with gcc 4.4
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3530
diff changeset
    26
#include <stdint.h>
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
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: 3182
diff changeset
    28
namespace ns3 {
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3182
diff changeset
    29
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: 3182
diff changeset
    30
enum LogLevel {
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: 3182
diff changeset
    31
  LOG_NONE           = 0x00000000, // no logging
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: 3182
diff changeset
    32
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: 3182
diff changeset
    33
  LOG_ERROR          = 0x00000001, // serious error messages only
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: 3182
diff changeset
    34
  LOG_LEVEL_ERROR    = 0x00000001,
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: 3182
diff changeset
    35
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: 3182
diff changeset
    36
  LOG_WARN           = 0x00000002, // warning messages
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: 3182
diff changeset
    37
  LOG_LEVEL_WARN     = 0x00000003,
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: 3182
diff changeset
    38
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: 3182
diff changeset
    39
  LOG_DEBUG          = 0x00000004, // rare ad-hoc debug messages
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: 3182
diff changeset
    40
  LOG_LEVEL_DEBUG    = 0x00000007,
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: 3182
diff changeset
    41
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: 3182
diff changeset
    42
  LOG_INFO           = 0x00000008, // informational messages (e.g., banners)
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: 3182
diff changeset
    43
  LOG_LEVEL_INFO     = 0x0000000f,
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: 3182
diff changeset
    44
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: 3182
diff changeset
    45
  LOG_FUNCTION       = 0x00000010, // function tracing
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: 3182
diff changeset
    46
  LOG_LEVEL_FUNCTION = 0x0000001f, 
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: 3182
diff changeset
    47
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: 3182
diff changeset
    48
  LOG_LOGIC          = 0x00000020, // control flow tracing within functions
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: 3182
diff changeset
    49
  LOG_LEVEL_LOGIC    = 0x0000003f,
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: 3182
diff changeset
    50
5522
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
    51
  LOG_ALL            = 0x1fffffff, // print everything
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: 3182
diff changeset
    52
  LOG_LEVEL_ALL      = LOG_ALL,
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: 3182
diff changeset
    53
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: 3182
diff changeset
    54
  LOG_PREFIX_FUNC    = 0x80000000, // prefix all trace prints with function
5522
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
    55
  LOG_PREFIX_TIME    = 0x40000000, // prefix all trace prints with simulation time
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
    56
  LOG_PREFIX_NODE    = 0x20000000  // prefix all trace prints with simulation node
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: 3182
diff changeset
    57
};
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: 3182
diff changeset
    58
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: 3182
diff changeset
    59
/**
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: 3182
diff changeset
    60
 * \param name a log component name
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: 3182
diff changeset
    61
 * \param level a logging level
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3182
diff changeset
    62
 * \ingroup logging
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: 3182
diff changeset
    63
 *
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: 3182
diff changeset
    64
 * Enable the logging output associated with that log component.
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: 3182
diff changeset
    65
 * The logging output can be later disabled with a call
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: 3182
diff changeset
    66
 * to ns3::LogComponentDisable.
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: 3182
diff changeset
    67
 *
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: 3182
diff changeset
    68
 * Same as running your program with the NS_LOG environment
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: 3182
diff changeset
    69
 * variable set as NS_LOG='name=level'
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3182
diff changeset
    70
 */
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: 3182
diff changeset
    71
void LogComponentEnable (char const *name, enum LogLevel level);
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3182
diff changeset
    72
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: 3182
diff changeset
    73
/**
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: 3182
diff changeset
    74
 * \param level a logging level
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3182
diff changeset
    75
 * \ingroup logging
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: 3182
diff changeset
    76
 *
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: 3182
diff changeset
    77
 * Enable the logging output for all registered log components.
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: 3182
diff changeset
    78
 *
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: 3182
diff changeset
    79
 * Same as running your program with the NS_LOG environment
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: 3182
diff changeset
    80
 * variable set as NS_LOG='*=level'
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3182
diff changeset
    81
 */
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: 3182
diff changeset
    82
void LogComponentEnableAll (enum LogLevel level);
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3182
diff changeset
    83
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: 3182
diff changeset
    84
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: 3182
diff changeset
    85
/**
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: 3182
diff changeset
    86
 * \param name a log component name
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: 3182
diff changeset
    87
 * \param level a logging level
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3182
diff changeset
    88
 * \ingroup logging
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: 3182
diff changeset
    89
 *
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: 3182
diff changeset
    90
 * Disable the logging output associated with that log component.
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: 3182
diff changeset
    91
 * The logging output can be later re-enabled with a call
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: 3182
diff changeset
    92
 * to ns3::LogComponentEnable.
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: 3182
diff changeset
    93
 */
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: 3182
diff changeset
    94
void LogComponentDisable (char const *name, enum LogLevel level);
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3182
diff changeset
    95
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: 3182
diff changeset
    96
/**
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: 3182
diff changeset
    97
 * \param level a logging level
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3182
diff changeset
    98
 * \ingroup logging
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: 3182
diff changeset
    99
 *
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: 3182
diff changeset
   100
 * Disable all logging for all components.
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: 3182
diff changeset
   101
 */
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: 3182
diff changeset
   102
void LogComponentDisableAll (enum LogLevel level);
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3182
diff changeset
   103
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: 3182
diff changeset
   104
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: 3182
diff changeset
   105
} // namespace ns3
7ce1353e63ba Make the LogComponent* utility functions available for optimized builds as well, albeit as noops. Closes #258.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3182
diff changeset
   106
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
/**
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
 * \ingroup logging
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
 * \param name a string
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
 *
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
 * 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
   112
 * 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
   113
 * 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
   114
 * "log component" which can be later selectively enabled
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
 * or disabled with the ns3::LogComponentEnable and 
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   116
 * ns3::LogComponentDisable functions or with the NS_LOG
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   117
 * environment variable.
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
 */
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   119
#define NS_LOG_COMPONENT_DEFINE(name)                           \
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   120
  static ns3::LogComponent g_log = ns3::LogComponent (name)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   121
3095
ea368d066bea add NS_LOG_APPEND_CONTEXT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3007
diff changeset
   122
#define NS_LOG_APPEND_TIME_PREFIX                               \
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   123
  if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME))                   \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   124
    {                                                           \
3495
67786573098a use fully-qualified c++ typename to allow using macros outside of the ns3 namespace.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3483
diff changeset
   125
      ns3::LogTimePrinter printer = ns3::LogGetTimePrinter ();  \
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   126
      if (printer != 0)                                         \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   127
        {                                                       \
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   128
          (*printer)(std::clog);                               \
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   129
          std::clog << " ";                                     \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   130
        }                                                       \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   131
    }
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   132
5522
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
   133
#define NS_LOG_APPEND_NODE_PREFIX                               \
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
   134
  if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE))                   \
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
   135
    {                                                           \
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
   136
      ns3::LogNodePrinter printer = ns3::LogGetNodePrinter ();  \
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
   137
      if (printer != 0)                                         \
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
   138
        {                                                       \
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   139
          (*printer)(std::clog);                               \
5522
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
   140
          std::clog << " ";                                     \
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
   141
        }                                                       \
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
   142
    }
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
   143
3095
ea368d066bea add NS_LOG_APPEND_CONTEXT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3007
diff changeset
   144
#define NS_LOG_APPEND_FUNC_PREFIX                               \
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   145
  if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC))                   \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   146
    {                                                           \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   147
      std::clog << g_log.Name () << ":" <<                      \
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   148
      __FUNCTION__ << "(): ";                                 \
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   149
    }                                                           \
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   150
3095
ea368d066bea add NS_LOG_APPEND_CONTEXT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3007
diff changeset
   151
#ifndef NS_LOG_APPEND_CONTEXT
ea368d066bea add NS_LOG_APPEND_CONTEXT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3007
diff changeset
   152
#define NS_LOG_APPEND_CONTEXT
ea368d066bea add NS_LOG_APPEND_CONTEXT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3007
diff changeset
   153
#endif /* NS_LOG_APPEND_CONTEXT */
ea368d066bea add NS_LOG_APPEND_CONTEXT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3007
diff changeset
   154
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   155
7424
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   156
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   157
#ifdef NS3_LOG_ENABLE
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   158
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   159
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   160
/**
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   161
 * \ingroup debugging
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   162
 * \defgroup logging Logging
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   163
 * \brief Logging functions and macros
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   164
 *
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   165
 * LOG functionality: macros which allow developers to
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   166
 * send information out on screen. All logging messages 
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   167
 * are disabled by default. To enable selected logging 
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   168
 * messages, use the ns3::LogComponentEnable
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   169
 * function or use the NS_LOG environment variable 
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   170
 *
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   171
 * Use the environment variable NS_LOG to define a ':'-separated list of
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   172
 * logging components to enable. For example (using bash syntax), 
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   173
 * NS_LOG="OlsrAgent" would enable one component at all log levels. 
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   174
 * NS_LOG="OlsrAgent:Ipv4L3Protocol" would enable two components, 
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   175
 * at all log levels, etc.
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   176
 * NS_LOG="*" will enable all available log components at all levels.
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   177
 *
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   178
 * To control more selectively the log levels for each component, use
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   179
 * this syntax: NS_LOG='Component1=func|warn:Component2=error|debug'
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   180
 * This example would enable the 'func', and 'warn' log
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   181
 * levels for 'Component1' and the 'error' and 'debug' log levels
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   182
 * for 'Component2'.  The wildcard can be used here as well.  For example
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   183
 * NS_LOG='*=level_all|prefix' would enable all log levels and prefix all
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   184
 * prints with the component and function names.
8995
b86c8ccff7a6 Document preferred usage of NS_LOG_FUNCTION() and
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7424
diff changeset
   185
 *
b86c8ccff7a6 Document preferred usage of NS_LOG_FUNCTION() and
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7424
diff changeset
   186
 * A note on NS_LOG_FUNCTION() and NS_LOG_FUNCTION_NOARGS():
b86c8ccff7a6 Document preferred usage of NS_LOG_FUNCTION() and
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7424
diff changeset
   187
 * generally, use of (at least) NS_LOG_FUNCTION(this) is preferred.
b86c8ccff7a6 Document preferred usage of NS_LOG_FUNCTION() and
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7424
diff changeset
   188
 * Use NS_LOG_FUNCTION_NOARGS() only in static functions.
7424
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   189
 */
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   190
dec79131f5f8 bug 1244: Seg Faults in optimized builds due to missing Logging components
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7353
diff changeset
   191
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   192
/**
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   193
 * \ingroup logging
1795
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
   194
 * \param level the log level
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
   195
 * \param msg the message to log
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
   196
 *
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
   197
 * 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
   198
 * 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
   199
 * 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
   200
 *
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
   201
 * Typical usage looks like:
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
   202
 * \code
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
   203
 * 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
   204
 * \endcode
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1783
diff changeset
   205
 */
1506
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
   206
#define NS_LOG(level, msg)                                      \
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
   207
  do                                                            \
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
   208
    {                                                           \
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
   209
      if (g_log.IsEnabled (level))                              \
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
   210
        {                                                       \
3095
ea368d066bea add NS_LOG_APPEND_CONTEXT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3007
diff changeset
   211
          NS_LOG_APPEND_TIME_PREFIX;                            \
5522
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
   212
          NS_LOG_APPEND_NODE_PREFIX;                            \
3095
ea368d066bea add NS_LOG_APPEND_CONTEXT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3007
diff changeset
   213
          NS_LOG_APPEND_CONTEXT;                                \
ea368d066bea add NS_LOG_APPEND_CONTEXT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3007
diff changeset
   214
          NS_LOG_APPEND_FUNC_PREFIX;                            \
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   215
          std::clog << msg << std::endl;                        \
1506
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
   216
        }                                                       \
3c8b23550e6a disable log unless debug build
Craig Dowell <craigdo@ee.washington.edu>
parents: 1504
diff changeset
   217
    }                                                           \
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   218
  while (false)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   219
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   220
/**
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   221
 * \ingroup logging
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   222
 * \param msg the message to log
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   223
 *
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   224
 * 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
   225
 */
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   226
#define NS_LOG_ERROR(msg) \
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   227
  NS_LOG (ns3::LOG_ERROR, msg)
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   228
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   229
/**
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   230
 * \ingroup logging
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   231
 * \param msg the message to log
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   232
 *
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   233
 * 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
   234
 */
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   235
#define NS_LOG_WARN(msg) \
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   236
  NS_LOG (ns3::LOG_WARN, msg)
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   237
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   238
/**
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   239
 * \ingroup logging
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   240
 * \param msg the message to log
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   241
 *
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   242
 * 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
   243
 */
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   244
#define NS_LOG_DEBUG(msg) \
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   245
  NS_LOG (ns3::LOG_DEBUG, msg)
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   246
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   247
/**
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   248
 * \ingroup logging
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   249
 * \param msg the message to log
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   250
 *
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   251
 * 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
   252
 */
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   253
#define NS_LOG_INFO(msg) \
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   254
  NS_LOG (ns3::LOG_INFO, msg)
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   255
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   256
/**
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   257
 * \ingroup logging
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   258
 *
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   259
 * Output the name of the function.
8995
b86c8ccff7a6 Document preferred usage of NS_LOG_FUNCTION() and
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7424
diff changeset
   260
 *
b86c8ccff7a6 Document preferred usage of NS_LOG_FUNCTION() and
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7424
diff changeset
   261
 * This should be used only in static functions; most member functions
b86c8ccff7a6 Document preferred usage of NS_LOG_FUNCTION() and
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7424
diff changeset
   262
 * should instead use NS_LOG_FUNCTION().
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   263
 */
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2982
diff changeset
   264
#define NS_LOG_FUNCTION_NOARGS()                                \
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   265
  do                                                            \
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   266
    {                                                           \
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   267
      if (g_log.IsEnabled (ns3::LOG_FUNCTION))                  \
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   268
        {                                                       \
3095
ea368d066bea add NS_LOG_APPEND_CONTEXT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3007
diff changeset
   269
          NS_LOG_APPEND_TIME_PREFIX;                            \
5522
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
   270
          NS_LOG_APPEND_NODE_PREFIX;                            \
3095
ea368d066bea add NS_LOG_APPEND_CONTEXT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3007
diff changeset
   271
          NS_LOG_APPEND_CONTEXT;                                \
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   272
          std::clog << g_log.Name () << ":"                     \
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   273
                    << __FUNCTION__ << "()" << std::endl;       \
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   274
        }                                                       \
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   275
    }                                                           \
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1503
diff changeset
   276
  while (false)
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1503
diff changeset
   277
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   278
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   279
/**
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   280
 * \ingroup logging
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   281
 * \param parameters the parameters to output.
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   282
 *
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2982
diff changeset
   283
 * If log level LOG_FUNCTION is enabled, this macro will output
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   284
 * all input parameters separated by ", ".
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   285
 *
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   286
 * Typical usage looks like:
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   287
 * \code
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2982
diff changeset
   288
 * NS_LOG_FUNCTION (aNumber<<anotherNumber);
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   289
 * \endcode
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   290
 * And the output will look like:
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   291
 * \code
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   292
 * Component:Function (aNumber, anotherNumber)
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   293
 * \endcode
8995
b86c8ccff7a6 Document preferred usage of NS_LOG_FUNCTION() and
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7424
diff changeset
   294
 *
b86c8ccff7a6 Document preferred usage of NS_LOG_FUNCTION() and
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7424
diff changeset
   295
 * To facilitate function tracing, most functions should begin with
b86c8ccff7a6 Document preferred usage of NS_LOG_FUNCTION() and
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7424
diff changeset
   296
 * (at least) NS_LOG_FUNCTION(this).  Static functions should use
b86c8ccff7a6 Document preferred usage of NS_LOG_FUNCTION() and
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7424
diff changeset
   297
 * NS_LOG_FUNCTION_NOARGS() instead.
b86c8ccff7a6 Document preferred usage of NS_LOG_FUNCTION() and
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7424
diff changeset
   298
 *
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   299
 */
3530
b1744fac67da fully qualify class name to use macro outside of ns3 namespace.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3495
diff changeset
   300
#define NS_LOG_FUNCTION(parameters)                             \
b1744fac67da fully qualify class name to use macro outside of ns3 namespace.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3495
diff changeset
   301
  do                                                            \
b1744fac67da fully qualify class name to use macro outside of ns3 namespace.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3495
diff changeset
   302
    {                                                           \
b1744fac67da fully qualify class name to use macro outside of ns3 namespace.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3495
diff changeset
   303
      if (g_log.IsEnabled (ns3::LOG_FUNCTION))                  \
b1744fac67da fully qualify class name to use macro outside of ns3 namespace.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3495
diff changeset
   304
        {                                                       \
b1744fac67da fully qualify class name to use macro outside of ns3 namespace.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3495
diff changeset
   305
          NS_LOG_APPEND_TIME_PREFIX;                            \
5522
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
   306
          NS_LOG_APPEND_NODE_PREFIX;                            \
3530
b1744fac67da fully qualify class name to use macro outside of ns3 namespace.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3495
diff changeset
   307
          NS_LOG_APPEND_CONTEXT;                                \
b1744fac67da fully qualify class name to use macro outside of ns3 namespace.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3495
diff changeset
   308
          std::clog << g_log.Name () << ":"                     \
b1744fac67da fully qualify class name to use macro outside of ns3 namespace.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3495
diff changeset
   309
                    << __FUNCTION__ << "(";                     \
7252
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7169
diff changeset
   310
          ns3::ParameterLogger (std::clog) << parameters;      \
3530
b1744fac67da fully qualify class name to use macro outside of ns3 namespace.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3495
diff changeset
   311
          std::clog << ")" << std::endl;                        \
b1744fac67da fully qualify class name to use macro outside of ns3 namespace.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3495
diff changeset
   312
        }                                                       \
b1744fac67da fully qualify class name to use macro outside of ns3 namespace.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3495
diff changeset
   313
    }                                                           \
1828
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1795
diff changeset
   314
  while (false)
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1795
diff changeset
   315
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1795
diff changeset
   316
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   317
/**
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   318
 * \ingroup logging
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   319
 * \param msg the message to log
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   320
 *
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   321
 * 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
   322
 */
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   323
#define NS_LOG_LOGIC(msg) \
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   324
  NS_LOG (ns3::LOG_LOGIC, msg)
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   325
2980
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   326
/**
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   327
 * \ingroup logging
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   328
 * \param msg the message to log
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   329
 *
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   330
 * Output the requested message unconditionaly.
98b75bde4403 add doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2979
diff changeset
   331
 */
1503
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   332
#define NS_LOG_UNCOND(msg)              \
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   333
  do                                    \
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   334
    {                                   \
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   335
      std::clog << msg << std::endl;    \
53dd8f414ba6 sorting out logging
Craig Dowell <craigdo@ee.washington.edu>
parents: 1498
diff changeset
   336
    }                                   \
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   337
  while (false)
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   338
7017
f288fc1bb2be making NS3_LOGGING_ENABLE control macro expansion and nothing more
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 6821
diff changeset
   339
#else /* LOG_ENABLE */
f288fc1bb2be making NS3_LOGGING_ENABLE control macro expansion and nothing more
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 6821
diff changeset
   340
f288fc1bb2be making NS3_LOGGING_ENABLE control macro expansion and nothing more
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 6821
diff changeset
   341
#define NS_LOG(level, msg)
f288fc1bb2be making NS3_LOGGING_ENABLE control macro expansion and nothing more
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 6821
diff changeset
   342
#define NS_LOG_ERROR(msg)
f288fc1bb2be making NS3_LOGGING_ENABLE control macro expansion and nothing more
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 6821
diff changeset
   343
#define NS_LOG_WARN(msg)
f288fc1bb2be making NS3_LOGGING_ENABLE control macro expansion and nothing more
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 6821
diff changeset
   344
#define NS_LOG_DEBUG(msg)
f288fc1bb2be making NS3_LOGGING_ENABLE control macro expansion and nothing more
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 6821
diff changeset
   345
#define NS_LOG_INFO(msg)
f288fc1bb2be making NS3_LOGGING_ENABLE control macro expansion and nothing more
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 6821
diff changeset
   346
#define NS_LOG_FUNCTION_NOARGS()
f288fc1bb2be making NS3_LOGGING_ENABLE control macro expansion and nothing more
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 6821
diff changeset
   347
#define NS_LOG_FUNCTION(msg)
f288fc1bb2be making NS3_LOGGING_ENABLE control macro expansion and nothing more
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 6821
diff changeset
   348
#define NS_LOG_LOGIC(msg)
f288fc1bb2be making NS3_LOGGING_ENABLE control macro expansion and nothing more
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 6821
diff changeset
   349
#define NS_LOG_UNCOND(msg)
f288fc1bb2be making NS3_LOGGING_ENABLE control macro expansion and nothing more
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 6821
diff changeset
   350
f288fc1bb2be making NS3_LOGGING_ENABLE control macro expansion and nothing more
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 6821
diff changeset
   351
#endif /* LOG_ENABLE */
f288fc1bb2be making NS3_LOGGING_ENABLE control macro expansion and nothing more
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 6821
diff changeset
   352
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   353
namespace ns3 {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   354
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   355
/**
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   356
 * \ingroup logging
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   357
 *
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   358
 * Print the list of logging messages available.
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   359
 * 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
   360
 * variable set as NS_LOG=print-list
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   361
 */
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   362
void LogComponentPrintList (void);
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   363
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   364
typedef void (*LogTimePrinter)(std::ostream &os);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7017
diff changeset
   365
typedef void (*LogNodePrinter)(std::ostream &os);
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   366
3005
cc521f35f033 avoid segfault when setting NS_LOG=*
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2986
diff changeset
   367
void LogSetTimePrinter (LogTimePrinter);
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   368
LogTimePrinter LogGetTimePrinter (void);
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   369
5522
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
   370
void LogSetNodePrinter (LogNodePrinter);
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   371
LogNodePrinter LogGetNodePrinter (void);
5522
0d1a06c5b285 Print node context in log messages
Guillaume Seguin <guillaume@segu.in>
parents: 4353
diff changeset
   372
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   373
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   374
class LogComponent {
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   375
public:
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   376
  LogComponent (char const *name);
1783
36472385a1cc NS_LOG parsing changes to address bug 91
Craig Dowell <craigdo@ee.washington.edu>
parents: 1775
diff changeset
   377
  void EnvVarCheck (char const *name);
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   378
  bool IsEnabled (enum LogLevel level) const;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   379
  bool IsNoneEnabled (void) const;
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   380
  void Enable (enum LogLevel level);
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   381
  void Disable (enum LogLevel level);
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   382
  char const *Name (void) const;
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   383
private:
1772
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   384
  int32_t     m_levels;
dd278e20e52e log verbosity changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 1507
diff changeset
   385
  char const *m_name;
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   386
};
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   387
2978
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   388
class ParameterLogger : public std::ostream
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   389
{
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   390
  int m_itemNumber;
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   391
  std::ostream &m_os;
2978
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   392
public:
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   393
  ParameterLogger (std::ostream &os);
2978
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   394
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   395
  template<typename T>
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   396
  ParameterLogger& operator<< (T param)
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   397
  {
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   398
    switch (m_itemNumber)
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   399
      {
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   400
      case 0: // first parameter
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   401
        m_os << param;
2978
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   402
        break;
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   403
      default: // parameter following a previous parameter
2979
3d39dd617b8d add time logging support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2978
diff changeset
   404
        m_os << ", " << param;
2978
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   405
        break;
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   406
      }
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   407
    m_itemNumber++;
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   408
    return *this;
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   409
  }
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   410
};
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   411
1498
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   412
} // namespace ns3
520bc8457799 log rides along for free
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   413
2978
c93e1d0d6916 cleanup to avoid too many #ifdefs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2976
diff changeset
   414
7353
09fccf6195ea bug 1203: Inconsistently named ifndef/define macros in ns-3 headers
Vedran Miletic <rivanvx@gmail.com>
parents: 7256
diff changeset
   415
#endif /* LOG_H */