1
0
Fork 0

fixed logging in arangosh

This commit is contained in:
Jan Steemann 2013-10-31 18:43:00 +01:00
parent 83a2e5ca3d
commit 4ad95f8b53
2 changed files with 57 additions and 28 deletions

View File

@ -493,35 +493,60 @@ void ArangoClient::stopPager () {
#endif
////////////////////////////////////////////////////////////////////////////////
/// @brief strip binary data from string
/// this is done before sending the string to a pager or writing it to the log
////////////////////////////////////////////////////////////////////////////////
static std::string StripBinary (const char* value) {
string result;
char const* p = value;
bool inBinary = false;
while (*p) {
if (inBinary) {
if (*p == 'm') {
inBinary = false;
}
}
else {
if (*p == '\x1b') {
inBinary = true;
}
else {
result.push_back(*p);
}
}
++p;
}
return result;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief print to pager
////////////////////////////////////////////////////////////////////////////////
void ArangoClient::internalPrint (const char* format, const char* str) {
if (str) {
if (*str == '\x1b') {
// terminal escape sequence
if (str == 0) {
str = format;
format = "%s";
}
if (_pager == stdout) {
fprintf(_pager, format, str);
if (_log) {
string sanitised = StripBinary(str);
log(format, sanitised.c_str());
}
}
else {
// regular string value
fprintf(_pager, format, str);
log(format, str);
}
}
else {
if (*format == '\x1b') {
// terminal escape sequence
if (_pager == stdout) {
fprintf(_pager, "%s", format);
}
}
else {
// regular string value
fprintf(_pager, "%s", format);
log("%s", format);
string sanitised = StripBinary(str);
if (! sanitised.empty()) {
fprintf(_pager, format, sanitised.c_str());
log(format, sanitised.c_str());
}
}
}
@ -592,9 +617,11 @@ void ArangoClient::printByeBye () {
void ArangoClient::log (const char* format,
const char* str) {
if (_log) {
if (*str != '\x1b') {
string sanitised = StripBinary(str);
if (! sanitised.empty()) {
// do not print terminal escape sequences into log
fprintf(_log, format, str);
fprintf(_log, format, sanitised.c_str());
}
}
}
@ -607,9 +634,11 @@ void ArangoClient::log (const char* format,
const char* prompt,
const char* str) {
if (_log) {
if (*str != '\x1b') {
string sanitised = StripBinary(str);
if (! sanitised.empty()) {
// do not print terminal escape sequences into log
fprintf(_log, format, prompt, str);
fprintf(_log, format, prompt, sanitised.c_str());
}
}
}