1 mike 1.1.2.1 /*
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 mike 1.1.2.1 // 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.1.2.2 #include "Strlcpy.h"
40 #include "Strlcat.h"
|
41 mike 1.1.2.1
42 static enum LogLevel _level = LL_INFORMATION;
43
44 void OpenLog(const char* ident, int perror)
45 {
46 int options = LOG_PID;
47
|
48 mike 1.1.2.7 #if defined(PEGASUS_OS_LINUX)
|
49 mike 1.1.2.1 if (perror)
50 options |= LOG_PERROR;
|
51 mike 1.1.2.7 #else
52 perror = 0;
53 #endif
|
54 mike 1.1.2.1
55 openlog(ident, options, LOG_DAEMON);
56 }
57
58 void SetLogLevel(enum LogLevel level)
59 {
60 _level = level;
61 }
62
63 void Log(enum LogLevel type, const char *format, ...)
64 {
65 static int _priorities[] =
66 {
67 LOG_ALERT, /* LL_FATAL, */
68 LOG_CRIT, /* LL_SEVERE */
69 LOG_WARNING, /* LL_WARNING */
70 LOG_NOTICE, /* LL_INFORMATION */
71 LOG_INFO, /* LL_TRACE */
72 };
|
73 mike 1.1.2.2 static const char* _prefix[] =
74 {
|
75 mike 1.1.2.3 "FATAL",
76 "SEVERE",
77 "WARNING",
|
78 mike 1.1.2.4 "INFORMATION",
|
79 mike 1.1.2.3 "TRACE"
|
80 mike 1.1.2.2 };
81 char prefixedFormat[EXECUTOR_BUFFER_SIZE];
82
83 /* Prefix the format with the log level. */
84
85 Strlcpy(prefixedFormat, _prefix[(int)type], sizeof(prefixedFormat));
86 Strlcat(prefixedFormat, ": ", sizeof(prefixedFormat));
87 Strlcat(prefixedFormat, format, sizeof(prefixedFormat));
|
88 mike 1.1.2.1
89 /* This array maps Pegasus "log levels" to syslog priorities. */
90
91 if ((int)type <= (int)_level)
92 {
93 va_list ap;
|
94 mike 1.1.2.8 char buffer[EXECUTOR_BUFFER_SIZE];
95
|
96 mike 1.1.2.1 va_start(ap, format);
|
97 mike 1.1.2.8 vsprintf(buffer, prefixedFormat, ap);
|
98 mike 1.1.2.1 va_end(ap);
|
99 mike 1.1.2.8
100 syslog(_priorities[(int)type], "%s", buffer);
|
101 mike 1.1.2.1 }
102 }
103
104 /*
105 **==============================================================================
106 **
107 ** GetLogLevel()
108 **
109 **==============================================================================
110 */
111
|
112 mike 1.1.2.6 void GetLogLevel()
|
113 mike 1.1.2.1 {
114 char buffer[EXECUTOR_BUFFER_SIZE];
115
|
116 mike 1.1.2.6 if (GetConfigParam("logLevel", buffer) == 0)
|
117 mike 1.1.2.1 {
118 if (strcasecmp(buffer, "TRACE") == 0)
119 SetLogLevel(LL_TRACE);
120 else if (strcasecmp(buffer, "INFORMATION") == 0)
121 SetLogLevel(LL_INFORMATION);
122 else if (strcasecmp(buffer, "WARNING") == 0)
123 SetLogLevel(LL_WARNING);
124 else if (strcasecmp(buffer, "SEVERE") == 0)
125 SetLogLevel(LL_SEVERE);
126 else if (strcasecmp(buffer, "FATAL") == 0)
127 SetLogLevel(LL_FATAL);
128 }
129 }
|