2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-22 05:27:40 +08:00
|
|
|
#include <osg/Notify>
|
2001-01-11 00:32:10 +08:00
|
|
|
#include <string>
|
2004-03-03 21:27:21 +08:00
|
|
|
#include <iostream>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-02-23 01:12:10 +08:00
|
|
|
using namespace std;
|
2002-02-03 19:35:24 +08:00
|
|
|
|
2002-06-12 02:41:57 +08:00
|
|
|
osg::NotifySeverity g_NotifyLevel = osg::NOTICE;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
void osg::setNotifyLevel(osg::NotifySeverity severity)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
osg::initNotifyLevel();
|
|
|
|
g_NotifyLevel = severity;
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
osg::NotifySeverity osg::getNotifyLevel()
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
osg::initNotifyLevel();
|
2001-01-11 00:32:10 +08:00
|
|
|
return g_NotifyLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
bool osg::initNotifyLevel()
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2002-06-12 02:41:57 +08:00
|
|
|
static bool s_NotifyInit = false;
|
2001-10-04 05:44:07 +08:00
|
|
|
|
2002-06-12 02:41:57 +08:00
|
|
|
if (s_NotifyInit) return true;
|
|
|
|
|
|
|
|
s_NotifyInit = true;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
// g_NotifyLevel
|
|
|
|
// =============
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
g_NotifyLevel = osg::NOTICE; // Default value
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-04-24 22:52:53 +08:00
|
|
|
char* OSGNOTIFYLEVEL=getenv("OSG_NOTIFY_LEVEL");
|
|
|
|
if (!OSGNOTIFYLEVEL) OSGNOTIFYLEVEL=getenv("OSGNOTIFYLEVEL");
|
2001-09-20 05:08:56 +08:00
|
|
|
if(OSGNOTIFYLEVEL)
|
|
|
|
{
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
std::string stringOSGNOTIFYLEVEL(OSGNOTIFYLEVEL);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
// Convert to upper case
|
|
|
|
for(std::string::iterator i=stringOSGNOTIFYLEVEL.begin();
|
|
|
|
i!=stringOSGNOTIFYLEVEL.end();
|
|
|
|
++i)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
*i=toupper(*i);
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
if(stringOSGNOTIFYLEVEL.find("ALWAYS")!=std::string::npos) g_NotifyLevel=osg::ALWAYS;
|
|
|
|
else if(stringOSGNOTIFYLEVEL.find("FATAL")!=std::string::npos) g_NotifyLevel=osg::FATAL;
|
|
|
|
else if(stringOSGNOTIFYLEVEL.find("WARN")!=std::string::npos) g_NotifyLevel=osg::WARN;
|
|
|
|
else if(stringOSGNOTIFYLEVEL.find("NOTICE")!=std::string::npos) g_NotifyLevel=osg::NOTICE;
|
|
|
|
else if(stringOSGNOTIFYLEVEL.find("DEBUG_INFO")!=std::string::npos) g_NotifyLevel=osg::DEBUG_INFO;
|
|
|
|
else if(stringOSGNOTIFYLEVEL.find("DEBUG_FP")!=std::string::npos) g_NotifyLevel=osg::DEBUG_FP;
|
|
|
|
else if(stringOSGNOTIFYLEVEL.find("DEBUG")!=std::string::npos) g_NotifyLevel=osg::DEBUG_INFO;
|
2002-08-20 16:14:02 +08:00
|
|
|
else if(stringOSGNOTIFYLEVEL.find("INFO")!=std::string::npos) g_NotifyLevel=osg::INFO;
|
2002-08-20 18:26:36 +08:00
|
|
|
else std::cout << "Warning: invalid OSG_NOTIFY_LEVEL set ("<<stringOSGNOTIFYLEVEL<<")"<<std::endl;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
2002-06-12 02:41:57 +08:00
|
|
|
|
|
|
|
#if defined(WIN32) && !(defined(__CYGWIN__) || defined(__MINGW32__))
|
2002-06-16 04:57:50 +08:00
|
|
|
const char* NullStreamName = "nul";
|
2002-06-12 02:41:57 +08:00
|
|
|
#else
|
2002-06-16 04:57:50 +08:00
|
|
|
const char* NullStreamName = "/dev/null";
|
2002-06-12 02:41:57 +08:00
|
|
|
#endif
|
|
|
|
|
2002-06-16 04:57:50 +08:00
|
|
|
std::ostream& osg::notify(const osg::NotifySeverity severity)
|
|
|
|
{
|
|
|
|
// set up global notify null stream for inline notify
|
|
|
|
static std::ofstream s_NotifyNulStream(NullStreamName);
|
|
|
|
|
|
|
|
static bool initialized = false;
|
|
|
|
if (!initialized)
|
|
|
|
{
|
|
|
|
std::cerr<<""; // dummy op to force construction of cerr, before a reference is passed back to calling code.
|
|
|
|
std::cout<<""; // dummy op to force construction of cout, before a reference is passed back to calling code.
|
|
|
|
initialized = osg::initNotifyLevel();
|
|
|
|
}
|
2002-06-12 02:41:57 +08:00
|
|
|
|
|
|
|
if (severity<=g_NotifyLevel)
|
|
|
|
{
|
|
|
|
if (severity<=osg::WARN) return std::cerr;
|
|
|
|
else return std::cout;
|
|
|
|
}
|
|
|
|
return s_NotifyNulStream;
|
|
|
|
}
|