• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/core/log.h

00001 // Copyright 2009-2010 Sandia Corporation. Under the terms
00002 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
00003 // Government retains certain rights in this software.
00004 // 
00005 // Copyright (c) 2009-2010, Sandia Corporation
00006 // All rights reserved.
00007 // 
00008 // This file is part of the SST software package. For license
00009 // information, see the LICENSE file in the top level directory of the
00010 // distribution.
00011 
00012 
00013 #ifndef _SST_LOG_H
00014 #define _SST_LOG_H
00015 
00016 #include <stdio.h>
00017 #include <cstdarg>
00018 #include <string>
00019 
00020 namespace SST { 
00021 
00022 template < int ENABLE = 1 >
00023 class Log {
00024     public:
00025         Log( std::string prefix = "", bool enable = true ) :
00026             m_prefix( prefix ), m_enabled( enable )
00027         {}
00028     
00029         void enable() {
00030             m_enabled = true;
00031         }
00032         void disable() {
00033             m_enabled = false;
00034         }
00035 
00036         void prepend( std::string str ) {
00037             m_prefix = str + m_prefix; 
00038         }
00039 
00040         inline void write( const std::string fmt, ... )
00041         {
00042             if ( ENABLE ) {
00043 
00044                 if ( ! m_enabled ) return;
00045 
00046                 printf( "%s", m_prefix.c_str() );
00047                 va_list ap;
00048                 va_start( ap,fmt );
00049                 vprintf( fmt.c_str(), ap ); 
00050                 va_end( ap);
00051             }
00052         }
00053 
00054     private:
00055         std::string m_prefix;
00056         bool        m_enabled;
00057 };
00058 } // namespace SST
00059 
00060 #endif

Generated on Fri Oct 22 2010 11:02:13 for SST by  doxygen 1.7.1