aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/llerrorbuffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/llcommon/llerrorbuffer.cpp279
1 files changed, 0 insertions, 279 deletions
diff --git a/linden/indra/llcommon/llerrorbuffer.cpp b/linden/indra/llcommon/llerrorbuffer.cpp
deleted file mode 100644
index 9de4616..0000000
--- a/linden/indra/llcommon/llerrorbuffer.cpp
+++ /dev/null
@@ -1,279 +0,0 @@
1/**
2 * @file llerrorbuffer.cpp
3 *
4 * Copyright (c) 2002-2007, Linden Research, Inc.
5 *
6 * The source code in this file ("Source Code") is provided by Linden Lab
7 * to you under the terms of the GNU General Public License, version 2.0
8 * ("GPL"), unless you have obtained a separate licensing agreement
9 * ("Other License"), formally executed by you and Linden Lab. Terms of
10 * the GPL can be found in doc/GPL-license.txt in this distribution, or
11 * online at http://secondlife.com/developers/opensource/gplv2
12 *
13 * There are special exceptions to the terms and conditions of the GPL as
14 * it is applied to this Source Code. View the full text of the exception
15 * in the file doc/FLOSS-exception.txt in this software distribution, or
16 * online at http://secondlife.com/developers/opensource/flossexception
17 *
18 * By copying, modifying or distributing this software, you acknowledge
19 * that you have read and understood your obligations described above,
20 * and agree to abide by those obligations.
21 *
22 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
23 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
24 * COMPLETENESS OR PERFORMANCE.
25 */
26
27#include "linden_common.h"
28
29#include "llerrorbuffer.h"
30#include "llfixedbuffer.h"
31
32#include <fstream>
33#include <string.h>
34
35#if LL_WINDOWS
36# define WIN32_LEAN_AND_MEAN
37# include <winsock2.h>
38# include <windows.h> // for OutputDebugString
39#else
40# include <syslog.h>
41# include <stdio.h>
42#endif
43
44#include <time.h>
45
46// In order to compile in Visual C++ 6.0, you must use std:: in the header, and then
47// use the std namespace in the cpp. Otherwise, you'll break the (very) fragile C++ parser.
48using namespace std;
49
50LLErrorBuffer::LLErrorBuffer()
51: streambuf(),
52 mFile(NULL),
53 mBuf(),
54 mFixedBuf(NULL),
55 mErrorActive(TRUE),
56 mErrorTimestamp(TRUE),
57 mFileActive(FALSE),
58 mSyslogActive(TRUE),
59 mWinDebugActive(TRUE),
60 mElevatedRemote(FALSE),
61 mIsUTC(TRUE),
62 mLevel(DEBUG),
63 mPriority(DEBUG)
64{
65 mFilename[0] = '\0';
66#if LL_WINDOWS
67 // by default, turn off timestamps in the debug log on windows
68 mErrorTimestamp = FALSE;
69#endif
70}
71
72LLErrorBuffer::~LLErrorBuffer()
73{
74 delete mFile;
75 mFile = NULL;
76}
77
78#if !LL_WINDOWS
79int LLErrorBuffer::ELevelToSyslogPriority(const ELevel l)
80{
81 switch(l)
82 {
83 case DEBUG:
84 return LOG_DEBUG;
85 case INFO:
86 switch(mElevatedRemote)
87 {
88 case TRUE: return LOG_NOTICE;
89 default: return LOG_INFO;
90 }
91 case WARN:
92 return LOG_WARNING;
93 case FATAL:
94 return LOG_CRIT;
95 default:
96 return LOG_CRIT;
97 }
98 return LOG_CRIT;
99}
100#endif // LL_WINDOWS
101
102BOOL LLErrorBuffer::setFile(const char *filename)
103{
104 if (mFile == NULL)
105 {
106 mFile = new llofstream();
107 }
108 if (mFile->is_open())
109 {
110 mFile->close();
111 }
112 if (filename == NULL)
113 {
114 llwarns << "Input filename is NULL!!" << llendl;
115 return FALSE;
116 }
117 mFile->open(filename, llofstream::out | llofstream::app); /* Flawfinder: ignore */
118 if (mFile->is_open())
119 {
120 mFileActive = TRUE;
121 }
122 else
123 {
124 mFileActive = FALSE;
125 delete mFile;
126 mFile = NULL;
127 }
128 snprintf(mFilename, sizeof(mFilename), filename); /* Flawfinder: ignore */
129 return mFileActive;
130}
131
132void LLErrorBuffer::closeFile()
133{
134 if (mFile && mFile->is_open())
135 {
136 mFile->close();
137 mFileActive = FALSE;
138 delete mFile;
139 mFile = NULL;
140 }
141}
142
143const char * LLErrorBuffer::getFilename() const
144{
145 return mFilename;
146}
147
148void LLErrorBuffer::setUTCTimestamp(BOOL utc)
149{
150 mIsUTC = utc;
151}
152
153void LLErrorBuffer::enableError(BOOL active)
154{
155 mErrorActive = active;
156}
157
158void LLErrorBuffer::enableErrorTimestamp(BOOL active)
159{
160 mErrorTimestamp = active;
161}
162
163void LLErrorBuffer::enableFile(BOOL active)
164{
165 if (mFile != NULL)
166 {
167 if (mFile->is_open())
168 mFileActive = active;
169 }
170 else
171 mFileActive = FALSE;
172}
173
174#if !LL_WINDOWS
175void LLErrorBuffer::enableSyslog(BOOL active)
176{
177 mSyslogActive = active;
178}
179#endif // LL_WINDOWS
180
181#if LL_WINDOWS
182void LLErrorBuffer::enableWinDebug(BOOL active)
183{
184 mWinDebugActive = active;
185}
186#endif // LL_WINDOWS
187
188int LLErrorBuffer::overflow(int c)
189{
190 if (EOF != c)
191 {
192 if ('\n' == c)
193 {
194 // If we're not supposed to print anything, don't, but
195 // pretend that we did so taht the iostream doesn't think
196 // there's been a failure
197 if (mPriority < mLevel)
198 {
199 // Flush our message buffer
200 mBuf = "";
201 return 0;
202 }
203#if !LL_WINDOWS
204 if (mSyslogActive)
205 {
206 int pri = ELevelToSyslogPriority(mPriority);
207 syslog(pri, "%s", mBuf.c_str());
208 }
209#endif // LL_WINDOWS
210 const S32 BUF_SIZE = 64;
211 char time_str[BUF_SIZE]; /* Flawfinder: ignore */
212 if (mFileActive || mErrorActive)
213 {
214 time_t now;
215 time(&now);
216 S32 chars;
217 if(mIsUTC)
218 {
219 chars = (S32)strftime(time_str, BUF_SIZE,
220 "%Y-%m-%dT%H:%M:%SZ",
221 gmtime(&now));
222 }
223 else
224 {
225 chars = (S32)strftime(time_str, BUF_SIZE,
226 "%Y-%m-%dT%H:%M:%S %Z",
227 localtime(&now));
228 }
229 if (0 == chars)
230 {
231 strcpy(time_str, "time error"); /* Flawfinder: ignore */
232 }
233 }
234 if (mFileActive)
235 {
236 *mFile << time_str << " " << mBuf << std::endl;
237 }
238 if (mErrorActive)
239 {
240 if (mErrorTimestamp)
241 {
242 fprintf(stderr, "%s %s\n", time_str, mBuf.c_str());
243 }
244 else
245 {
246 fprintf(stderr, "%s\n", mBuf.c_str());
247 }
248
249 // std::cerr goes into the void on the viewer
250 //std::cerr << time_str << ' ' << mBuf << std::endl;
251 }
252 if (mFixedBuf)
253 {
254 mFixedBuf->addLine(mBuf.c_str());
255 }
256#if LL_WINDOWS
257 if (mWinDebugActive)
258 {
259 llutf16string utf16str = wstring_to_utf16str(utf8str_to_wstring(mBuf));
260 utf16str += '\n';
261 OutputDebugString(utf16str.c_str());
262 }
263#endif // LL_WINDOWS
264 // Is there a better way to truncate a string?
265 mBuf.erase(0, mBuf.length()); // Hack, Linux doesn't implement clear()!
266 }
267 else
268 {
269 mBuf += c;
270 }
271 }
272 return 0;
273}
274
275LLErrorBuffer::ELevel LLErrorBuffer::mergeLevel(const LLErrorBuffer::ELevel l)
276{
277 mLevel = llmin(mLevel, l);
278 return mLevel;
279}