aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/llerror.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llcommon/llerror.cpp')
-rw-r--r--linden/indra/llcommon/llerror.cpp57
1 files changed, 49 insertions, 8 deletions
diff --git a/linden/indra/llcommon/llerror.cpp b/linden/indra/llcommon/llerror.cpp
index d9ab57c..0e7db89 100644
--- a/linden/indra/llcommon/llerror.cpp
+++ b/linden/indra/llcommon/llerror.cpp
@@ -37,15 +37,16 @@
37 37
38#include <cctype> 38#include <cctype>
39#ifdef __GNUC__ 39#ifdef __GNUC__
40#include <cxxabi.h> 40# include <cxxabi.h>
41#endif 41#endif // __GNUC__
42#include <sstream> 42#include <sstream>
43#if !LL_WINDOWS 43#if !LL_WINDOWS
44#include <syslog.h> 44# include <syslog.h>
45#endif 45# include <unistd.h>
46#endif // !LL_WINDOWS
46#if LL_WINDOWS 47#if LL_WINDOWS
47#include <windows.h> 48# include <windows.h>
48#endif 49#endif // LL_WINDOWS
49#include <vector> 50#include <vector>
50 51
51#include "llapp.h" 52#include "llapp.h"
@@ -133,18 +134,58 @@ namespace {
133 class RecordToStderr : public LLError::Recorder 134 class RecordToStderr : public LLError::Recorder
134 { 135 {
135 public: 136 public:
136 RecordToStderr(bool timestamp) : mTimestamp(timestamp) { } 137 RecordToStderr(bool timestamp) : mTimestamp(timestamp), mUseANSI(ANSI_PROBE) { }
137 138
138 virtual bool wantsTime() { return mTimestamp; } 139 virtual bool wantsTime() { return mTimestamp; }
139 140
140 virtual void recordMessage(LLError::ELevel level, 141 virtual void recordMessage(LLError::ELevel level,
141 const std::string& message) 142 const std::string& message)
142 { 143 {
144 if (ANSI_PROBE == mUseANSI)
145 mUseANSI = (checkANSI() ? ANSI_YES : ANSI_NO);
146
147 if (ANSI_YES == mUseANSI)
148 {
149 // Default all message levels to bold so we can distinguish our own messages from those dumped by subprocesses and libraries.
150 colorANSI("1"); // bold
151 switch (level) {
152 case LLError::LEVEL_ERROR:
153 colorANSI("31"); // red
154 break;
155 case LLError::LEVEL_WARN:
156 colorANSI("34"); // blue
157 break;
158 case LLError::LEVEL_DEBUG:
159 colorANSI("35"); // magenta
160 break;
161 default:
162 break;
163 }
164 }
143 fprintf(stderr, "%s\n", message.c_str()); 165 fprintf(stderr, "%s\n", message.c_str());
166 if (ANSI_YES == mUseANSI) colorANSI("0"); // reset
144 } 167 }
145 168
146 private: 169 private:
147 bool mTimestamp; 170 bool mTimestamp;
171 typedef enum ANSIState {ANSI_PROBE, ANSI_YES, ANSI_NO};
172 ANSIState mUseANSI;
173 void colorANSI(const std::string color)
174 {
175 // ANSI color code escape sequence
176 fprintf(stderr, "\033[%sm", color.c_str() );
177 };
178 bool checkANSI(void)
179 {
180#if LL_LINUX || LL_DARWIN
181 // Check whether it's okay to use ANSI; if stderr is
182 // a tty then we assume yes. Can be turned off with
183 // the LL_NO_ANSI_COLOR env var.
184 return (0 != isatty(2)) &&
185 (NULL == getenv("LL_NO_ANSI_COLOR"));
186#endif // LL_LINUX
187 return false;
188 };
148 }; 189 };
149 190
150 class RecordToFixedBuffer : public LLError::Recorder 191 class RecordToFixedBuffer : public LLError::Recorder