allow slog logs to be disabled/configured
This commit is contained in:
parent
e57c930f0c
commit
6e8d7ef1b8
|
@ -1,3 +1,6 @@
|
||||||
|
PRISMA_SLOW_LOGS_MS=
|
||||||
|
GRAPHQL_SLOW_LOGS_MS=
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
# OPTIONAL SECRETS #
|
# OPTIONAL SECRETS #
|
||||||
# put these in .env.local, and don't commit them to git #
|
# put these in .env.local, and don't commit them to git #
|
||||||
|
|
|
@ -16,4 +16,6 @@ NEXT_PUBLIC_NORMAL_POLL_INTERVAL=30000
|
||||||
NEXT_PUBLIC_LONG_POLL_INTERVAL=60000
|
NEXT_PUBLIC_LONG_POLL_INTERVAL=60000
|
||||||
NEXT_PUBLIC_EXTRA_LONG_POLL_INTERVAL=300000
|
NEXT_PUBLIC_EXTRA_LONG_POLL_INTERVAL=300000
|
||||||
NEXT_PUBLIC_URL=https://stacker.news
|
NEXT_PUBLIC_URL=https://stacker.news
|
||||||
TOR_PROXY=http://127.0.0.1:7050/
|
TOR_PROXY=http://127.0.0.1:7050/
|
||||||
|
PRISMA_SLOW_LOGS_MS=50
|
||||||
|
GRAPHQL_SLOW_LOGS_MS=50
|
|
@ -6,7 +6,7 @@ const prisma = global.prisma || (() => {
|
||||||
log: [{ level: 'query', emit: 'event' }, 'warn', 'error']
|
log: [{ level: 'query', emit: 'event' }, 'warn', 'error']
|
||||||
})
|
})
|
||||||
prisma.$on('query', (e) => {
|
prisma.$on('query', (e) => {
|
||||||
if (e.duration > 50) {
|
if (process.env.PRISMA_SLOW_LOGS_MS && e.duration > process.env.PRISMA_SLOW_LOGS_MS) {
|
||||||
console.log('Query: ' + e.query)
|
console.log('Query: ' + e.query)
|
||||||
console.log('Params: ' + e.params)
|
console.log('Params: ' + e.params)
|
||||||
console.log('Duration: ' + e.duration + 'ms')
|
console.log('Duration: ' + e.duration + 'ms')
|
||||||
|
|
|
@ -26,7 +26,7 @@ const apolloServer = new ApolloServer({
|
||||||
return (error, result) => {
|
return (error, result) => {
|
||||||
const end = process.hrtime.bigint()
|
const end = process.hrtime.bigint()
|
||||||
const ms = (end - start) / 1000000n
|
const ms = (end - start) / 1000000n
|
||||||
if (ms > 50) {
|
if (process.env.GRAPHQL_SLOW_LOGS_MS && ms > process.env.GRAPHQL_SLOW_LOGS_MS) {
|
||||||
console.log(`Field ${info.parentType.name}.${info.fieldName} took ${ms}ms`)
|
console.log(`Field ${info.parentType.name}.${info.fieldName} took ${ms}ms`)
|
||||||
}
|
}
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
Loading…
Reference in New Issue