1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 //#####DESCRIPTIONBEGIN####
30 // Description: Standard include file for test infra
33 //####DESCRIPTIONEND####
35 //=================================================================
36 // This class handles output of errors, debugging trace and so on. All its members are static, so it's really a namespace :-).
37 // It handles two output streams - error and output - and allows these to be redirected independently to files etc...
38 // Part of the justification for this (which might be carried out on the command line) involves shortcomings of
39 // SAMBA client, which deals badly with the flushing of file buffers.
40 // The definition of LogFunc, which defines a function (void *,LPCTSTR) to which output is sent, is in eCosStd.
41 //=================================================================
46 #include "Collections.h"
50 static const String Timestamp();
52 static void Out(LPCTSTR psz) { pfnOut(pOutParam,psz); }
53 static void Err(LPCTSTR psz) { pfnError(pErrorParam,psz); } // Send to "stderr"
54 static void TimeStampedErr(LPCTSTR pszFormat,...);
56 enum TraceLevel {TRACE_LEVEL_ERRORS, TRACE_LEVEL_TRACE, TRACE_LEVEL_VTRACE}; // These are the levels of trace
58 // Here's how to set and get the current trace value:
59 static void EnableTracing(TraceLevel n) { nVerbosity=n; }
60 static TraceLevel TracingEnabled() { return nVerbosity; }
62 static void SetInteractive(bool b) { bInteractive=b; } // Declare this program to be "interactive" (usually means command-line)
63 static bool IsInteractive() { return bInteractive; }
65 static void SetOutput (LogFunc *pFn,void *pParam) { pfnOut=pFn; pOutParam=pParam; } // Make stdout go to this callback
66 static void SetError (LogFunc *pFn,void *pParam) { pfnError=pFn; pErrorParam=pParam; } // Make stderr go to this callback
68 static bool SetOutput (LPCTSTR pszFilename); // Make stdout go to this file
69 static bool SetError (LPCTSTR pszFilename); // Make stderr go to this file
72 #ifndef TRACE // because if running under a debugger we might have a better definition (via OutputDebugString) already
73 // Use this to generate output that will only appear if trace level is at least TRACE_LEVEL_TRACE (turned on by -v)
74 #define TRACE if(CeCosTrace::TracingEnabled()>=CeCosTrace::TRACE_LEVEL_TRACE) CeCosTrace::TimeStampedErr
79 #define ERROR CeCosTrace::TimeStampedErr
80 // Use this to generate output that will only appear if trace level is at least TRACE_LEVEL_VTRACE (turned on by -V)
81 #define VTRACE if(CeCosTrace::TracingEnabled()>=CeCosTrace::TRACE_LEVEL_VTRACE) CeCosTrace::TimeStampedErr
83 // Use this to generate output that will only appear if mode is interactive (see above)
84 #define INTERACTIVE if(CeCosTrace::IsInteractive()||CeCosTrace::TracingEnabled()>=CeCosTrace::TRACE_LEVEL_TRACE) CeCosTrace::TimeStampedErr
86 // Thus log function can be used to direct output to a FILE* (e.g. stdout) passed as the first argument:
87 static void CALLBACK StreamLogFunc (void *, LPCTSTR psz);
90 // Information we need to know for a stream (error or output)
95 StreamInfo(LPCTSTR pszFile,FILE *_f) : tLastReopen(Now()),strFilename(pszFile),f(_f) {}
96 ~StreamInfo() { fclose(f); }
99 // Here are the two streams
100 static StreamInfo OutInfo,ErrInfo;
102 static void CALLBACK StreamInfoFunc (void *, LPCTSTR psz);
104 static LPCTSTR arpszDow[7];
106 static TraceLevel nVerbosity;
107 static bool bInteractive;
108 static LogFunc *pfnOut; static void *pOutParam;
109 static LogFunc *pfnError; static void *pErrorParam;