(file) Return to Log.c CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Executor

  1 kumpf 1.1.4.2 /*
  2               //%2006////////////////////////////////////////////////////////////////////////
  3               //
  4               // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  5               // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  6               // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  7               // IBM Corp.; EMC Corporation, The Open Group.
  8               // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  9               // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
 10               // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 11               // EMC Corporation; VERITAS Software Corporation; The Open Group.
 12               // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 13               // EMC Corporation; Symantec Corporation; The Open Group.
 14               //
 15               // Permission is hereby granted, free of charge, to any person obtaining a copy
 16               // of this software and associated documentation files (the "Software"), to
 17               // deal in the Software without restriction, including without limitation the
 18               // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 19               // sell copies of the Software, and to permit persons to whom the Software is
 20               // furnished to do so, subject to the following conditions:
 21               // 
 22 kumpf 1.1.4.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 23               // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 24               // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 25               // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 26               // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 27               // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 28               // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 29               // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 30               //
 31               //%/////////////////////////////////////////////////////////////////////////////
 32               */
 33               #include "Log.h"
 34               #include "Defines.h"
 35               #include "Config.h"
 36               #include <syslog.h>
 37               #include <string.h>
 38               #include <stdarg.h>
 39               #include "Strlcpy.h"
 40               #include "Strlcat.h"
 41               
 42               static enum LogLevel _level = LL_INFORMATION;
 43 kumpf 1.1.4.2 
 44 mike  1.1.4.3 void OpenLog(const char* ident)
 45 kumpf 1.1.4.2 {
 46                   int options = LOG_PID;
 47               
 48                   openlog(ident, options, LOG_DAEMON);
 49               }
 50               
 51               void SetLogLevel(enum LogLevel level)
 52               {
 53                   _level = level;
 54               }
 55               
 56               void Log(enum LogLevel type, const char *format, ...)
 57               {
 58 kumpf 1.1.4.4     // These definitions are consistent with System::syslog in SystemPOSIX.cpp.
 59 kumpf 1.1.4.2     static int _priorities[] =
 60                   {
 61 kumpf 1.1.4.4         LOG_CRIT, /* LL_FATAL, */
 62                       LOG_ERR, /* LL_SEVERE */
 63 kumpf 1.1.4.2         LOG_WARNING, /* LL_WARNING */
 64 kumpf 1.1.4.4         LOG_INFO, /* LL_INFORMATION */
 65                       LOG_DEBUG, /* LL_TRACE */
 66 kumpf 1.1.4.2     };
 67 kumpf 1.1.4.4 
 68 kumpf 1.1.4.2     static const char* _prefix[] =
 69                   {
 70                       "FATAL",
 71                       "SEVERE",
 72                       "WARNING",
 73                       "INFORMATION",
 74                       "TRACE"
 75                   };
 76 kumpf 1.1.4.4 
 77 kumpf 1.1.4.2     char prefixedFormat[EXECUTOR_BUFFER_SIZE];
 78               
 79                   /* Prefix the format with the log level. */
 80               
 81                   Strlcpy(prefixedFormat, _prefix[(int)type], sizeof(prefixedFormat));
 82                   Strlcat(prefixedFormat, ": ", sizeof(prefixedFormat));
 83                   Strlcat(prefixedFormat, format, sizeof(prefixedFormat));
 84               
 85                   /* This array maps Pegasus "log levels" to syslog priorities. */
 86               
 87                   if ((int)type <= (int)_level)
 88                   {
 89                       va_list ap;
 90                       char buffer[EXECUTOR_BUFFER_SIZE];
 91               
 92                       va_start(ap, format);
 93                       /* Flawfinder: ignore */
 94                       vsprintf(buffer, prefixedFormat, ap);
 95                       va_end(ap);
 96               
 97                       syslog(_priorities[(int)type], "%s", buffer);
 98 kumpf 1.1.4.2     }
 99               }
100               
101               /*
102               **==============================================================================
103               **
104               ** GetLogLevel()
105               **
106               **==============================================================================
107               */
108               
109               void GetLogLevel()
110               {
111                   char buffer[EXECUTOR_BUFFER_SIZE];
112               
113                   if (GetConfigParam("logLevel", buffer) == 0)
114                   {
115                       if (strcasecmp(buffer, "TRACE") == 0)
116                           SetLogLevel(LL_TRACE);
117                       else if (strcasecmp(buffer, "INFORMATION") == 0)
118                           SetLogLevel(LL_INFORMATION);
119 kumpf 1.1.4.2         else if (strcasecmp(buffer, "WARNING") == 0)
120                           SetLogLevel(LL_WARNING);
121                       else if (strcasecmp(buffer, "SEVERE") == 0)
122                           SetLogLevel(LL_SEVERE);
123                       else if (strcasecmp(buffer, "FATAL") == 0)
124                           SetLogLevel(LL_FATAL);
125                   }
126               }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2