如何通过 selenium Chromedriver 禁用切割日志?
How to disable cutting logs by selenium Chromedriver?
我对从 selenium Chrome 驱动程序的控制台日志中捕获数据很感兴趣。
线路可能会很长。这对我来说不是问题——无论如何我都需要完整的字符串。但是,线被切断了。有人知道如何禁止切割这些线吗?
来自 Chrome 控制台日志:
*07/29/2015 07:56:17,474 [1438145776486z8saqwcu9] [DEB] ["Request complete: https://some_server.addr.com:443/subarg1/subarg2/subarg3/subarg4/subarg5/login?_=5776213 Status: OK (200). **Response payload: ","NEXT_ACTION_12"]***
来自Chrome驱动程序日志:
*[29.240][DEBUG]: DEVTOOLS EVENT Console.messageAdded { "message": { "column": 24, "executionContextId": 10, "level": "debug", "line": 18849, "parameters": [ { "type": "string", "value": "07/29/2015 07:56:17,474 [1438145776486z8saqwcu9] [DEB] [\"Request complete: https://some_server.addr.com:443/subarg1/subarg2/subarg3/subarg4/subarg5/login?_=5776213 Status: OK (200). **Response payloa...**" } ], "source": "console-api",*
ChromeDriverService.CreateDefaultService().LogPath = "1.txt";
driver = new ChromeDriver();
在那种情况下,您应该捕获完整的字符串。
从我的角度来看,查看 chromedriver 源,这是不可能的。
我看不到覆盖此行为的方法。
截断由 chromedriver 本身进行。如果记录的值为字符串 - 它被截断为 200 个字符,请参阅下面的部分来源。 FormatValueForDisplay
正在为字符串值
调用 TruncateString
Status DevToolsClientImpl::ProcessEvent(const internal::InspectorEvent& event) {
if (IsVLogOn(1)) {
VLOG(1) << "DEVTOOLS EVENT " << event.method << " "
<< FormatValueForDisplay(*event.params);
}
std::string FormatValueForDisplay(const base::Value& value) {
scoped_ptr<base::Value> copy(SmartDeepCopy(&value));
return PrettyPrintValue(*copy);
}
scoped_ptr<base::Value> SmartDeepCopy(const base::Value* value) {
//skipped code
} else if (value->GetAsString(&data)) {
TruncateString(&data);
return scoped_ptr<base::Value>(new base::StringValue(data));
}
void TruncateString(std::string* data) {
const size_t kMaxLength = 200;
if (data->length() > kMaxLength) {
data->resize(kMaxLength);
data->replace(kMaxLength - 3, 3, "...");
}
}
我对从 selenium Chrome 驱动程序的控制台日志中捕获数据很感兴趣。 线路可能会很长。这对我来说不是问题——无论如何我都需要完整的字符串。但是,线被切断了。有人知道如何禁止切割这些线吗?
来自 Chrome 控制台日志:
*07/29/2015 07:56:17,474 [1438145776486z8saqwcu9] [DEB] ["Request complete: https://some_server.addr.com:443/subarg1/subarg2/subarg3/subarg4/subarg5/login?_=5776213 Status: OK (200). **Response payload: ","NEXT_ACTION_12"]***
来自Chrome驱动程序日志:
*[29.240][DEBUG]: DEVTOOLS EVENT Console.messageAdded { "message": { "column": 24, "executionContextId": 10, "level": "debug", "line": 18849, "parameters": [ { "type": "string", "value": "07/29/2015 07:56:17,474 [1438145776486z8saqwcu9] [DEB] [\"Request complete: https://some_server.addr.com:443/subarg1/subarg2/subarg3/subarg4/subarg5/login?_=5776213 Status: OK (200). **Response payloa...**" } ], "source": "console-api",*
ChromeDriverService.CreateDefaultService().LogPath = "1.txt";
driver = new ChromeDriver();
在那种情况下,您应该捕获完整的字符串。
从我的角度来看,查看 chromedriver 源,这是不可能的。
我看不到覆盖此行为的方法。
截断由 chromedriver 本身进行。如果记录的值为字符串 - 它被截断为 200 个字符,请参阅下面的部分来源。 FormatValueForDisplay
正在为字符串值
TruncateString
Status DevToolsClientImpl::ProcessEvent(const internal::InspectorEvent& event) {
if (IsVLogOn(1)) {
VLOG(1) << "DEVTOOLS EVENT " << event.method << " "
<< FormatValueForDisplay(*event.params);
}
std::string FormatValueForDisplay(const base::Value& value) {
scoped_ptr<base::Value> copy(SmartDeepCopy(&value));
return PrettyPrintValue(*copy);
}
scoped_ptr<base::Value> SmartDeepCopy(const base::Value* value) {
//skipped code
} else if (value->GetAsString(&data)) {
TruncateString(&data);
return scoped_ptr<base::Value>(new base::StringValue(data));
}
void TruncateString(std::string* data) {
const size_t kMaxLength = 200;
if (data->length() > kMaxLength) {
data->resize(kMaxLength);
data->replace(kMaxLength - 3, 3, "...");
}
}