Logging.h

00001 /*
00002  *  Phusion Passenger - http://www.modrails.com/
00003  *  Copyright (C) 2008  Phusion
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; version 2 of the License.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License along
00015  *  with this program; if not, write to the Free Software Foundation, Inc.,
00016  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00017  */
00018 #ifndef _PASSENGER_LOGGING_H_
00019 #define _PASSENGER_LOGGING_H_
00020 
00021 #include <sys/types.h>
00022 #include <unistd.h>
00023 #include <ostream>
00024 
00025 namespace Passenger {
00026 
00027 using namespace std;
00028 
00029 extern int _debugLevel;
00030 extern ostream *_logStream;
00031 extern ostream *_debugStream;
00032 
00033 void setDebugFile(const char *logFile = NULL);
00034 
00035 /**
00036  * Write the given expression to the log stream.
00037  */
00038 #define P_LOG(expr) \
00039         do { \
00040                 if (Passenger::_logStream != 0) { \
00041                         *Passenger::_logStream << \
00042                                 "[" << getpid() << ":" << __FILE__ << ":" << __LINE__ << "] " << \
00043                                 expr << std::endl; \
00044                 } \
00045         } while (false)
00046 
00047 /**
00048  * Write the given expression, which represents a warning,
00049  * to the log stream.
00050  */
00051 #define P_WARN(expr) P_LOG(expr)
00052 
00053 /**
00054  * Write the given expression, which represents an error,
00055  * to the log stream.
00056  */
00057 #define P_ERROR(expr) P_LOG(expr)
00058 
00059 /**
00060  * Write the given expression, which represents a debugging message,
00061  * to the log stream.
00062  */
00063 #define P_DEBUG(expr) P_TRACE(1, expr)
00064 
00065 #ifdef PASSENGER_DEBUG
00066         #define P_TRACE(level, expr) \
00067                 do { \
00068                         if (Passenger::_debugLevel >= level) { \
00069                                 if (Passenger::_debugStream != 0) { \
00070                                         *Passenger::_debugStream << \
00071                                                 "[" << getpid() << ":" << __FILE__ << ":" << __LINE__ << "] " << \
00072                                                 expr << std::endl; \
00073                                 } \
00074                         } \
00075                 } while (false)
00076 #else
00077         #define P_TRACE(level, expr) do { /* nothing */ } while (false)
00078 #endif
00079 
00080 } // namespace Passenger
00081 
00082 #endif /* _PASSENGER_LOGGING_H_ */
00083 

Generated on Fri Apr 11 18:16:04 2008 for Passenger by  doxygen 1.5.3