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
34
lib/logs.js
34
lib/logs.js
|
|
@ -18,7 +18,7 @@ const NUM_RESULTS = 1000
|
|||
* @returns {date} Last timestamp
|
||||
*/
|
||||
function getLastSeen (deviceId) {
|
||||
const sql = `select timestamp from logs
|
||||
const sql = `select timestamp from logs
|
||||
where device_id=$1
|
||||
order by timestamp desc limit 1`
|
||||
return db.oneOrNone(sql, [deviceId])
|
||||
|
|
@ -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 }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue