(file) Return to Logger.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 karl  1.20 //%2005////////////////////////////////////////////////////////////////////////
  2 mike  1.8  //
  3 karl  1.18 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.17 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.18 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.20 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 mike  1.8  //
 12            // Permission is hereby granted, free of charge, to any person obtaining a copy
 13 kumpf 1.10 // of this software and associated documentation files (the "Software"), to
 14            // deal in the Software without restriction, including without limitation the
 15            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16 mike  1.8  // sell copies of the Software, and to permit persons to whom the Software is
 17            // furnished to do so, subject to the following conditions:
 18            // 
 19 kumpf 1.10 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20 mike  1.8  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22 kumpf 1.10 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25 mike  1.8  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27            //
 28            //==============================================================================
 29            //
 30            // Author: Mike Brasher (mbrasher@bmc.com)
 31            //
 32 david 1.12 // Modified By: Dave Rosckes (rosckes@us.ibm.com)
 33 mike  1.8  //
 34            //%/////////////////////////////////////////////////////////////////////////////
 35            
 36            #ifndef Pegasus_Logger_h
 37            #define Pegasus_Logger_h
 38            
 39            #include <Pegasus/Common/Config.h>
 40            #include <Pegasus/Common/Formatter.h>
 41 kumpf 1.11 #include <Pegasus/Common/Linkage.h>
 42 david 1.14 #include <Pegasus/Common/System.h>
 43 mike  1.21 #include <Pegasus/Common/MessageLoader.h>
 44            
 45            #define PEG_LOGGER_TRACE(ARGS_LIST) \
 46                do \
 47                { \
 48                    if (Logger::wouldLog(Logger::TRACE)) \
 49                    { \
 50                        Logger::trace ARGS_LIST ; \
 51                    } \
 52                } \
 53                while (0)
 54 mike  1.8  
 55            PEGASUS_NAMESPACE_BEGIN
 56            
 57            class LoggerRep;
 58            
 59 mike  1.21 /** This class provides the interface for writing log records to the log.
 60 mike  1.8  */
 61            class PEGASUS_COMMON_LINKAGE Logger
 62            {
 63            public:
 64            
 65                enum LogFileType 
 66 mike  1.21     {
 67                    TRACE_LOG, 
 68                    STANDARD_LOG, 
 69                    ERROR_LOG,
 70                    DEBUG_LOG
 71 mike  1.8      };
 72 mike  1.21 
 73 mike  1.8      enum { NUM_LOGS = 4 };
 74                  
 75 mike  1.21     /** Log file Level - Defines the loglevel of the log entry irrespective of 
 76                    which log file it goes into. This is actually a bit mask as defined in 
 77                    logger.cpp. Thus, it serves both as a level of indication of the 
 78                    seriousness and possibly as a mask to select what is logged. 
 79 mike  1.8          ATTN: The selection test has not been done.
 80                */
 81                static const Uint32 TRACE;
 82                static const Uint32 INFORMATION;
 83                static const Uint32 WARNING;
 84                static const Uint32 SEVERE;
 85                static const Uint32 FATAL;
 86            
 87 mike  1.21     /** Puts a message to the defined log file
 88                    @param logFileType - Type of log file (Trace, etc.)
 89                    @param systemId  - ID of the system generating the log entry within 
 90                    Pegasus. This is user defined but generally breaks down into major
 91                    Pegasus components.
 92                    @param level logLevel of the log entry. To be used both t0
 93                    mark the log entry and tested against a mask to determine if log 
 94                    entry should be written.
 95                    @param formatString     Format definition string for the Log. See the 
 96                    Formatter for details.
 97                    @param Arg0 - Arg 9 - Up to 9 arguments representing the variables
 98                    that go into the log entry.
 99                    <pre>
100                    Logger::put(Logger::TRACE_LOG, "CIMServer", Logger::WARNING,
101                        "X=$0, Y=$1, Z=$2", 88,  "Hello World", 7.5);
102                    </pre>
103                */
104                static void put(
105                    LogFileType logFileType,
106                    const String& systemId,
107                    Uint32 logLevel,
108 mike  1.21         const String& formatString,
109                    const Formatter::Arg& arg0,
110                    const Formatter::Arg& arg1,
111                    const Formatter::Arg& arg2,
112                    const Formatter::Arg& arg3,
113                    const Formatter::Arg& arg4 = Formatter::DEFAULT_ARG,
114                    const Formatter::Arg& arg5 = Formatter::DEFAULT_ARG,
115                    const Formatter::Arg& arg6 = Formatter::DEFAULT_ARG,
116                    const Formatter::Arg& arg7 = Formatter::DEFAULT_ARG,
117                    const Formatter::Arg& arg8 = Formatter::DEFAULT_ARG,
118                    const Formatter::Arg& arg9 = Formatter::DEFAULT_ARG);
119            
120                /** Optimized zero-argument form of put().
121                */
122                static void put(
123                    LogFileType logFileType,
124                    const String& systemId,
125                    Uint32 logLevel,
126                    const String& formatString);
127 david 1.12 
128 mike  1.21     /** Optimized one-argument form of put().
129 mike  1.8      */
130                static void put(
131 mike  1.21         LogFileType logFileType,
132                    const String& systemId,
133                    Uint32 logLevel,
134                    const String& formatString,
135                    const Formatter::Arg& arg0);
136 karl  1.19 
137 mike  1.21     /** Optimized two-argument form of put().
138                */
139 karl  1.19     static void put(
140 mike  1.21         LogFileType logFileType,
141                    const String& systemId,
142                    Uint32 logLevel,
143                    const String& formatString,
144                    const Formatter::Arg& arg0,
145                    const Formatter::Arg& arg1);
146 karl  1.19 
147 mike  1.21     /** Optimized three-argument form of put().
148                */
149 karl  1.19     static void put(
150 mike  1.21         LogFileType logFileType,
151                    const String& systemId,
152                    Uint32 logLevel,
153                    const String& formatString,
154                    const Formatter::Arg& arg0,
155                    const Formatter::Arg& arg1,
156                    const Formatter::Arg& arg2);
157 david 1.12 
158 chuck 1.16 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
159 mike  1.21 
160 chuck 1.15     /** put_l - Puts a localized message to the defined log file
161 mike  1.21         @param logFileType - Type of log file (Trace, etc.)
162                    @param systemId  - ID of the system generating the log entry within 
163                    Pegasus. This is user defined but generally breaks down into major
164                    Pegasus components.
165                    @param level logLevel of the log entry. To be used both t0
166                    mark the log entry and tested against a mask to determine if log 
167                    entry should be written.
168                    @param messageId Message ID of the format string to load from 
169                    the resource bundle. 
170                    @param formatString     Default format definition string. See the 
171                    Formatter for details.  This will be used as the default format string
172                    in case the resource bundle cannot be found.
173                    @param Arg0 - Arg 9 - Up to 9 arguments representing the variables
174                    that go into the log entry.
175                    <pre>
176                    Logger::put(Logger::TRACE_LOG, "CIMServer", Logger::WARNING,
177                        "X=$0, Y=$1, Z=$2", 88,  "Hello World", 7.5);
178                    </pre>
179 chuck 1.15     */
180                static void put_l(
181 mike  1.21         LogFileType logFileType,
182                    const String& systemId,
183                    Uint32 logLevel,
184                    const String& messageId,                    
185                    const String& formatString,
186                    const Formatter::Arg& arg0,
187                    const Formatter::Arg& arg1,
188                    const Formatter::Arg& arg2,
189                    const Formatter::Arg& arg3,
190                    const Formatter::Arg& arg4 = Formatter::DEFAULT_ARG,
191                    const Formatter::Arg& arg5 = Formatter::DEFAULT_ARG,
192                    const Formatter::Arg& arg6 = Formatter::DEFAULT_ARG,
193                    const Formatter::Arg& arg7 = Formatter::DEFAULT_ARG,
194                    const Formatter::Arg& arg8 = Formatter::DEFAULT_ARG,
195                    const Formatter::Arg& arg9 = Formatter::DEFAULT_ARG);
196 karl  1.19 
197 mike  1.21     /** Optimized zero-argument form of put_l().
198                */
199                static void put_l(
200                    LogFileType logFileType,
201                    const String& systemId,
202                    Uint32 logLevel,
203                    const String& messageId,                    
204                    const String& formatString);
205            
206                /** Optimized one-argument form of put_l().
207                */
208                static void put_l(
209                    LogFileType logFileType,
210                    const String& systemId,
211                    Uint32 logLevel,
212                    const String& messageId,                    
213                    const String& formatString,
214                    const Formatter::Arg& arg0);
215            
216                /** Optimized two-argument form of put_l().
217                */
218 karl  1.19     static void put_l(
219 mike  1.21         LogFileType logFileType,
220                    const String& systemId,
221                    Uint32 logLevel,
222                    const String& messageId,                    
223                    const String& formatString,
224                    const Formatter::Arg& arg0,
225                    const Formatter::Arg& arg1);
226 karl  1.19 
227 mike  1.21     /** Optimized three-argument form of put_l().
228                */
229 karl  1.19     static void put_l(
230 mike  1.21         LogFileType logFileType,
231                    const String& systemId,
232                    Uint32 logLevel,
233                    const String& messageId,                    
234                    const String& formatString,
235                    const Formatter::Arg& arg0,
236                    const Formatter::Arg& arg1,
237                    const Formatter::Arg& arg2);
238 chuck 1.15 
239 mike  1.21 #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
240 chuck 1.15 
241 mike  1.21     /** Puts a message to the define log. Should only be used for trace type 
242                    logs.
243                */
244 david 1.12     static void trace(
245 mike  1.21         LogFileType logFileType,
246                    const String& systemId,
247                    const Uint32 logComponent,
248                    const String& formatString,
249                    const Formatter::Arg& arg0,
250                    const Formatter::Arg& arg1,
251                    const Formatter::Arg& arg2,
252                    const Formatter::Arg& arg3,
253                    const Formatter::Arg& arg4 = Formatter::DEFAULT_ARG,
254                    const Formatter::Arg& arg5 = Formatter::DEFAULT_ARG,
255                    const Formatter::Arg& arg6 = Formatter::DEFAULT_ARG,
256                    const Formatter::Arg& arg7 = Formatter::DEFAULT_ARG,
257                    const Formatter::Arg& arg8 = Formatter::DEFAULT_ARG,
258                    const Formatter::Arg& arg9 = Formatter::DEFAULT_ARG); 
259            
260                /** Optimized three-argument form of trace().
261                */
262                static void trace(
263                    LogFileType logFileType,
264                    const String& systemId,
265                    const Uint32 logComponent,
266 mike  1.21         const String& formatString);
267            
268                /** Optimized one-argument form of trace().
269                */
270                static void trace(
271                    LogFileType logFileType,
272                    const String& systemId,
273                    const Uint32 logComponent,
274                    const String& formatString,
275                    const Formatter::Arg& arg0);
276            
277                /** Optimized two-argument form of trace().
278                */
279                static void trace(
280                    LogFileType logFileType,
281                    const String& systemId,
282                    const Uint32 logComponent,
283                    const String& formatString,
284                    const Formatter::Arg& arg0,
285                    const Formatter::Arg& arg1);
286            
287 mike  1.21     /** Optimized three-argument form of trace().
288                */
289                static void trace(
290                    LogFileType logFileType,
291                    const String& systemId,
292                    const Uint32 logComponent,
293                    const String& formatString,
294                    const Formatter::Arg& arg0,
295                    const Formatter::Arg& arg1,
296                    const Formatter::Arg& arg2);
297 chuck 1.15 
298 chuck 1.16 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
299 mike  1.21 
300                /** Puts a localized message to the log. Should only be used
301                    for trace type logs.
302                */
303 chuck 1.15     static void trace_l(
304 mike  1.21         LogFileType logFileType,
305                    const String& systemId,
306                    const Uint32 logComponent,
307                    const String& messageId,                       
308                    const String& formatString,
309                    const Formatter::Arg& arg0,
310                    const Formatter::Arg& arg1,
311                    const Formatter::Arg& arg2,
312                    const Formatter::Arg& arg3,
313                    const Formatter::Arg& arg4 = Formatter::DEFAULT_ARG,
314                    const Formatter::Arg& arg5 = Formatter::DEFAULT_ARG,
315                    const Formatter::Arg& arg6 = Formatter::DEFAULT_ARG,
316                    const Formatter::Arg& arg7 = Formatter::DEFAULT_ARG,
317                    const Formatter::Arg& arg8 = Formatter::DEFAULT_ARG,
318                    const Formatter::Arg& arg9 = Formatter::DEFAULT_ARG);
319 chuck 1.15 
320 mike  1.21     /** Optimized zero-argument form of trace_l().
321                */
322                static void trace_l(
323                    LogFileType logFileType,
324                    const String& systemId,
325                    const Uint32 logComponent,
326                    const String& messageId,                       
327                    const String& formatString);
328            
329                /** Optimized one-argument form of trace_l().
330                */
331                static void trace_l(
332                    LogFileType logFileType,
333                    const String& systemId,
334                    const Uint32 logComponent,
335                    const String& messageId,                       
336                    const String& formatString,
337                    const Formatter::Arg& arg0);
338            
339                /** Optimized two-argument form of trace_l().
340                */
341 mike  1.21     static void trace_l(
342                    LogFileType logFileType,
343                    const String& systemId,
344                    const Uint32 logComponent,
345                    const String& messageId,                       
346                    const String& formatString,
347                    const Formatter::Arg& arg0,
348                    const Formatter::Arg& arg1);
349            
350                /** Optimized three-argument form of trace_l().
351                */
352                static void trace_l(
353                    LogFileType logFileType,
354                    const String& systemId,
355                    const Uint32 logComponent,
356                    const String& messageId,                       
357                    const String& formatString,
358                    const Formatter::Arg& arg0,
359                    const Formatter::Arg& arg1,
360                    const Formatter::Arg& arg2);
361            
362 mike  1.21 #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
363 chuck 1.15 
364 mike  1.8      /** setHomeDirectory
365                */
366                static void setHomeDirectory(const String& homeDirectory);
367            
368 david 1.12     /** setlogLevelMask
369 mike  1.8      */
370 david 1.12     static void setlogLevelMask(const String logLevelList);
371 mike  1.8  
372                /** setLogWriteControlMask
373                */
374                static void setLogWriteControlMask(const Uint32);
375            
376 mike  1.21     /** Returns true if the given string is one of the legal log levels.
377                */
378 david 1.12     static Boolean isValidlogLevel(const String logLevel);
379 mike  1.21 
380                /** Tests if a log entry would be created by this call before
381                    the logger is called.  This function is intended to be used
382                    within the server for high usage log entries to avoid the
383                    overhead of doing the call when no log is created.
384                    @param logLevel Uint32 defining the level of the log to be
385                    executed.
386                    <p><b>Example:</b>
387                    <pre>
388                    if (Logger::wouldLog(Logger::TRACE))
389                    {
390                        Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, 
391                            Logger::TRACE, "HTTPMessage - HTTP header name: $0  "
392                            "HTTP header value: $1" ,name,value);
393                    }
394                    </pre>
395                */
396                static bool wouldLog(Uint32 logLevel)
397                {
398                    return _severityMask & logLevel;
399                }
400 mike  1.21 
401 mike  1.8  private:
402            
403                static LoggerRep* _rep;
404                static String _homeDirectory;
405                static Uint32 _severityMask;
406                static Uint32 _writeControlMask;
407 david 1.12 
408                static const char   _SEPARATOR;
409                static const Uint32 _NUM_LOGLEVEL;
410            
411                static const Boolean _SUCCESS;
412                static const Boolean _FAILURE;
413 mike  1.21 
414 david 1.12     static void _putInternal(
415 mike  1.21         LogFileType logFileType,
416                    const String& systemId,
417                    const Uint32 logComponent,
418                    Uint32 logLevel,
419                    const String& formatString,
420                    const String& messageId,
421                    const Formatter::Arg& arg0 = Formatter::DEFAULT_ARG,
422                    const Formatter::Arg& arg1 = Formatter::DEFAULT_ARG,
423                    const Formatter::Arg& arg2 = Formatter::DEFAULT_ARG,
424                    const Formatter::Arg& arg3 = Formatter::DEFAULT_ARG,
425                    const Formatter::Arg& arg4 = Formatter::DEFAULT_ARG,
426                    const Formatter::Arg& arg5 = Formatter::DEFAULT_ARG,
427                    const Formatter::Arg& arg6 = Formatter::DEFAULT_ARG,
428                    const Formatter::Arg& arg7 = Formatter::DEFAULT_ARG,
429                    const Formatter::Arg& arg8 = Formatter::DEFAULT_ARG,
430                    const Formatter::Arg& arg9 = Formatter::DEFAULT_ARG);
431 mike  1.8  };
432            
433            PEGASUS_NAMESPACE_END
434            
435            #endif /* Pegasus_Logger_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2