frontierdebug.c

Go to the documentation of this file.
00001 
00002 /*  $Id: frontierdebug.c 1209 2006-04-05 23:59:59Z karstenw $    */
00003 
00004 /******************************************************************************
00005 
00006     UserLand Frontier(tm) -- High performance Web content management,
00007     object database, system-level and Internet scripting environment,
00008     including source code editing and debugging.
00009 
00010     Copyright (C) 1992-2004 UserLand Software, Inc.
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 ******************************************************************************/
00027 
00028 #include "frontier.h"
00029 #include "standard.h"
00030 
00031 #include "about.h"
00032 #include "frontierdebug.h"
00033 #include "process.h"
00034 #include "processinternal.h"
00035 #include "strings.h"
00036 
00037 
00038 static const char debuglogname[] = "frontierdebuglog.txt";
00039 
00040 static FILE * logfile = nil;
00041 
00042 static boolean flreentering = false;
00043 
00044 
00045 /* compiler messages for GENERAL category */
00046 
00047 #if (LAND_GENERALLOG_LEVEL >= LAND_LOGLEVEL_3)
00048     #pragma message ("*********************** GENERAL LOG: Level 3")
00049 #elif (LAND_GENERALLOG_LEVEL >= LAND_LOGLEVEL_2)
00050     #pragma message ("*********************** GENERAL LOG: Level 2")
00051 #elif (LAND_GENERALLOG_LEVEL >= LAND_LOGLEVEL_1)
00052     #pragma message ("*********************** GENERAL LOG: Level 1")
00053 /*
00054 #else
00055     #pragma message ("*********************** GENERAL LOG: --OFF--")
00056 */
00057 #endif
00058 
00059 #if (LAND_GENERALLOG_LEVEL > LAND_LOGLEVEL_OFF)
00060     #if (LAND_GENERALLOG_TARGET & LAND_LOGTARGET_FILE)
00061         #pragma message ("*********************** GENERAL LOG: output to FILE")
00062     #endif
00063     #if (LAND_GENERALLOG_TARGET & LAND_LOGTARGET_ABOUT)
00064         #pragma message ("*********************** GENERAL LOG: output to ABOUT WINDOW")
00065     #endif
00066     #if (LAND_GENERALLOG_TARGET & LAND_LOGTARGET_DIALOG)
00067         #pragma message ("*********************** GENERAL LOG: output to DIALOG")
00068     #endif
00069     #if (LAND_GENERALLOG_TARGET & LAND_LOGTARGET_DEBUGGER)
00070         #pragma message ("*********************** GENERAL LOG: output to DEBUGGER")
00071     #endif
00072 #endif
00073 
00074 
00075 /* compiler messages for TCP category */
00076 
00077 #if (LAND_TCPLOG_LEVEL >= LAND_LOGLEVEL_3)
00078     #pragma message ("*********************** TCP LOG: Level 3")
00079 #elif (LAND_TCPLOG_LEVEL >= LAND_LOGLEVEL_2)
00080     #pragma message ("*********************** TCP LOG: Level 2")
00081 #elif (LAND_TCPLOG_LEVEL >= LAND_LOGLEVEL_1)
00082     #pragma message ("*********************** TCP LOG: Level 1")
00083 /*
00084 #else
00085     #pragma message ("*********************** TCP LOG: --OFF--")
00086 */
00087 #endif
00088 
00089 #if (LAND_TCPLOG_LEVEL > LAND_LOGLEVEL_OFF)
00090     #if (LAND_TCPLOG_TARGET & LAND_LOGTARGET_FILE)
00091         #pragma message ("*********************** TCP LOG: output to FILE")
00092     #endif
00093     #if (LAND_TCPLOG_TARGET & LAND_LOGTARGET_ABOUT)
00094         #pragma message ("*********************** TCP LOG: output to ABOUT WINDOW")
00095     #endif
00096     #if (LAND_TCPLOG_TARGET & LAND_LOGTARGET_DIALOG)
00097         #pragma message ("*********************** TCP LOG: output to DIALOG")
00098     #endif
00099     #if (LAND_TCPLOG_TARGET & LAND_LOGTARGET_DEBUGGER)
00100         #pragma message ("*********************** TCP LOG: output to DEBUGGER")
00101     #endif
00102 #endif
00103 
00104 
00105 /* compiler messages for DB category */
00106 
00107 #if (LAND_DBLOG_LEVEL >= LAND_LOGLEVEL_3)
00108     #pragma message ("*********************** DB LOG: Level 3")
00109 #elif (LAND_DBLOG_LEVEL >= LAND_LOGLEVEL_2)
00110     #pragma message ("*********************** DB LOG: Level 2")
00111 #elif (LAND_DBLOG_LEVEL >= LAND_LOGLEVEL_1)
00112     #pragma message ("*********************** DB LOG: Level 1")
00113 /*
00114 #else
00115     #pragma message ("*********************** DB LOG: --OFF--")
00116 */
00117 #endif
00118 
00119 #if (LAND_DBLOG_LEVEL > LAND_LOGLEVEL_OFF)
00120     #if (LAND_DBLOG_TARGET & LAND_LOGTARGET_FILE)
00121         #pragma message ("*********************** DB LOG: output to FILE")
00122     #endif
00123     #if (LAND_DBLOG_TARGET & LAND_LOGTARGET_ABOUT)
00124         #pragma message ("*********************** DB LOG: output to ABOUT WINDOW")
00125     #endif
00126     #if (LAND_DBLOG_TARGET & LAND_LOGTARGET_DIALOG)
00127         #pragma message ("*********************** DB LOG: output to DIALOG")
00128     #endif
00129     #if (LAND_DBLOG_TARGET & LAND_LOGTARGET_DEBUGGER)
00130         #pragma message ("*********************** DB LOG: output to DEBUGGER")
00131     #endif
00132 #endif
00133 
00134 
00135 /* compiler messages for THREADS category */
00136 
00137 #if (LAND_THREADSLOG_LEVEL >= LAND_LOGLEVEL_3)
00138     #pragma message ("*********************** THREADS LOG: Level 3")
00139 #elif (LAND_THREADSLOG_LEVEL >= LAND_LOGLEVEL_2)
00140     #pragma message ("*********************** THREADS LOG: Level 2")
00141 #elif (LAND_THREADSLOG_LEVEL >= LAND_LOGLEVEL_1)
00142     #pragma message ("*********************** THREADS LOG: Level 1")
00143 /*
00144 #else
00145     #pragma message ("*********************** THREADS LOG: --OFF--")
00146 */
00147 #endif
00148 
00149 #if (LAND_THREADSLOG_LEVEL > LAND_LOGLEVEL_OFF)
00150     #if (LAND_THREADSLOG_TARGET & LAND_LOGTARGET_FILE)
00151         #pragma message ("*********************** THREADS LOG: output to FILE")
00152     #endif
00153     #if (LAND_THREADSLOG_TARGET & LAND_LOGTARGET_ABOUT)
00154         #pragma message ("*********************** THREADS LOG: output to ABOUT WINDOW")
00155     #endif
00156     #if (LAND_THREADSLOG_TARGET & LAND_LOGTARGET_DIALOG)
00157         #pragma message ("*********************** THREADS LOG: output to DIALOG")
00158     #endif
00159     #if (LAND_THREADSLOG_TARGET & LAND_LOGTARGET_DEBUGGER)
00160         #pragma message ("*********************** THREADS LOG: output to DEBUGGER")
00161     #endif
00162 #endif
00163 
00164 
00165 /* functions */
00166 
00167 #ifdef WIN95VERSION
00168     extern DWORD ixthreadglobalsgrabcount;
00169 #endif
00170 
00171 static void logtofile (char *str, char *category) {
00172 
00173     unsigned long ticks = gettickcount ();
00174     static unsigned long lastticks = 0;
00175     #ifdef WIN95VERSION
00176         DWORD idthread = GetCurrentThreadId();
00177         static DWORD idlastthread = 0;
00178         long grabcount = (long) TlsGetValue (ixthreadglobalsgrabcount);
00179     #endif
00180     #ifdef MACVERSION
00181         long idthread = (long) (**getcurrentthread ()).idthread;
00182         static long idlastthread = 0;
00183     #endif
00184 
00185     if (logfile == NULL) {
00186         logfile = fopen (debuglogname, "a");
00187         }
00188 
00189     if (idthread != idlastthread) {
00190         fprintf (logfile, "\n");
00191         idlastthread = idthread;
00192         }
00193 
00194     #ifdef WIN95VERSION
00195         fprintf (logfile, "%08X (%04ld) | %04X (%02ld) | %s | &s\n", (unsigned long) ticks, (ticks - lastticks), idthread, grabcount, category, str);
00196     #endif
00197 
00198     #ifdef MACVERSION
00199         fprintf (logfile, "%08lX (%04ld) | %08lX | %s | %s\n", (unsigned long) ticks, (ticks - lastticks), idthread, category, str);
00200     #endif
00201 
00202     lastticks = ticks;
00203 
00204     fflush (logfile);
00205     }/*logtofile*/
00206 
00207 
00208 static void logtoaboutwindow (char *str) {
00209 
00210     bigstring bs;
00211     
00212     copyctopstring (str, bs);
00213 
00214     aboutsetmiscstring (bs);
00215     }/*logtoaboutwindow*/
00216 
00217 
00218 static void logtodialog (char *str) {
00219 #pragma unused(str)
00220 
00221     }/*logtodialog*/
00222 
00223 
00224 static void logtodebugger (char *str) {
00225 
00226     bigstring bs;
00227     
00228     copyctopstring (str, bs);
00229     
00230     DebugStr (bs);
00231     }/*logtodebugger*/
00232 
00233 
00234 static void logtotargets (char *str, long targetflags, char *category) {
00235 
00236     if (flreentering)
00237         return;
00238     
00239     flreentering = true;
00240             
00241     if (targetflags & LAND_LOGTARGET_FILE)
00242         logtofile (str, category);
00243 
00244     if (targetflags & LAND_LOGTARGET_ABOUT)
00245         logtoaboutwindow (str);
00246         
00247     if (targetflags & LAND_LOGTARGET_DIALOG)
00248         logtodialog (str);
00249         
00250     if (targetflags & LAND_LOGTARGET_DEBUGGER)
00251         logtodebugger (str);
00252     
00253     flreentering = false;
00254     }/*logtotargets*/
00255 
00256 
00257 void logmessage (char *msg, char *file, long line, long targetflags, char *category) {
00258     
00259     char str[400];
00260     
00261     str[0] = 0;
00262     
00263     sprintf (str, "%s [%s,%ld]", msg, file, line);
00264     
00265     logtotargets (str, targetflags, category);
00266     }/*logmessage*/
00267     
00268 
00269 long logassert (char *expr, char *file, long line, long targetflags, char *category) {
00270     
00271     char str[400];
00272     
00273     str[0] = 0;
00274     
00275     sprintf (str, "Assertion failed: %s [%s,%ld]", expr, file, line);
00276     
00277     logtotargets (str, targetflags, category);
00278     
00279     return (0);
00280     }/*logassert*/
00281 
00282 
00283 void logstartup () {
00284 
00285     /*perhaps get location of app here, so we can more precisely place our log file*/
00286 
00287     }/*logstartup*/
00288 
00289 
00290 void logshutdown () {
00291 
00292     if (logfile != NULL)
00293         fclose (logfile);
00294     }/*DBTRACKERCLOSE*/
00295 
00296 
00297 
00298 
00299 

Generated on Wed May 31 18:19:47 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6