如何显示所选日志级别?

时间:2015-06-03 11:45:55

标签: javascript php jquery

我正在制作一个显示所有日志消息的选择框,我正在努力让它显示所选值的所有日志消息。我可以获取各个值的日志消息,因此当您选择“信息”时,它会显示“信息”级别下的所有消息

但是我的问题是如何选择更高的日志级别来显示日志级别以及低于该级别的日志级别?

我希望它如何运作:

日志消息来自我的数据库,这些消息用于支持用户的应用程序消息记录

  • “Debug”然后选择“Debug,Error,Message,Info”
  • “错误”然后让它选择“错误,消息,信息”
  • “消息”然后选择“消息,信息”
  • “信息”然后选择“信息”

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"));

    } 

1 个答案:

答案 0 :(得分:1)

您可能需要使用SQL来选择多个值,例如

SELECT *****
FROM recordtable
WHERE warninglevel IN("Error","warning" )

IN运算符将允许您选择匹配多个值的字段。该示例允许您选择“错误”和“警告”级别的日志。你可以做其他选择。