log endpoint
This commit is contained in:
parent
d870625db5
commit
0ca0870caa
2 changed files with 33 additions and 1 deletions
|
|
@ -15,7 +15,8 @@ module.exports = (logFileName, logLevel) => {
|
||||||
winston.add(new (winston.transports.DailyRotateFile)({
|
winston.add(new (winston.transports.DailyRotateFile)({
|
||||||
filename: logFileName,
|
filename: logFileName,
|
||||||
datePattern: "yyyy-MM-DD",
|
datePattern: "yyyy-MM-DD",
|
||||||
json: false,
|
// https://github.com/winstonjs/winston-daily-rotate-file/issues/188
|
||||||
|
json: true,
|
||||||
maxSize: 1000000,
|
maxSize: 1000000,
|
||||||
maxFiles: 7,
|
maxFiles: 7,
|
||||||
level: logLevel
|
level: logLevel
|
||||||
|
|
|
||||||
|
|
@ -3215,4 +3215,35 @@ module.exports = async (
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ap.get('/api/log', async (_, res) => {
|
||||||
|
try {
|
||||||
|
// https://github.com/winstonjs/winston#querying-logs
|
||||||
|
/**
|
||||||
|
* @type {import('winston').QueryOptions}
|
||||||
|
*/
|
||||||
|
const options = {
|
||||||
|
from: new Date() - 1 * 60 * 60 * 1000,
|
||||||
|
until: new Date()
|
||||||
|
}
|
||||||
|
|
||||||
|
const results = await Common.Utils.makePromise((res, rej) => {
|
||||||
|
logger.query(options, (err, results) => {
|
||||||
|
if (err) {
|
||||||
|
rej(err)
|
||||||
|
} else {
|
||||||
|
res(results)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
res.status(200).json(results)
|
||||||
|
} catch (e) {
|
||||||
|
res
|
||||||
|
.status(e.message === Common.Constants.ErrorCode.NOT_AUTH ? 401 : 500)
|
||||||
|
.json({
|
||||||
|
errorMessage: e.message
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue