feat: add new server log page
This commit is contained in:
parent
fc1951c4b2
commit
703c5d7c91
38 changed files with 2844 additions and 29 deletions
14
lib/db.js
14
lib/db.js
|
|
@ -1,6 +1,9 @@
|
|||
const Pgp = require('pg-promise')
|
||||
const uuid = require('uuid')
|
||||
const _ = require('lodash/fp')
|
||||
const psqlUrl = require('../lib/options').postgresql
|
||||
const logger = require('./logger')
|
||||
const eventBus = require('./event-bus')
|
||||
|
||||
const pgp = Pgp({
|
||||
pgNative: true,
|
||||
|
|
@ -15,4 +18,15 @@ const pgp = Pgp({
|
|||
})
|
||||
|
||||
const db = pgp(psqlUrl)
|
||||
|
||||
eventBus.subscribe('log', args => {
|
||||
const { level, message, meta } = args
|
||||
|
||||
const sql = `insert into server_logs
|
||||
(id, device_id, message, log_level, meta) values ($1, $2, $3, $4, $5) returning *`
|
||||
|
||||
db.one(sql, [uuid.v4(), '', message, level, meta])
|
||||
.then(_.mapKeys(_.camelCase))
|
||||
})
|
||||
|
||||
module.exports = db
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue