mirror of https://gitee.com/bigwinds/arangodb
issue #330
This commit is contained in:
parent
443757df3b
commit
2b84d417f8
|
@ -13,6 +13,8 @@ online manual, available at http://www.arangodb.org/
|
|||
|
||||
The most important startup options are:
|
||||
|
||||
OPTION "--audit-log <string>"
|
||||
log input and output to audit log file <string> ENDOPTION
|
||||
OPTION "--configuration <string>"
|
||||
read configuration from file <string> ENDOPTION
|
||||
OPTION "--log.level <string>"
|
||||
|
|
|
@ -183,6 +183,9 @@ ArangoClient::ArangoClient ()
|
|||
_pager(stdout),
|
||||
_usePager(false),
|
||||
|
||||
_logFile(""),
|
||||
_logOptions(false),
|
||||
|
||||
_serverOptions(false),
|
||||
_endpointString(),
|
||||
_endpointServer(0),
|
||||
|
@ -282,6 +285,18 @@ void ArangoClient::setupPrettyPrint (ProgramOptionsDescription& description) {
|
|||
_prettyPrintOptions = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief sets up the log options
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ArangoClient::setupLog (ProgramOptionsDescription& description) {
|
||||
description
|
||||
("audit-log", &_logFile, "audit log file to save commands and results to")
|
||||
;
|
||||
|
||||
_logOptions = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief sets up the pager options
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -506,10 +521,44 @@ void ArangoClient::stopPager () {
|
|||
|
||||
void ArangoClient::internalPrint (const char* format, const char* str) {
|
||||
if (str) {
|
||||
fprintf(_pager, format, str);
|
||||
if (*str != '\x1b') {
|
||||
fprintf(_pager, format, str);
|
||||
log(format, str);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fprintf(_pager, "%s", format);
|
||||
if (*format != '\x1b') {
|
||||
// do not print terminal escape sequences to pager
|
||||
fprintf(_pager, "%s", format);
|
||||
log("%s", format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief open the log file
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ArangoClient::openLog () {
|
||||
if (! _logFile.empty()) {
|
||||
_log = fopen(_logFile.c_str(), "w");
|
||||
if (_log == 0) {
|
||||
cerr << "Cannot open file '" << _logFile << "' for logging." << endl;
|
||||
}
|
||||
else {
|
||||
cout << "Logging input and output to '" << _logFile << "'." << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief close the log file
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ArangoClient::closeLog () {
|
||||
if (! _logFile.empty() && _log != 0) {
|
||||
fclose(_log);
|
||||
_log = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -533,7 +582,30 @@ void ArangoClient::printWelcomeInfo () {
|
|||
|
||||
void ArangoClient::printByeBye () {
|
||||
if (! _quiet) {
|
||||
cout << "<ctrl-D>\n" << TRI_BYE_MESSAGE << endl;
|
||||
cout << "<ctrl-D>" << endl << TRI_BYE_MESSAGE << endl;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief log output
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ArangoClient::log (const char* format, const char* str) {
|
||||
if (_log) {
|
||||
if (*str != '\x1b') {
|
||||
// do not print terminal escape sequences into log
|
||||
fprintf(_log, format, str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief flush log output
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ArangoClient::flushLog () {
|
||||
if (_log) {
|
||||
fflush(_log);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -255,6 +255,12 @@ namespace triagens {
|
|||
|
||||
void setupPager (triagens::basics::ProgramOptionsDescription& description);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief sets up the log options
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void setupLog (triagens::basics::ProgramOptionsDescription& description);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief sets up the server options
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -289,6 +295,18 @@ namespace triagens {
|
|||
|
||||
void internalPrint (const char* format, const char* str = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief open log
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void openLog ();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief close log
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void closeLog ();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief print info message
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -301,6 +319,18 @@ namespace triagens {
|
|||
|
||||
void printByeBye ();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief log output
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void log (const char* format, const char* str);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief flush log
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void flushLog ();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief creates an new endpoint
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -488,6 +518,24 @@ namespace triagens {
|
|||
|
||||
bool _usePager;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief log filename
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
string _logFile;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief the log FILE
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
FILE* _log;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief use log options
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool _logOptions;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief use server options
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -433,6 +433,7 @@ static void ParseProgramOptions (int argc, char* argv[]) {
|
|||
BaseClient.setupAutoComplete(description);
|
||||
BaseClient.setupPrettyPrint(description);
|
||||
BaseClient.setupPager(description);
|
||||
BaseClient.setupLog(description);
|
||||
BaseClient.setupServer(description);
|
||||
|
||||
// and parse the command line and config file
|
||||
|
@ -447,6 +448,11 @@ static void ParseProgramOptions (int argc, char* argv[]) {
|
|||
LOGGER_FATAL << "module path not known, please use '--javascript.modules-path'";
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// turn on paging automatically if "pager" option is set
|
||||
if (options.has("pager") && ! options.has("use-pager")) {
|
||||
BaseClient.setUsePager(true);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -842,6 +848,8 @@ static void RunShell (v8::Handle<v8::Context> context, bool promptError) {
|
|||
if (*input == '\0') {
|
||||
continue;
|
||||
}
|
||||
|
||||
BaseClient.log("arangosh> %s\n", input);
|
||||
|
||||
string i = triagens::basics::StringUtils::trim(input);
|
||||
|
||||
|
@ -854,7 +862,7 @@ static void RunShell (v8::Handle<v8::Context> context, bool promptError) {
|
|||
TRI_FreeString(TRI_CORE_MEM_ZONE, input);
|
||||
input = TRI_DuplicateString("help()");
|
||||
}
|
||||
|
||||
|
||||
console.addHistory(input);
|
||||
|
||||
v8::HandleScope scope;
|
||||
|
@ -869,7 +877,10 @@ static void RunShell (v8::Handle<v8::Context> context, bool promptError) {
|
|||
|
||||
if (tryCatch.HasCaught()) {
|
||||
// command failed
|
||||
cout << TRI_StringifyV8Exception(&tryCatch);
|
||||
string exception(TRI_StringifyV8Exception(&tryCatch));
|
||||
|
||||
cout << exception;
|
||||
BaseClient.log("%s", exception.c_str());
|
||||
|
||||
// this will change the prompt for the next round
|
||||
promptError = true;
|
||||
|
@ -877,6 +888,10 @@ static void RunShell (v8::Handle<v8::Context> context, bool promptError) {
|
|||
|
||||
BaseClient.stopPager();
|
||||
cout << endl;
|
||||
|
||||
BaseClient.log("%s\n", "");
|
||||
// make sure the last command result makes it into the log file
|
||||
BaseClient.flushLog();
|
||||
}
|
||||
|
||||
console.close();
|
||||
|
@ -1055,7 +1070,7 @@ int main (int argc, char* argv[]) {
|
|||
// .............................................................................
|
||||
|
||||
ParseProgramOptions(argc, argv);
|
||||
|
||||
|
||||
// .............................................................................
|
||||
// set-up client connection
|
||||
// .............................................................................
|
||||
|
@ -1285,6 +1300,8 @@ int main (int argc, char* argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
BaseClient.openLog();
|
||||
|
||||
// .............................................................................
|
||||
// run normal shell
|
||||
// .............................................................................
|
||||
|
@ -1322,6 +1339,8 @@ int main (int argc, char* argv[]) {
|
|||
|
||||
context->Exit();
|
||||
context.Dispose();
|
||||
|
||||
BaseClient.closeLog();
|
||||
|
||||
// calling dispose in V8 3.10.x causes a segfault. the v8 docs says its not necessary to call it upon program termination
|
||||
// v8::V8::Dispose();
|
||||
|
|
|
@ -272,10 +272,10 @@
|
|||
internal.printIndent(newLevel);
|
||||
|
||||
if (internal.COLOR_OUTPUT) {
|
||||
internal.output(internal.COLOR_OUTPUT_DEFAULT,
|
||||
internal.quoteJsonString(k),
|
||||
internal.COLOR_OUTPUT_RESET,
|
||||
" : ");
|
||||
internal.output(internal.COLOR_OUTPUT_DEFAULT);
|
||||
internal.output(internal.quoteJsonString(k));
|
||||
internal.output(internal.COLOR_OUTPUT_RESET);
|
||||
internal.output(" : ");
|
||||
}
|
||||
else {
|
||||
internal.output(internal.quoteJsonString(k), " : ");
|
||||
|
|
Loading…
Reference in New Issue