Core/Rpc: CompressLog

git-svn-id: svn://ultimatepp.org/upp/trunk@7845 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2014-10-31 07:55:18 +00:00
parent b10efedc2f
commit 31471a889d
4 changed files with 41 additions and 2 deletions

View file

@ -346,6 +346,7 @@ struct JsonRpcRequestNamed : RpcRequest {
void LogRpcRequests(bool b = true);
void SetRpcServerTrace(Stream& s, int level = 1);
void SetRpcServerTraceCompress(bool compress);
void StopRpcServerTrace();
void SuppressRpcServerTraceForMethodCall();

View file

@ -48,6 +48,7 @@ void ThrowRpcError(const char *s)
static Stream *rpc_trace, *suppressed_rpc_trace;
static int rpc_trace_level;
static bool rpc_trace_compress = true;
void SetRpcServerTrace(Stream& s, int level)
{
@ -55,6 +56,11 @@ void SetRpcServerTrace(Stream& s, int level)
rpc_trace_level = level;
}
void SetRpcServerTraceCompress(bool compress)
{
rpc_trace_compress = compress;
}
void StopRpcServerTrace()
{
rpc_trace = NULL;
@ -71,8 +77,14 @@ bool CallRpcMethod(RpcData& data, const char *group, String methodname, const St
LLOG("method name: " << methodname);
if(sRpcMethodFilter)
methodname = (*sRpcMethodFilter)(methodname);
if(rpc_trace)
*rpc_trace << "RPC Request:\n" << request << '\n';
if(rpc_trace) {
*rpc_trace << "RPC Request:\n";
if(rpc_trace_compress)
*rpc_trace << CompressLog(request);
else
*rpc_trace << request;
*rpc_trace << '\n';
}
void (*fn)(RpcData&) = RpcMapGet(group, methodname);
if(!fn)
return false;

View file

@ -536,6 +536,30 @@ Vector<String> GetCsvLine(Stream& s, int separator, byte charset)
}
}
String CompressLog(const char *s)
{
StringBuffer result;
while(*s) {
const char *b = s;
while(IsSpace(*s))
s++;
result.Cat(b, s);
if(!*s)
break;
b = s;
while(*s && !IsSpace(*s))
s++;
if(s - b > 200) {
result.Cat(b, 20);
result.Cat("....", 4);
result.Cat(s - 20, 20);
}
else
result.Cat(b, s);
}
return result;
}
int ChNoInvalid(int c)
{
return c == DEFAULTCHAR ? '_' : c;

View file

@ -234,6 +234,8 @@ String NormalizeSpaces(const char *begin, const char *end);
String CsvString(const String& text);
Vector<String> GetCsvLine(Stream& s, int separator, byte charset);
String CompressLog(const char *s);
#ifndef PLATFORM_WIN32
void Sleep(int msec);
#endif