This repository was archived by the owner on Jun 9, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ import { env } from 'process'
2+
13const systemLogTag = '__nfSystemLog'
24
35const 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
Original file line number Diff line number Diff line change 1+ const process = require ( "process" )
2+
13const test = require ( 'ava' )
24
35const { 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+ } )
You can’t perform that action at this time.
0 commit comments