lib/modules/monitorLog.js
function fetchLogs(root, msg, callback) {
    const number = msg.number;
    const logfile = msg.logfile;
    const serverId = msg.serverId;
    const filePath = path.join(root, getLogFileName(logfile, serverId));

    const endLogs = [];
    exec(`tail -n ${number} ${filePath}`, (error, output) => {
        const endOut = [];
        output = output.replace(/^\s+|\s+$/g, '').split(/\s+/);

        for (let i = 5; i < output.length; i += 6) {
            endOut.push(output[i]);
        }

        const endLength = endOut.length;
        for (let j = 0; j < endLength; j++) {
            const map = {};
            let json;
            try {
                json = JSON.parse(endOut[j]);
            } catch (e) {
                logger.error(`the log cannot parsed to json, ${e}`);
                continue;   // eslint-disable-line
            }
            map.time = json.time;
            map.route = json.route || json.service;
            map.serverId = serverId;
            map.timeUsed = json.timeUsed;
            map.params = endOut[j];
            endLogs.push(map);
        }

        callback({ logfile: logfile, dataArray: endLogs });
    });
}
function fetchLogs(root, msg, callback) {
    const number = msg.number;
    const logfile = msg.logfile;
    const serverId = msg.serverId;
    const filePath = path.join(root, getLogFileName(logfile, serverId));

    const endLogs = [];
    exec(`tail -n ${number} ${filePath}`, (error, output) => {
        const endOut = [];
        output = output.replace(/^\s+|\s+$/g, '').split(/\s+/);

        for (let i = 5; i < output.length; i += 6) {
            endOut.push(output[i]);
        }

        const endLength = endOut.length;
        for (let j = 0; j < endLength; j++) {
            const map = {};
            let json;
            try {
                json = JSON.parse(endOut[j]);
            } catch (e) {
                logger.error(`the log cannot parsed to json, ${e}`);
                continue;   // eslint-disable-line
            }
            map.time = json.time;
            map.route = json.route || json.service;
            map.serverId = serverId;
            map.timeUsed = json.timeUsed;
            map.params = endOut[j];
            endLogs.push(map);
        }

        callback({ logfile: logfile, dataArray: endLogs });
    });
}
function fetchLogs ( root , msg , callback ) { const number = msg . number ; const logfile = msg . logfile ; const serverId = msg . serverId ; const filePath = path . join ( root , getLogFileName ( logfile , serverId ) ) ; const endLogs = [ ] ; exec ( ` ${ number } ${ filePath } ` , ( error , output ) => { const endOut = [ ] ; output = output . replace ( / ^\s+|\s+$ / g , '' ) . split ( / \s+ / ) ; for ( let i = 5 ; i < output . length ; i += 6 ) { endOut . push ( output [ i ] ) ; } const endLength = endOut . length ; for ( let j = 0 ; j < endLength ; j ++ ) { const map = { } ; let json ; try { json = JSON . parse ( endOut [ j ] ) ; } catch ( e ) { logger . error ( ` ${ e } ` ) ; continue ; // eslint-disable-line } map . time = json . time ; map . route = json . route || json . service ; map . serverId = serverId ; map . timeUsed = json . timeUsed ; map . params = endOut [ j ] ; endLogs . push ( map ) ; } callback ( { logfile : logfile , dataArray : endLogs } ) ; } ) ; }
get the latest logs
get the latest logs