1 kumpf 1.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.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 mike 1.5.16.1 #include <stdio.h>
|
40 kumpf 1.2
41 static enum LogLevel _level = LL_INFORMATION;
42
|
43 kumpf 1.3 /*
44 **==============================================================================
45 **
46 ** InitLogLevel()
47 **
48 **==============================================================================
49 */
50
|
51 kumpf 1.4 void InitLogLevel(void)
|
52 kumpf 1.3 {
53 char buffer[EXECUTOR_BUFFER_SIZE];
54
55 if (GetConfigParam("logLevel", buffer) == 0)
56 {
|
57 kumpf 1.5 SetLogLevel(buffer);
58 }
59 }
60
61 /*
62 **==============================================================================
63 **
64 ** SetLogLevel()
65 **
66 **==============================================================================
67 */
68
69 int SetLogLevel(const char* logLevel)
70 {
71 if (strcasecmp(logLevel, "TRACE") == 0)
72 {
73 _level = LL_TRACE;
74 return 0;
75 }
76 else if (strcasecmp(logLevel, "INFORMATION") == 0)
77 {
78 kumpf 1.5 _level = LL_INFORMATION;
79 return 0;
80 }
81 else if (strcasecmp(logLevel, "WARNING") == 0)
82 {
83 _level = LL_WARNING;
84 return 0;
85 }
86 else if (strcasecmp(logLevel, "SEVERE") == 0)
87 {
88 _level = LL_SEVERE;
89 return 0;
90 }
91 else if (strcasecmp(logLevel, "FATAL") == 0)
92 {
93 _level = LL_FATAL;
94 return 0;
95 }
96 else
97 {
98 return -1;
|
99 kumpf 1.3 }
100 }
101
102 /*
103 **==============================================================================
104 **
105 ** GetLogLevel()
106 **
107 **==============================================================================
108 */
109
|
110 kumpf 1.4 enum LogLevel GetLogLevel(void)
|
111 kumpf 1.3 {
112 return _level;
113 }
114
|
115 kumpf 1.5 /*
116 **==============================================================================
117 **
118 ** OpenLog()
119 **
120 **==============================================================================
121 */
122
|
123 kumpf 1.2 void OpenLog(const char* ident)
124 {
125 int options = LOG_PID;
126
127 openlog(ident, options, LOG_DAEMON);
128 }
129
|
130 kumpf 1.5 /*
131 **==============================================================================
132 **
133 ** Log()
134 **
135 **==============================================================================
136 */
137
|
138 kumpf 1.2 void Log(enum LogLevel type, const char *format, ...)
139 {
140 /* These definitions are consistent with System::syslog in
141 SystemPOSIX.cpp. */
142 static int _priorities[] =
143 {
144 LOG_CRIT, /* LL_FATAL, */
145 LOG_ERR, /* LL_SEVERE */
146 LOG_WARNING, /* LL_WARNING */
147 LOG_INFO, /* LL_INFORMATION */
148 LOG_DEBUG, /* LL_TRACE */
149 };
150
151 /* This array maps Pegasus "log levels" to syslog priorities. */
152
153 if ((int)type <= (int)_level)
154 {
155 va_list ap;
156 char buffer[EXECUTOR_BUFFER_SIZE];
157
158 va_start(ap, format);
159 kumpf 1.2 /* Flawfinder: ignore */
|
160 kumpf 1.3 vsprintf(buffer, format, ap);
|
161 kumpf 1.2 va_end(ap);
162
163 syslog(_priorities[(int)type], "%s", buffer);
164 }
165 }
|