Back to index

lightning-sunbird  0.9+nobinonly
ImageLogging.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 2001
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Stuart Parmenter <pavlov@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "prlog.h"
00041 #include "prinrval.h"
00042 
00043 #include "nsString.h"
00044 
00045 #if defined(PR_LOGGING)
00046 extern PRLogModuleInfo *gImgLog;
00047 
00048 #define GIVE_ME_MS_NOW() PR_IntervalToMilliseconds(PR_IntervalNow())
00049 
00050 class LogScope {
00051 public:
00052   LogScope(PRLogModuleInfo *aLog, void *from, const nsACString &fn) :
00053     mLog(aLog), mFrom(from), mFunc(fn)
00054   {
00055     PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s {ENTER}\n",
00056                                    GIVE_ME_MS_NOW(),
00057                                    mFrom, mFunc.get()));
00058   }
00059 
00060   /* const char * constructor */
00061   LogScope(PRLogModuleInfo *aLog, void *from, const nsACString &fn,
00062            const nsDependentCString &paramName, const char *paramValue) :
00063     mLog(aLog), mFrom(from), mFunc(fn)
00064   {
00065     PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%s\") {ENTER}\n",
00066                                    GIVE_ME_MS_NOW(),
00067                                    mFrom, mFunc.get(),
00068                                    paramName.get(),
00069                                    paramValue));
00070   }
00071 
00072   /* void ptr constructor */
00073   LogScope(PRLogModuleInfo *aLog, void *from, const nsACString &fn,
00074            const nsDependentCString &paramName, const void *paramValue) :
00075     mLog(aLog), mFrom(from), mFunc(fn)
00076   {
00077     PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=%p) {ENTER}\n",
00078                                    GIVE_ME_MS_NOW(),
00079                                    mFrom, mFunc.get(),
00080                                    paramName.get(),
00081                                    paramValue));
00082   }
00083 
00084   /* PRInt32 constructor */
00085   LogScope(PRLogModuleInfo *aLog, void *from, const nsACString &fn,
00086            const nsDependentCString &paramName, PRInt32 paramValue) :
00087     mLog(aLog), mFrom(from), mFunc(fn)
00088   {
00089     PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n",
00090                                    GIVE_ME_MS_NOW(),
00091                                    mFrom, mFunc.get(),
00092                                    paramName.get(),
00093                                    paramValue));
00094   }
00095 
00096   /* PRUint32 constructor */
00097   LogScope(PRLogModuleInfo *aLog, void *from, const nsACString &fn,
00098            const nsDependentCString &paramName, PRUint32 paramValue) :
00099     mLog(aLog), mFrom(from), mFunc(fn)
00100   {
00101     PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%d\") {ENTER}\n",
00102                                    GIVE_ME_MS_NOW(),
00103                                    mFrom, mFunc.get(),
00104                                    paramName.get(),
00105                                    paramValue));
00106   }
00107 
00108 
00109   ~LogScope() {
00110     PR_LOG(mLog, PR_LOG_DEBUG, ("%d [this=%p] %s {EXIT}\n",
00111                                    GIVE_ME_MS_NOW(),
00112                                    mFrom, mFunc.get()));
00113   }
00114 
00115 private:
00116   PRLogModuleInfo *mLog;
00117   void *mFrom;
00118   nsCAutoString mFunc;
00119 };
00120 
00121 
00122 class LogFunc {
00123 public:
00124   LogFunc(PRLogModuleInfo *aLog, void *from, const nsDependentCString &fn)
00125   {
00126     PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s\n",
00127                                 GIVE_ME_MS_NOW(), from,
00128                                 fn.get()));
00129   }
00130 
00131   LogFunc(PRLogModuleInfo *aLog, void *from, const nsDependentCString &fn,
00132           const nsDependentCString &paramName, const char *paramValue)
00133   {
00134     PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%s\")\n",
00135                                 GIVE_ME_MS_NOW(), from,
00136                                 fn.get(),
00137                                 paramName.get(), paramValue));
00138   }
00139 
00140   LogFunc(PRLogModuleInfo *aLog, void *from, const nsDependentCString &fn,
00141           const nsDependentCString &paramName, const void *paramValue)
00142   {
00143     PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%p\")\n",
00144                                 GIVE_ME_MS_NOW(), from,
00145                                 fn.get(),
00146                                 paramName.get(), paramValue));
00147   }
00148 
00149 
00150   LogFunc(PRLogModuleInfo *aLog, void *from, const nsDependentCString &fn,
00151           const nsDependentCString &paramName, PRUint32 paramValue)
00152   {
00153     PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s (%s=\"%d\")\n",
00154                                 GIVE_ME_MS_NOW(), from,
00155                                 fn.get(),
00156                                 paramName.get(), paramValue));
00157   }
00158 
00159 };
00160 
00161 
00162 class LogMessage {
00163 public:
00164   LogMessage(PRLogModuleInfo *aLog, void *from, const nsDependentCString &fn,
00165              const nsDependentCString &msg)
00166   {
00167     PR_LOG(aLog, PR_LOG_DEBUG, ("%d [this=%p] %s -- %s\n",
00168                                 GIVE_ME_MS_NOW(), from,
00169                                 fn.get(),
00170                                 msg.get()));
00171   }
00172 };
00173 
00174 #define LOG_SCOPE(l, s) \
00175   LogScope LOG_SCOPE_TMP_VAR ##__LINE__ (l,                            \
00176                                          NS_STATIC_CAST(void *, this), \
00177                                          NS_LITERAL_CSTRING(s))
00178 
00179 #define LOG_SCOPE_WITH_PARAM(l, s, pn, pv) \
00180   LogScope LOG_SCOPE_TMP_VAR ##__LINE__ (l,                            \
00181                                          NS_STATIC_CAST(void *, this), \
00182                                          NS_LITERAL_CSTRING(s),        \
00183                                          NS_LITERAL_CSTRING(pn), pv)
00184 
00185 #define LOG_FUNC(l, s)                  \
00186   LogFunc(l,                            \
00187           NS_STATIC_CAST(void *, this), \
00188           NS_LITERAL_CSTRING(s))
00189 
00190 #define LOG_FUNC_WITH_PARAM(l, s, pn, pv) \
00191   LogFunc(l,                              \
00192           NS_STATIC_CAST(void *, this),   \
00193           NS_LITERAL_CSTRING(s),          \
00194           NS_LITERAL_CSTRING(pn), pv)
00195 
00196 #define LOG_STATIC_FUNC(l, s)           \
00197   LogFunc(l,                            \
00198           nsnull,                       \
00199           NS_LITERAL_CSTRING(s))
00200 
00201 #define LOG_STATIC_FUNC_WITH_PARAM(l, s, pn, pv) \
00202   LogFunc(l,                             \
00203           nsnull,                        \
00204           NS_LITERAL_CSTRING(s),         \
00205           NS_LITERAL_CSTRING(pn), pv)
00206 
00207 
00208 
00209 #define LOG_MSG(l, s, m)                   \
00210   LogMessage(l,                            \
00211              NS_STATIC_CAST(void *, this), \
00212              NS_LITERAL_CSTRING(s),        \
00213              NS_LITERAL_CSTRING(m))
00214 
00215 
00216 #else
00217 #define LOG_SCOPE(l, s)
00218 #define LOG_SCOPE_WITH_PARAM(l, s, pn, pv)
00219 #define LOG_FUNC(l, s)
00220 #define LOG_FUNC_WITH_PARAM(l, s, pn, pv)
00221 #define LOG_STATIC_FUNC(l, s)
00222 #define LOG_STATIC_FUNC_WITH_PARAM(l, s, pn, pv)
00223 #define LOG_MSG(l, s, m)
00224 #endif
00225 
00226 #define LOG_MSG_WITH_PARAM LOG_FUNC_WITH_PARAM