2 Copyright (C) 2012 Intel Corporation
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 #include "timestamp.h"
31 void debugOut(const string &message);
33 /*! \addtogroup libamb
39 * \brief The DebugOut class represents a class used for outputing debug information
40 * The specified debug level will only be outputed if the debug level is => the debug threshhold
41 * Here's a simple example:
43 * DebugOut::setDebugThreshhold(3);
44 * DebugOut(DebugOut::Warning) << "This is a warning" << std::endl;
45 * DebugOut(3) << "This will only show if the threshhold is 3 or lower." << std::endl;
47 * /// Start logging to a file:
49 * logfile.open("amb.log", ios::out | ios::trunc);
50 * DebugOut::setOutput(logfile)
52 * /// Throw exception on warning or error:
53 * DebugOut::setThrowErr(true);
54 * DebugOut::setThrowWarn(true);
55 * DebugOut(DebugOut::Error) << "This will throw an exception." << std::endl;
58 * DebugOut::setOutput(std::cerr);
59 * DebugOut() << "This will log to stderr." << std::endl;
66 * \brief deprecateMethod prints warning if method is used. Throws if version >= PROJECT_SERIES
67 * \param methodName name of method being deprecated.
68 * \param version version in which this method will no longer function in.
70 void deprecateMethod(const string &methodName, const std::string & version);
78 * \brief Error use when essential functionality is blocked
80 static const int Error;
83 * \brief Warning use when non-essential functionality is bocked, or when workarounds exist.
85 static const int Warning;
87 DebugOut(int debugLevel = 4)
89 mDebugLevel = debugLevel;
91 if(mDebugLevel <= debugThreshhold || mDebugLevel == Error || mDebugLevel == Warning)
95 out<<bufferTime(amb::currentTime())<<" | ";
97 if(mDebugLevel == Error)
99 if(mDebugLevel == Warning)
104 DebugOut(const std::string & toLog, int debugLevel = 4)
105 :DebugOut(debugLevel)
107 (*this) << toLog << endl;
110 DebugOut const& operator << (const string &message) const
112 if(mDebugLevel <= debugThreshhold || mDebugLevel == Error || mDebugLevel == Warning)
121 DebugOut const& operator << (ostream & (*manip)(std::ostream&)) const
123 if(mDebugLevel <= debugThreshhold || mDebugLevel == Error || mDebugLevel == Warning)
129 if((mDebugLevel == Error && throwErr))
131 throw std::runtime_error("Abort on Error is set");
133 else if ((mDebugLevel == Warning && throwWarn))
135 throw std::runtime_error("Abort on Warning is set");
141 DebugOut const & operator << (double val) const
143 if(mDebugLevel <= debugThreshhold || mDebugLevel == Error || mDebugLevel == Warning)
152 static void setDebugThreshhold(int th)
154 debugThreshhold = th;
157 static void setOutput(ostream &o)
162 static void setThrowWarn(bool v)
167 static void setThrowErr(bool v)
172 static const int getDebugThreshhold()
174 return debugThreshhold;
179 std::string bufferTime(double time)
187 while(f.str().length() <= 15)
195 static int debugThreshhold;
196 static std::streambuf *buf;
197 static bool throwWarn;
198 static bool throwErr;