Added flag to opt-out db storing

This commit is contained in:
Douglas Barone 2021-01-04 10:31:01 -04:00
parent eb36ea8ce4
commit 786197f115

View File

@ -3,7 +3,7 @@ import { format, subDays } from 'date-fns'
const DAYS_TO_KEEP = process.env.NODE_ENV === 'production' ? 30 : 1
async function log({ level, tags = [], message = '', data }) {
async function log({ level, tags = [], message = '', data }, store = true) {
const now = new Date()
const color = {
@ -19,19 +19,21 @@ async function log({ level, tags = [], message = '', data }) {
console.log(
`${color}[${format(now, 'HH:mm:ss')}]${entryTags}\x1b[0m${message}`
)
try {
await prisma.log.create({
data: {
timestamp: now,
level,
tags,
message,
data
}
})
} catch (e) {
console.log(e)
}
if (store)
try {
await prisma.log.create({
data: {
timestamp: now,
level,
tags,
message,
data
}
})
} catch (e) {
console.log(e)
}
}
function logLow({ tags, message, data }) {