Skip to content

Commit f4429db

Browse files
authoredJan 19, 2024
fix: mute system logger in local dev (#458)
Follow-up to #457. The system logger shouldn't be visible in local dev.
1 parent 3392c0b commit f4429db

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
 

‎src/lib/system_logger.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { env } from 'process'
2+
13
const systemLogTag = '__nfSystemLog'
24

35
const serializeError = (error: Error): Record<string, unknown> => {
@@ -28,6 +30,10 @@ class SystemLogger {
2830
}
2931

3032
private doLog(logger: typeof console.log, message: string) {
33+
if (env.NETLIFY_DEV && !env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
34+
return
35+
}
36+
3137
logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }))
3238
}
3339

‎test/unit/system_logger.js

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const process = require("process")
2+
13
const test = require('ava')
24

35
const { systemLogger, LogLevel } = require('../../dist/internal')
@@ -35,3 +37,23 @@ test('Fields', (t) => {
3537

3638
console.log = originalLog
3739
})
40+
41+
test('Local Dev', (t) => {
42+
const originalLog = console.log
43+
const logs = []
44+
console.log = (...message) => logs.push(message)
45+
systemLogger.log('hello!')
46+
t.is(logs.length, 1)
47+
48+
process.env.NETLIFY_DEV= "true"
49+
systemLogger.log('hello!')
50+
t.is(logs.length, 1)
51+
52+
process.env.NETLIFY_ENABLE_SYSTEM_LOGGING= "true"
53+
systemLogger.log('hello!')
54+
t.is(logs.length, 2)
55+
56+
delete process.env.NETLIFY_DEV
57+
delete process.env.NETLIFY_ENABLE_SYSTEM_LOGGING
58+
console.log = originalLog
59+
})

0 commit comments

Comments
 (0)
Please sign in to comment.