Back to index

lightning-sunbird  0.9+nobinonly
tracelog.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is lineterm.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Ramalingam Saravanan.
00018  * Portions created by the Initial Developer are Copyright (C) 1999
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 /* tracelog.h: Tracing/logging module header
00038  * CPP options:
00039  *   DEBUG_LTERM:          to enable debugging output
00040  *   _UNISTRING_H:   for unicode messages compatible with "unistring.h"
00041  */
00042 
00043 #ifndef _TRACELOG_H
00044 
00045 #define _TRACELOG_H 1
00046 
00047 #include <stdio.h>
00048 #include <string.h>
00049 
00050 /* Trace/log macros (to be used after call to tlog_init to initialize):
00051  * TLOG_ERROR:   error message macro, e.g.,
00052  *                                          TLOG_ERROR(format, val1, val2);
00053  * TOG_WARNING:  warning message macro, e.g.,
00054  *                                          TLOG_WARNING(format, val1, val2);
00055  * TLOG_PRINT:   message logging macro, e.g., (no terminating semicolon)
00056  *                                         TLOG_PRINT(10,(format, val1, val2));
00057  * (if UNISTRING module is being used)
00058  * TLOG_UNICHAR: Unicode string logging macro, e.g., (no terminating semicolon)
00059  *                                          TLOG_UNICHAR(10,(label,str,count));
00060  */
00061 
00062 /* Max. number of modules recognized by TRACELOG */
00063 # define TLOG_MAXMODULES 50
00064 
00065 #ifdef  __cplusplus
00066 extern "C" {
00067 #endif
00068 
00069 /* Initializes all TRACELOG operations;
00070  * needs to be called before any other trace/log calls.
00071  *
00072  * FILESTREAM is the file stream to be used to print messages.
00073  *
00074  * Normally, only error messages are sent to FILESTREAM.
00075  * If FILESTREAM is null, all output, including error output, is suppressed.
00076  */
00077 
00078 void tlog_init(FILE* fileStream);
00079 
00116 int tlog_set_level(int imodule, int messageLevel, const char *functionList);
00117 
00118 int tlog_test(int imodule, char *procname, int level);
00119 void tlog_message(const char *format, ...);
00120 void tlog_warning(const char *format, ...);
00121 
00122 /* TRACELOG global variables */
00123 typedef struct { 
00124   FILE *errorStream;                     /* file stream for logging */
00125   int debugOn;
00126   int messageLevel[TLOG_MAXMODULES];
00127   char *functionList[TLOG_MAXMODULES];   /* list of functions to be debugged */
00128 } TlogGlobal;
00129 
00130 extern TlogGlobal tlogGlobal;
00131 
00132 #ifdef  __cplusplus
00133 }
00134 #endif
00135 
00136 #if defined(USE_NSPR_BASE) && !defined(DEBUG_LTERM)
00137 #include "prlog.h"
00138 #define TLOG_MESSAGE PR_LogPrint
00139 #else
00140 #define TLOG_MESSAGE tlog_message
00141 #endif
00142 
00143 #define TLOG_ERROR TLOG_MESSAGE
00144 
00145 #define TLOG_WARNING if (tlogGlobal.debugOn) TLOG_MESSAGE
00146 
00147 #define TLOG_PRINT(imodule,procname,level,args) \
00148 do {                                            \
00149   if (tlogGlobal.debugOn && tlog_test(imodule,":" #procname ":",level)) {  \
00150       TLOG_MESSAGE args;                                                  \
00151   }                                             \
00152 } while(0)
00153 
00154 #ifdef _UNISTRING_H
00155 void tlog_unichar(const UNICHAR *buf, int count);
00156 
00157 #define TLOG_UNICHAR(imodule,procname,level,args) \
00158 do {                                              \
00159 if (tlogGlobal.debugOn && tlog_test(imodule,":" #procname ":",level)) {  \
00160     tlog_unichar args;                            \
00161   }                                               \
00162 } while(0)
00163 #endif
00164 
00165 #endif  /* _TRACELOG_H */