33 *
44 * This module provides standardized console logging utilities for internal application logging.
55 * It is separate from the user-facing logging system in logging.ts.
6- *
7- * For Node.js runtime, uses TraceRoot logger for enhanced logging with trace correlation.
8- * For Edge runtime, falls back to console logging to avoid import errors.
96 */
107import chalk from 'chalk'
118import { env } from '@/lib/env'
129
13- // Runtime detection - check if we're in Edge runtime
14- const isEdgeRuntime = ( ) => {
15- return (
16- typeof window !== 'undefined' ||
17- ( typeof globalThis !== 'undefined' && 'EdgeRuntime' in globalThis ) ||
18- typeof process === 'undefined' ||
19- ( typeof process !== 'undefined' && process . env . NEXT_RUNTIME === 'edge' )
20- )
21- }
22-
23- // Conditional TraceRoot import - only in Node runtime
24- let traceRootLogger : any = null
25-
26- if ( ! isEdgeRuntime ( ) ) {
27- try {
28- const traceRoot = require ( 'traceroot-sdk-ts' )
29- traceRootLogger = traceRoot . getLogger
30- } catch ( importError ) {
31- console . warn ( 'TraceRoot SDK not available, falling back to console logging' )
32- }
33- }
34-
3510/**
3611 * LogLevel enum defines the severity levels for logging
3712 *
@@ -133,29 +108,16 @@ const formatObject = (obj: any): string => {
133108 *
134109 * This class provides methods for logging at different severity levels
135110 * and handles formatting, colorization, and environment-specific behavior.
136- * Uses TraceRoot logger in Node runtime and falls back to console logging in Edge runtime.
137111 */
138112export class Logger {
139113 private module : string
140- private traceRootLoggerInstance : any = null
141114
142115 /**
143116 * Create a new logger for a specific module
144117 * @param module The name of the module (e.g., 'OpenAIProvider', 'AgentBlockHandler')
145118 */
146119 constructor ( module : string ) {
147120 this . module = module
148-
149- // Initialize TraceRoot logger instance if available
150- if ( traceRootLogger ) {
151- try {
152- this . traceRootLoggerInstance = traceRootLogger ( module )
153- } catch ( error ) {
154- console . warn (
155- `Failed to create TraceRoot logger for module ${ module } , falling back to console logging`
156- )
157- }
158- }
159121 }
160122
161123 /**
@@ -262,11 +224,7 @@ export class Logger {
262224 * @param args Additional arguments to log
263225 */
264226 debug ( message : string , ...args : any [ ] ) {
265- if ( this . traceRootLoggerInstance ) {
266- this . traceRootLoggerInstance . debug ( message , ...args )
267- } else {
268- this . log ( LogLevel . DEBUG , message , ...args )
269- }
227+ this . log ( LogLevel . DEBUG , message , ...args )
270228 }
271229
272230 /**
@@ -284,11 +242,7 @@ export class Logger {
284242 * @param args Additional arguments to log
285243 */
286244 info ( message : string , ...args : any [ ] ) {
287- if ( this . traceRootLoggerInstance ) {
288- this . traceRootLoggerInstance . info ( message , ...args )
289- } else {
290- this . log ( LogLevel . INFO , message , ...args )
291- }
245+ this . log ( LogLevel . INFO , message , ...args )
292246 }
293247
294248 /**
@@ -305,11 +259,7 @@ export class Logger {
305259 * @param args Additional arguments to log
306260 */
307261 warn ( message : string , ...args : any [ ] ) {
308- if ( this . traceRootLoggerInstance ) {
309- this . traceRootLoggerInstance . warn ( message , ...args )
310- } else {
311- this . log ( LogLevel . WARN , message , ...args )
312- }
262+ this . log ( LogLevel . WARN , message , ...args )
313263 }
314264
315265 /**
@@ -326,11 +276,7 @@ export class Logger {
326276 * @param args Additional arguments to log
327277 */
328278 error ( message : string , ...args : any [ ] ) {
329- if ( this . traceRootLoggerInstance ) {
330- this . traceRootLoggerInstance . error ( message , ...args )
331- } else {
332- this . log ( LogLevel . ERROR , message , ...args )
333- }
279+ this . log ( LogLevel . ERROR , message , ...args )
334280 }
335281}
336282
0 commit comments