give lamassu support 2 full days of logs; log sharing last for 1 week
This commit is contained in:
parent
dc2f4e497f
commit
783b85ed72
3 changed files with 22 additions and 18 deletions
|
|
@ -41,7 +41,7 @@ app.get('/api/support_logs/logs', (req, res, next) => {
|
|||
.then(log => (!_.isNil(log) && !_.isEmpty(log)) ? log : supportLogs.batch().then(_.first))
|
||||
.then(result => {
|
||||
const log = result || {}
|
||||
return logs.getMachineLogs(log.deviceId, log.timestamp)
|
||||
return logs.getUnlimitedMachineLogs(log.deviceId, log.timestamp)
|
||||
})
|
||||
.then(r => res.send(r))
|
||||
.catch(next)
|
||||
|
|
|
|||
32
lib/logs.js
32
lib/logs.js
|
|
@ -56,23 +56,27 @@ function update (deviceId, logLines) {
|
|||
return db.none(sql)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all logs by machine id
|
||||
* and timestamp
|
||||
*
|
||||
* @name list
|
||||
* @function
|
||||
*
|
||||
* @param {string} deviceId Machine id to fetch the logs for
|
||||
* @param {date} until Show the logs until the date provided, defaults to now
|
||||
*
|
||||
* @returns {array} Array of logs for the requested machinej
|
||||
*/
|
||||
function getUnlimitedMachineLogs (deviceId, until = new Date().toISOString()) {
|
||||
const sql = `select id, log_level, timestamp, message from logs
|
||||
where device_id=$1
|
||||
and timestamp <= $2
|
||||
and timestamp > ($2 - interval '2 days')
|
||||
order by timestamp asc`
|
||||
|
||||
return Promise.all([db.any(sql, [ deviceId, until ]), getMachineName(deviceId)])
|
||||
.then(([logs, machineName]) => ({
|
||||
logs: _.map(_.mapKeys(_.camelCase), logs),
|
||||
currentMachine: {deviceId, name: machineName}
|
||||
}))
|
||||
}
|
||||
|
||||
function getMachineLogs (deviceId, until = new Date().toISOString()) {
|
||||
const sql = `select id, log_level, timestamp, message from logs
|
||||
where device_id=$1
|
||||
and timestamp <= $3
|
||||
order by timestamp asc limit $2`
|
||||
order by timestamp asc
|
||||
limit $2`
|
||||
|
||||
return Promise.all([db.any(sql, [ deviceId, NUM_RESULTS, until ]), getMachineName(deviceId)])
|
||||
.then(([logs, machineName]) => ({
|
||||
logs: _.map(_.mapKeys(_.camelCase), logs),
|
||||
|
|
@ -80,4 +84,4 @@ function getMachineLogs (deviceId, until = new Date().toISOString()) {
|
|||
}))
|
||||
}
|
||||
|
||||
module.exports = { getMachineLogs, update, getLastSeen }
|
||||
module.exports = { getUnlimitedMachineLogs, getMachineLogs, update, getLastSeen }
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ function insert (deviceId) {
|
|||
function batch () {
|
||||
const sql = `select s.id, s.device_id, s.timestamp, devices.name from support_logs as s
|
||||
inner join devices on s.device_id = devices.device_id
|
||||
where timestamp > (now() - interval '2 days')
|
||||
where timestamp > (now() - interval '1 week')
|
||||
order by s.timestamp desc`
|
||||
return db.any(sql)
|
||||
.then(_.map(_.mapKeys(_.camelCase)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue