summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/llerror.cpp57
-rw-r--r--indra/llcommon/llstreamtools.cpp81
-rw-r--r--indra/llcommon/llstreamtools.h5
3 files changed, 62 insertions, 81 deletions
diff --git a/indra/llcommon/llerror.cpp b/indra/llcommon/llerror.cpp
index 22b2c9db82..13bf368334 100644
--- a/indra/llcommon/llerror.cpp
+++ b/indra/llcommon/llerror.cpp
@@ -37,15 +37,16 @@
#include <cctype>
#ifdef __GNUC__
-#include <cxxabi.h>
-#endif
+# include <cxxabi.h>
+#endif // __GNUC__
#include <sstream>
#if !LL_WINDOWS
-#include <syslog.h>
-#endif
+# include <syslog.h>
+# include <unistd.h>
+#endif // !LL_WINDOWS
#if LL_WINDOWS
-#include <windows.h>
-#endif
+# include <windows.h>
+#endif // LL_WINDOWS
#include <vector>
#include "llapp.h"
@@ -133,18 +134,58 @@ namespace {
class RecordToStderr : public LLError::Recorder
{
public:
- RecordToStderr(bool timestamp) : mTimestamp(timestamp) { }
+ RecordToStderr(bool timestamp) : mTimestamp(timestamp), mUseANSI(ANSI_PROBE) { }
virtual bool wantsTime() { return mTimestamp; }
virtual void recordMessage(LLError::ELevel level,
- const std::string& message)
+ const std::string& message)
{
+ if (ANSI_PROBE == mUseANSI)
+ mUseANSI = (checkANSI() ? ANSI_YES : ANSI_NO);
+
+ if (ANSI_YES == mUseANSI)
+ {
+ // Default all message levels to bold so we can distinguish our own messages from those dumped by subprocesses and libraries.
+ colorANSI("1"); // bold
+ switch (level) {
+ case LLError::LEVEL_ERROR:
+ colorANSI("31"); // red
+ break;
+ case LLError::LEVEL_WARN:
+ colorANSI("34"); // blue
+ break;
+ case LLError::LEVEL_DEBUG:
+ colorANSI("35"); // magenta
+ break;
+ default:
+ break;
+ }
+ }
fprintf(stderr, "%s\n", message.c_str());
+ if (ANSI_YES == mUseANSI) colorANSI("0"); // reset
}
private:
bool mTimestamp;
+ typedef enum ANSIState {ANSI_PROBE, ANSI_YES, ANSI_NO};
+ ANSIState mUseANSI;
+ void colorANSI(const std::string color)
+ {
+ // ANSI color code escape sequence
+ fprintf(stderr, "\033[%sm", color.c_str() );
+ };
+ bool checkANSI(void)
+ {
+#if LL_LINUX || LL_DARWIN
+ // Check whether it's okay to use ANSI; if stderr is
+ // a tty then we assume yes. Can be turned off with
+ // the LL_NO_ANSI_COLOR env var.
+ return (0 != isatty(2)) &&
+ (NULL == getenv("LL_NO_ANSI_COLOR"));
+#endif // LL_LINUX
+ return false;
+ };
};
class RecordToFixedBuffer : public LLError::Recorder
diff --git a/indra/llcommon/llstreamtools.cpp b/indra/llcommon/llstreamtools.cpp
index 8d4a3ef6b8..e4f121747c 100644
--- a/indra/llcommon/llstreamtools.cpp
+++ b/indra/llcommon/llstreamtools.cpp
@@ -263,20 +263,14 @@ bool get_word(std::string& output_string, std::istream& input_stream, int n)
// get everything up to and including the next newline
bool get_line(std::string& output_string, std::istream& input_stream)
{
+ output_string.clear();
char c = input_stream.get();
while (input_stream.good())
{
- if ('\r' == c)
- {
- // skip carriage returns
- }
- else
+ output_string += c;
+ if ('\n' == c)
{
- output_string += c;
- if ('\n' == c)
- {
- break;
- }
+ break;
}
c = input_stream.get();
}
@@ -288,27 +282,21 @@ bool get_line(std::string& output_string, std::istream& input_stream)
// add a newline on the end if bail before actual line ending
bool get_line(std::string& output_string, std::istream& input_stream, int n)
{
+ output_string.clear();
int char_count = 0;
char c = input_stream.get();
while (input_stream.good() && char_count < n)
{
char_count++;
output_string += c;
- if ('\r' == c)
+ if ('\n' == c)
{
- // skip carriage returns
+ break;
}
- else
+ if (char_count >= n)
{
- if ('\n' == c)
- {
- break;
- }
- if (char_count >= n)
- {
- output_string.append("\n");
- break;
- }
+ output_string.append("\n");
+ break;
}
c = input_stream.get();
}
@@ -408,49 +396,6 @@ void replace_newlines_with_whitespace(std::string& line)
}
}
-// returns 1 for solitary "{"
-// returns -1 for solitary "}"
-// otherwise returns 0
-int get_brace_count(const std::string& line)
-{
- int index = 0;
- int line_size = line.size();
- char c = 0;
- while (index < line_size)
- {
- c = line[index];
- index++;
- if (!isspace(c))
- {
- break;
- }
- }
- char brace = c;
- // make sure the rest of the line is whitespace
- while (index < line_size)
- {
- c = line[index];
- if (!isspace(c))
- {
- break;
- }
- index++;
- }
- if ('\n' != c)
- {
- return 0;
- }
- if ('{' == brace)
- {
- return 1;
- }
- else if ('}' == brace)
- {
- return -1;
- }
- return 0;
-}
-
// erases any double-quote characters in 'line'
void remove_double_quotes(std::string& line)
{
@@ -498,7 +443,7 @@ void get_keyword_and_value(std::string& keyword,
}
// get the keyword
- keyword.assign("");
+ keyword.clear();
while (line_index < line_size)
{
c = line[line_index];
@@ -510,6 +455,8 @@ void get_keyword_and_value(std::string& keyword,
line_index++;
}
+ // get the value
+ value.clear();
if (keyword.size() > 0
&& '\r' != line[line_index]
&& '\n' != line[line_index])
@@ -523,8 +470,6 @@ void get_keyword_and_value(std::string& keyword,
line_index++;
}
- // get the value
- value.assign("");
while (line_index < line_size)
{
c = line[line_index];
diff --git a/indra/llcommon/llstreamtools.h b/indra/llcommon/llstreamtools.h
index b024112f9f..22be3a914a 100644
--- a/indra/llcommon/llstreamtools.h
+++ b/indra/llcommon/llstreamtools.h
@@ -96,11 +96,6 @@ void escape_string(std::string& line);
// replaces each '\n' character with ' '
void replace_newlines_with_whitespace(std::string& line);
-// returns 1 for solitary "{"
-// returns -1 for solitary "}"
-// otherwise returns 0
-int get_brace_count(const std::string& line);
-
// erases any double-quote characters in line
void remove_double_quotes(std::string& line);