From fa22765ec8c32f9bf266b294f827e5406dbea65a Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Thu, 18 Jan 2024 14:05:28 +0100 Subject: [PATCH 1/2] fix: mute system logger in local dev --- src/lib/system_logger.ts | 6 ++++++ test/unit/system_logger.js | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/lib/system_logger.ts b/src/lib/system_logger.ts index a6cc5046..023f0ab2 100644 --- a/src/lib/system_logger.ts +++ b/src/lib/system_logger.ts @@ -1,3 +1,5 @@ +import { env } from 'node:process' + const systemLogTag = '__nfSystemLog' const serializeError = (error: Error): Record => { @@ -28,6 +30,10 @@ class SystemLogger { } private doLog(logger: typeof console.log, message: string) { + if (env.NETLIFY_DEV && !env.NETLIFY_ENABLE_SYSTEM_LOGGING) { + return + } + logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields })) } diff --git a/test/unit/system_logger.js b/test/unit/system_logger.js index 2a1926c7..712dfb28 100644 --- a/test/unit/system_logger.js +++ b/test/unit/system_logger.js @@ -1,3 +1,5 @@ +const process = require("process") + const test = require('ava') const { systemLogger, LogLevel } = require('../../dist/internal') @@ -35,3 +37,23 @@ test('Fields', (t) => { console.log = originalLog }) + +test('Local Dev', (t) => { + const originalLog = console.log + const logs = [] + console.log = (...message) => logs.push(message) + systemLogger.log('hello!') + t.is(logs.length, 1) + + process.env.NETLIFY_DEV= "true" + systemLogger.log('hello!') + t.is(logs.length, 1) + + process.env.NETLIFY_ENABLE_SYSTEM_LOGGING= "true" + systemLogger.log('hello!') + t.is(logs.length, 2) + + delete process.env.NETLIFY_DEV + delete process.env.NETLIFY_ENABLE_SYSTEM_LOGGING + console.log = originalLog +}) From ebac0ad3870439b8295dadc2070fba81cb3387e4 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Fri, 19 Jan 2024 09:52:13 +0100 Subject: [PATCH 2/2] fix: remove node: prefix for node v14 --- src/lib/system_logger.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/system_logger.ts b/src/lib/system_logger.ts index 023f0ab2..80afab13 100644 --- a/src/lib/system_logger.ts +++ b/src/lib/system_logger.ts @@ -1,4 +1,4 @@ -import { env } from 'node:process' +import { env } from 'process' const systemLogTag = '__nfSystemLog'