rlog: rlog.h Source File

- Main Page
- Modules
- Classes
- Files
- Related Pages

# rlog.h

Go to the documentation of this file.

    00001 /*****************************************************************************
    00002  * Author:   Valient Gough <vgough@pobox.com>
    00003  *
    00004  *****************************************************************************
    00005  * Copyright (c) 2002-2004, Valient Gough
    00006  *
    00007  * This library is free software; you can distribute it and/or modify it under
    00008  * the terms of the GNU Lesser General Public License (LGPL), as published by
    00009  * the Free Software Foundation; either version 2.1 of the License, or (at your
    00010  * option) any later version.
    00011  *
    00012  * This library is distributed in the hope that it will be useful, but WITHOUT
    00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00014  * FITNESS FOR A PARTICULAR PURPOSE.  See the LGPL in the file COPYING for more
    00015  * details.
    00016  *
    00017  */
    00018
    00019
    00020 #ifndef _rlog_incl_
    00021 #define _rlog_incl_
    00022
    00023 #define CONCAT2(A,B) A##B
    00024 #define CONCAT(A,B) CONCAT2(A,B)
    00025 #define STR(X) #X
    00026
    00027 #include <rlog/common.h>
    00028
    00034 // may be useful for checking from configuration files
    00035 #define CURRENT_RLOG_VERSION 20040503
    00036 extern "C" int RLogVersion();
    00037
    00038 namespace rlog
    00039 {
    00040
    00041     class RLogChannel;
    00042     class RLogPublisher;
    00043     class RLogNode;
    00044
    00048     enum LogLevel
    00049     {
    00050         Log_Undef    =0,
    00051         Log_Critical,
    00052         Log_Error,
    00053         Log_Warning,
    00054         Log_Notice,
    00055         Log_Info,
    00056         Log_Debug
    00057     };
    00058
    00069     void RLOG_DECL RLogInit(int &argc, char **argv);
    00070
    00071
    00072     // Get channel with a particular component name
    00073     RLOG_DECL RLogChannel *GetComponentChannel(const char *component,
    00074                                      const char *path,
    00075                                      LogLevel level = Log_Undef);
    00076
    00077     // the global channel receives messages for all components
    00078     RLOG_DECL RLogChannel *GetGlobalChannel( const char *path,
    00079                                    LogLevel level = Log_Undef);
    00080
    00124 #define DEF_CHANNEL(path,level) RLOG_CHANNEL_IMPL(RLOG_COMPONENT, path, level)
    00125 #define RLOG_CHANNEL(path) RLOG_CHANNEL_IMPL(RLOG_COMPONENT, path, rlog::Log_Undef)
    00126 #define RLOG_CHANNEL_IMPL(COMPONENT,path,level) \
    00127     rlog::GetComponentChannel(STR(COMPONENT),path,level)
    00128
    00129     /*
    00130         Pre-defined channels,
    00131         "debug", "warning", and "error".
    00132
    00133         You can of course defined sub-channels based on the predefined types,
    00134         such as "debug/level1", or whatever.
    00135     */
    00136     extern RLOG_DECL RLogChannel *_RLDebugChannel;
    00137     extern RLOG_DECL RLogChannel *_RLInfoChannel;
    00138     extern RLOG_DECL RLogChannel *_RLWarningChannel;
    00139     extern RLOG_DECL RLogChannel *_RLErrorChannel;
    00140
    00153     struct PublishLoc
    00154     {
    00155         // If the compiler supports printf attribute specification on function
    00156         // pointers, we'll use it here so that the compiler knows to check for
    00157         // proper printf formatting.  If it doesn't support it, then we'll
    00158         // force the check by inserting a bogus inline function..
    00160         void (*publish)(PublishLoc *, RLogChannel *, const char *format, ... )
    00161             PRINTF_FP(3,4);
    00162         RLogNode *pub;
    00163         const char *component;
    00164         const char *fileName;
    00165         const char *functionName;
    00166         int lineNum;
    00167         RLogChannel *channel;
    00168     };
    00169
    00176     void RLOG_DECL RLog_Register(PublishLoc *loc, RLogChannel *,
    00177                        const char *format, ... ) PRINTF(3,4);
    00178
    00184     void RLOG_DECL rAssertFailed( const char *component, const char *file,
    00185                         const char *function, int line,
    00186                         const char *conditionStr );
    00187
    00188     // if we don't have printf attributes on function pointers, but we do have
    00189     // printf attributes, then make a bogus check function..
    00190 #if !HAVE_PRINTF_FP && HAVE_PRINTF_ATTR
    00191     void __checkArgs(int, const char *, ... ) PRINTF(2,3);
    00192
    00193     inline void __checkArgs(int, const char *, ...)
    00194     { }
    00195 #endif
    00196 }
    00197
    00198 #if C99_VARIADAC_MACROS
    00199 #include <rlog/rlog-c99.h>
    00200 #elif PREC99_VARIADAC_MACROS
    00201 #include <rlog/rlog-prec99.h>
    00202 #else
    00203 #include <rlog/rlog-novariadic.h>
    00204 #endif
    00205
    00206
    00207 #define _rAssertFailed(COMPONENT, COND) \
    00208     rlog::rAssertFailed(STR(COMPONENT),__FILE__,__FUNCTION__,__LINE__, COND)
    00209
    00220 #define rAssert( cond ) \
    00221     do { \
    00222         if( unlikely((cond) == false) ) \
    00223         { rError( "Assert failed: " STR(cond) ); \
    00224           _rAssertFailed(RLOG_COMPONENT, STR(cond)); \
    00225         } \
    00226     } while(0)
    00227
    00235 #define rAssertSilent( cond ) \
    00236     do { \
    00237         if( unlikely((cond) == false) ) \
    00238         { _rAssertFailed(RLOG_COMPONENT, STR(cond)); } \
    00239     } while(0)
    00240
    00241
    00246 /* @def RLOG_NO_COPY
    00247     @brief Disables class copy constructor and operator =.
    00248
    00249     This macro declares a private copy constructor and assignment operator
    00250     which prevents automatic generation of these operation by the compiler.
    00251
    00252     Attention, it switches access to private, so use it only at the end of the
    00253     class declaration.
    00254     */
    00255 #define RLOG_NO_COPY(CNAME) \
    00256     private: \
    00257         CNAME(const CNAME&); \
    00258         CNAME & operator = (const CNAME &)
    00259
    00260
    00261 #endif // rlog.h
    00262