我目前正在制作一个选择框来显示所有日志消息,并且我正在努力让它显示所选值的所有日志消息。我可以获取各个值的日志消息,因此当您选择“信息”时,它会显示“信息”级别下的所有消息
但是我的问题是如何选择更高的日志级别来显示该日志级别以及低于该级别的日志级别?
我希望它如何工作:
日志消息来 self 的数据库,这些用于应用程序消息日志记录以供支持使用
- “调试”,然后选择“调试、错误、消息、信息”
- “错误”,然后让它选择“错误、消息、信息”
- “消息”,然后选择“消息、信息”
- “信息”,然后让它选择“信息”
Javascript代码
FilterLoggingTable();
function FilterLoggingTable()
{
// Check the value from the select box and filter out table data based on value selected
if ($("#loggingInputs").val() != null || $("#loggingDatePicker").val() != null)
{
var searchLoggingText = document.getElementById("loggingInputs").value.trim();
if (document.getElementById("loggingDatePicker") != null)
{
var searchLoggingDate = document.getElementById("loggingDatePicker").value.trim();
}
}
if (typeof GetServerLogging == 'function')
{
GetServerLogging(searchLoggingText, searchLoggingDate);
}
// Calls search logging function 2.5 seconds after page is ready
setTimeout(function ()
{
$("tr:not(:has(>th))").show().filter(function ()
{
var tableRowElement = this;
var tableRowTextFound, dateSelectedFound;
tableRowTextFound = (tableRowElement.textContent || tableRowElement.innerText || '').indexOf((searchLoggingText || "")) == -1;
dateSelectedFound = (tableRowElement.textContent || tableRowElement.innerText || '').indexOf((searchLoggingDate || "")) == -1;
return (tableRowTextFound || dateSelectedFound);
}).hide();
}, 1000);
};
// Get all server logging, and append to logging table (Logging page)
function GetServerLogging(loggingLevel, loggingDate) {
$.post("php/getServerLogging.php", {
command: "GetServerLogging",
getServerLoggingLevel: loggingLevel,
getServerLoggingDate: loggingDate
})
.success(function(data) {
var jsonMessage = JSON.parse(data);
var dataTable = $('#dataTables-example').DataTable();
dataTable.rows().remove().draw();
// Check to see if response message returns back "OK"
if (jsonMessage.RESPONSE == 'OK') {
$('#dataTables-example td').remove();
$("#dataTables-example tr:empty").remove();
// Set time before records start to load on page
setTimeout(function() {
console.log(JSON.stringify(data));
// Loops through the returned records
for (var i = 0; i < jsonMessage.RECORDS.length; i++) {
var currentRecord = jsonMessage.RECORDS[i];
var selectRecord = JSON.stringify(currentRecord);
var serverLoggingTableBody = $('#dataTables-example').children('tbody');
var serverLoggingTable = serverLoggingTableBody.length ? serverLoggingTableBody : $('#dataTables-example');
// Check to see if server log text doesn't equal to "Successfully synchronised"
if (currentRecord['ServerLogText'] != "Successfully synchronised") {
dataTable.row.add( [
GetCurrentDateUKFormatFromSQL(currentRecord['ServerLogDateTime']['date']),
currentRecord['ServerLogLevel'],
currentRecord['ServerLogText']
] ).draw();
}
}
}, 1000);
}
})
.fail(function(error) {
console.log("Unable to retrieve data from the server");
});
}
PHP 代码
if (isset($_POST['getServerLoggingLevel']) && isset($_POST['command']) && $_POST['command'] == "GetServerLogging") {
// Set server logging level to a variable to be used in MSSQL query
$getServerLog = $_POST['getServerLoggingLevel'];
// Set server logging data to a variable to be used in MSSQL query
$getServerLogDate = $_POST['getServerLoggingDate'];
// Create a string format for server logging date
$originalDate = $getServerLogDate;
$newDate = date("Y-m-d", strtotime($originalDate));
// Use logging information to query to database to get the correct data back
$SyncServerFunctionList->RespondWithUnencryptedJSONMessage("OK", $SyncServerFunctionList->MSSQLExecuteSelectAndReturnResultArray($connection, "SELECT Logs.Origin as ServerLogUser, Logs.Text as ServerLogText,
Logs.Type as ServerLogLevel, Logs.Timestamp as ServerLogDateTime from Logs
where Logs.Type like '$getServerLog' and CONVERT(varchar(10), Logs.Timestamp, 120) like '$newDate'
ORDER BY Timestamp ASC", "", "failed to select registered midwives"));
}
最佳答案
您可能需要使用 SQL 来选择多个值,例如
SELECT *****
FROM recordtable
WHERE warninglevel IN("Error","warning" )
IN 运算符将让您选择一个匹配多个值的字段。该示例允许您选择“错误”和“警告”级别的日志。您可以像这样进行其他选择。
关于javascript - 如何显示选定的日志级别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30619188/