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

  1 kumpf 1.2 /*
  2 martin 1.7 //%LICENSE////////////////////////////////////////////////////////////////
  3 kumpf  1.2 // 
  4 martin 1.7 // Licensed to The Open Group (TOG) under one or more contributor license
  5            // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  6            // this work for additional information regarding copyright ownership.
  7            // Each contributor licenses this file to you under the OpenPegasus Open
  8            // Source License; you may not use this file except in compliance with the
  9            // License.
 10            // 
 11            // Permission is hereby granted, free of charge, to any person obtaining a
 12            // copy of this software and associated documentation files (the "Software"),
 13            // to deal in the Software without restriction, including without limitation
 14            // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 15            // and/or sell copies of the Software, and to permit persons to whom the
 16            // Software is furnished to do so, subject to the following conditions:
 17            // 
 18            // The above copyright notice and this permission notice shall be included
 19            // in all copies or substantial portions of the Software.
 20            // 
 21            // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 22            // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 23            // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 24            // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 25 martin 1.7 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 26            // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 27            // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 28            // 
 29            //////////////////////////////////////////////////////////////////////////
 30 kumpf  1.2 */
 31 martin 1.7 
 32 kumpf  1.2 #include "Log.h"
 33            #include "Defines.h"
 34            #include "Config.h"
 35            #include <syslog.h>
 36            #include <string.h>
 37            #include <stdarg.h>
 38 kumpf  1.6 #include <stdio.h>
 39 kumpf  1.2 
 40            static enum LogLevel _level = LL_INFORMATION;
 41            
 42 kumpf  1.3 /*
 43            **==============================================================================
 44            **
 45            ** InitLogLevel()
 46            **
 47            **==============================================================================
 48            */
 49            
 50 kumpf  1.4 void InitLogLevel(void)
 51 kumpf  1.3 {
 52                char buffer[EXECUTOR_BUFFER_SIZE];
 53            
 54                if (GetConfigParam("logLevel", buffer) == 0)
 55                {
 56 kumpf  1.5         SetLogLevel(buffer);
 57                }
 58            }
 59            
 60            /*
 61            **==============================================================================
 62            **
 63            ** SetLogLevel()
 64            **
 65            **==============================================================================
 66            */
 67            
 68            int SetLogLevel(const char* logLevel)
 69            {
 70                if (strcasecmp(logLevel, "TRACE") == 0)
 71                {
 72                    _level = LL_TRACE;
 73                    return 0;
 74                }
 75                else if (strcasecmp(logLevel, "INFORMATION") == 0)
 76                {
 77 kumpf  1.5         _level = LL_INFORMATION;
 78                    return 0;
 79                }
 80                else if (strcasecmp(logLevel, "WARNING") == 0)
 81                {
 82                    _level = LL_WARNING;
 83                    return 0;
 84                }
 85                else if (strcasecmp(logLevel, "SEVERE") == 0)
 86                {
 87                    _level = LL_SEVERE;
 88                    return 0;
 89                }
 90                else if (strcasecmp(logLevel, "FATAL") == 0)
 91                {
 92                    _level = LL_FATAL;
 93                    return 0;
 94                }
 95                else
 96                {
 97                    return -1;
 98 kumpf  1.3     }
 99            }
100            
101            /*
102            **==============================================================================
103            **
104            ** GetLogLevel()
105            **
106            **==============================================================================
107            */
108            
109 kumpf  1.4 enum LogLevel GetLogLevel(void)
110 kumpf  1.3 {
111                return _level;
112            }
113            
114 kumpf  1.5 /*
115            **==============================================================================
116            **
117            ** OpenLog()
118            **
119            **==============================================================================
120            */
121            
122 kumpf  1.2 void OpenLog(const char* ident)
123            {
124                int options = LOG_PID;
125            
126                openlog(ident, options, LOG_DAEMON);
127            }
128            
129 kumpf  1.5 /*
130            **==============================================================================
131            **
132            ** Log()
133            **
134            **==============================================================================
135            */
136            
137 kumpf  1.2 void Log(enum LogLevel type, const char *format, ...)
138            {
139                /* These definitions are consistent with System::syslog in
140                   SystemPOSIX.cpp. */
141                static int _priorities[] =
142                {
143                    LOG_CRIT, /* LL_FATAL, */
144                    LOG_ERR, /* LL_SEVERE */
145                    LOG_WARNING, /* LL_WARNING */
146                    LOG_INFO, /* LL_INFORMATION */
147                    LOG_DEBUG, /* LL_TRACE */
148                };
149            
150                /* This array maps Pegasus "log levels" to syslog priorities. */
151            
152                if ((int)type <= (int)_level)
153                {
154                    va_list ap;
155                    char buffer[EXECUTOR_BUFFER_SIZE];
156            
157                    va_start(ap, format);
158 kumpf  1.2         /* Flawfinder: ignore */
159 kumpf  1.3         vsprintf(buffer, format, ap);
160 kumpf  1.2         va_end(ap);
161            
162                    syslog(_priorities[(int)type], "%s", buffer);
163                }
164            }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2