@@ -33,21 +33,19 @@ export interface LoggerConfig {
3333 enabled ?: boolean
3434}
3535
36- /**
37- * Get environment variable value
38- * Works in any JavaScript runtime (Node.js, Bun, etc.)
39- */
40- const getEnvVar = ( key : string ) : string | undefined => {
36+ const getNodeEnv = ( ) : string => {
4137 if ( typeof process !== 'undefined' && process . env ) {
42- return process . env [ key ]
38+ return process . env . NODE_ENV || 'development'
4339 }
44- return undefined
40+ return 'development'
4541}
4642
47- /**
48- * Get the current environment (development, production, test)
49- */
50- const getNodeEnv = ( ) : string => getEnvVar ( 'NODE_ENV' ) || 'development'
43+ const getLogLevel = ( ) : string | undefined => {
44+ if ( typeof process !== 'undefined' && process . env ) {
45+ return process . env . LOG_LEVEL
46+ }
47+ return undefined
48+ }
5149
5250/**
5351 * Get the minimum log level from environment variable or use defaults
@@ -56,7 +54,7 @@ const getNodeEnv = (): string => getEnvVar('NODE_ENV') || 'development'
5654 * - Test: ERROR (only show errors in tests)
5755 */
5856const getMinLogLevel = ( ) : LogLevel => {
59- const logLevelEnv = getEnvVar ( 'LOG_LEVEL' )
57+ const logLevelEnv = getLogLevel ( )
6058 if ( logLevelEnv && Object . values ( LogLevel ) . includes ( logLevelEnv as LogLevel ) ) {
6159 return logLevelEnv as LogLevel
6260 }
@@ -120,7 +118,6 @@ const formatObject = (obj: unknown, isDev: boolean): string => {
120118 stack : isDev ? obj . stack : undefined ,
121119 name : obj . name ,
122120 }
123- // Copy any additional enumerable properties from the error
124121 for ( const key of Object . keys ( obj ) ) {
125122 if ( ! ( key in errorObj ) ) {
126123 errorObj [ key ] = ( obj as unknown as Record < string , unknown > ) [ key ]
@@ -181,7 +178,6 @@ export class Logger {
181178 private shouldLog ( level : LogLevel ) : boolean {
182179 if ( ! this . config . enabled ) return false
183180
184- // In production, only log on server-side (where window is undefined)
185181 if ( getNodeEnv ( ) === 'production' && typeof window !== 'undefined' ) {
186182 return false
187183 }
0 commit comments