0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

more getLog work

show logs
show log helpers in shell
This commit is contained in:
Eliot Horowitz 2011-05-02 15:01:52 -04:00
parent 6c49cef53c
commit 815b995207
6 changed files with 66 additions and 4 deletions

View File

@ -37,6 +37,7 @@
#include "stats/snapshots.h"
#include "../util/concurrency/task.h"
#include "../util/version.h"
#include "../util/ramlog.h"
#include "../util/message_server.h"
#include "client.h"
#include "restapi.h"
@ -406,6 +407,8 @@ namespace mongo {
Client::initThread("initandlisten");
Logstream::get().addGlobalTee( new RamLog("global") );
bool is32bit = sizeof(int*) == 4;
{

View File

@ -312,9 +312,11 @@ namespace mongo {
}
virtual void init() {
assert( ! _log );
_log = new RamLog("global");
Logstream::get().addGlobalTee( _log );
_log = RamLog::get( "global" );
if ( ! _log ) {
_log = new RamLog("global");
Logstream::get().addGlobalTee( _log );
}
}
virtual void run( stringstream& ss ) {

View File

@ -23,6 +23,7 @@
#include "../util/message_server.h"
#include "../util/stringutils.h"
#include "../util/version.h"
#include "../util/ramlog.h"
#include "../util/signal_handlers.h"
#include "../util/admin_access.h"
#include "../db/dbwebserver.h"
@ -147,6 +148,7 @@ namespace mongo {
setupSIGTRAPforGDB();
setupCoreSignals();
setupSignals( false );
Logstream::get().addGlobalTee( new RamLog("global") );
}
void start( const MessageServer::Options& opts ) {

View File

@ -1084,6 +1084,10 @@ const StringData _jscode_raw_utils =
"shellHelper.show = function (what) {\n"
"assert(typeof what == \"string\");\n"
"\n"
"var args = what.split( /\\s+/ );\n"
"what = args[0]\n"
"args = args.splice(1)\n"
"\n"
"if (what == \"profile\") {\n"
"if (db.system.profile.count() == 0) {\n"
"print(\"db.system.profile is empty\");\n"
@ -1123,6 +1127,27 @@ const StringData _jscode_raw_utils =
"return \"\";\n"
"}\n"
"\n"
"if (what == \"log\" ) {\n"
"var n = \"global\";\n"
"if ( args.length > 0 )\n"
"n = args[0]\n"
"\n"
"var res = db.adminCommand( { getLog : n } )\n"
"for ( var i=0; i<res.log.length; i++){\n"
"print( res.log[i] )\n"
"}\n"
"return \"\"\n"
"}\n"
"\n"
"if (what == \"logs\" ) {\n"
"var res = db.adminCommand( { getLog : \"*\" } )\n"
"for ( var i=0; i<res.names.length; i++){\n"
"print( res.names[i] )\n"
"}\n"
"return \"\"\n"
"}\n"
"\n"
"\n"
"throw \"don't know how to show [\" + what + \"]\";\n"
"\n"
"}\n"
@ -1490,6 +1515,8 @@ const StringData _jscode_raw_utils =
"print(\"\\t\" + \"show collections show collections in current database\");\n"
"print(\"\\t\" + \"show users show users in current database\");\n"
"print(\"\\t\" + \"show profile show most recent system.profile entries with time >= 1ms\");\n"
"print(\"\\t\" + \"show logs show the accessible logger names\");\n"
"print(\"\\t\" + \"show log [name] prints out the last segment of log in memory, 'global' is default\");\n"
"print(\"\\t\" + \"use <db_name> set current database\");\n"
"print(\"\\t\" + \"db.foo.find() list objects in collection foo\");\n"
"print(\"\\t\" + \"db.foo.find( { a : 1 } ) list objects in foo where a == 1\");\n"

View File

@ -1079,6 +1079,10 @@ shellHelper.it = function(){
shellHelper.show = function (what) {
assert(typeof what == "string");
var args = what.split( /\s+/ );
what = args[0]
args = args.splice(1)
if (what == "profile") {
if (db.system.profile.count() == 0) {
print("db.system.profile is empty");
@ -1117,6 +1121,27 @@ shellHelper.show = function (what) {
//db.getMongo().getDBNames().sort().forEach(function (x) { print(x) });
return "";
}
if (what == "log" ) {
var n = "global";
if ( args.length > 0 )
n = args[0]
var res = db.adminCommand( { getLog : n } )
for ( var i=0; i<res.log.length; i++){
print( res.log[i] )
}
return ""
}
if (what == "logs" ) {
var res = db.adminCommand( { getLog : "*" } )
for ( var i=0; i<res.names.length; i++){
print( res.names[i] )
}
return ""
}
throw "don't know how to show [" + what + "]";
@ -1485,6 +1510,8 @@ help = shellHelper.help = function (x) {
print("\t" + "show collections show collections in current database");
print("\t" + "show users show users in current database");
print("\t" + "show profile show most recent system.profile entries with time >= 1ms");
print("\t" + "show logs show the accessible logger names");
print("\t" + "show log [name] prints out the last segment of log in memory, 'global' is default");
print("\t" + "use <db_name> set current database");
print("\t" + "db.foo.find() list objects in collection foo");
print("\t" + "db.foo.find( { a : 1 } ) list objects in foo where a == 1");

View File

@ -176,7 +176,8 @@ namespace mongo {
scoped_lock lk( *_namedLock );
for ( RM::iterator i=_named->begin(); i!=_named->end(); ++i ) {
names.push_back( i->first );
if ( i->second->n )
names.push_back( i->first );
}
}