@@ -10,6 +10,7 @@ import * as protobuf from 'protobufjs';
1010import { EventEmitter } from 'stream' ;
1111import { FlightClient , FlightInfo , DescriptorType , Ticket } from '../flight' ;
1212import { platform } from '../platform/node' ;
13+ import { Logger } from '../logger' ;
1314
1415const PROTO_PATH = './proto/Flight.proto' ;
1516const PROTO_DOWNLOAD_URL =
@@ -33,9 +34,9 @@ let grpcAvailable = false;
3334/**
3435 * Downloads the Flight.proto file from the remote URL and keeps it in memory
3536 */
36- async function downloadProtoFile ( ) : Promise < string > {
37+ async function downloadProtoFile ( logger ?: Logger ) : Promise < string > {
3738 try {
38- console . log ( '[spice.js] Downloading Flight.proto from remote source...' ) ;
39+ logger ?. info ( '[spice.js] Downloading Flight.proto from remote source...' ) ;
3940 const response = await platform . fetch ( PROTO_DOWNLOAD_URL , {
4041 method : 'GET' ,
4142 headers : { } ,
@@ -48,11 +49,11 @@ async function downloadProtoFile(): Promise<string> {
4849 }
4950
5051 const content = await response . text ( ) ;
51- console . log ( '[spice.js] Flight.proto downloaded successfully' ) ;
52+ logger ?. info ( '[spice.js] Flight.proto downloaded successfully' ) ;
5253
5354 return content ;
5455 } catch ( error : any ) {
55- console . warn ( `[spice.js] Failed to download proto file: ${ error . message } ` ) ;
56+ logger ? .warn ( `[spice.js] Failed to download proto file: ${ error . message } ` ) ;
5657 throw error ;
5758 }
5859}
@@ -61,15 +62,15 @@ async function downloadProtoFile(): Promise<string> {
6162 * Loads proto content from local file or downloads it
6263 * Returns the proto content as a string
6364 */
64- async function loadProtoContent ( ) : Promise < string | null > {
65+ async function loadProtoContent ( logger ?: Logger ) : Promise < string | null > {
6566 // Try local file first
6667 if ( fs . existsSync ( fullProtoPath ) ) {
6768 return fs . readFileSync ( fullProtoPath , 'utf-8' ) ;
6869 }
6970
7071 // Try to download
7172 try {
72- return await downloadProtoFile ( ) ;
73+ return await downloadProtoFile ( logger ) ;
7374 } catch ( error ) {
7475 return null ;
7576 }
@@ -78,7 +79,7 @@ async function loadProtoContent(): Promise<string | null> {
7879/**
7980 * Loads proto definition from content in memory using protobufjs
8081 */
81- function loadProtoFromContent ( content : string ) : any {
82+ function loadProtoFromContent ( content : string , logger ?: Logger ) : any {
8283 try {
8384 // Parse the proto content directly in memory using protobufjs
8485 const root = protobuf . parse ( content , { keepCase : false } ) . root ;
@@ -98,7 +99,10 @@ function loadProtoFromContent(content: string): any {
9899 const arrow = grpc . loadPackageDefinition ( packageDefinition ) . arrow as any ;
99100 return arrow . flight . protocol ;
100101 } catch ( error : any ) {
101- console . log ( '[spice.js] Failed to load proto from content:' , error . message ) ;
102+ logger ?. info (
103+ '[spice.js] Failed to load proto from content:' ,
104+ error . message ,
105+ ) ;
102106 throw error ;
103107 }
104108}
@@ -131,17 +135,20 @@ export class GrpcFlightClient {
131135 private flightTlsEnabled : boolean ;
132136 private initPromise : Promise < void > ;
133137 private useGrpc : boolean = grpcAvailable ;
138+ private logger : Logger ;
134139
135140 constructor (
136141 apiKey : string | undefined ,
137142 flightUrl : string ,
138143 userAgent : string ,
139144 flightTlsEnabled : boolean ,
145+ logger ?: Logger ,
140146 ) {
141147 this . apiKey = apiKey ;
142148 this . flightUrl = flightUrl ;
143149 this . userAgent = userAgent ;
144150 this . flightTlsEnabled = flightTlsEnabled ;
151+ this . logger = logger || new Logger ( true ) ;
145152 this . initPromise = this . initialize ( ) ;
146153 }
147154
@@ -157,7 +164,7 @@ export class GrpcFlightClient {
157164 try {
158165 // Check if we already have proto content in memory
159166 if ( ! protoContent ) {
160- protoContent = await loadProtoContent ( ) ;
167+ protoContent = await loadProtoContent ( this . logger ) ;
161168 }
162169
163170 if ( ! protoContent ) {
@@ -166,7 +173,7 @@ export class GrpcFlightClient {
166173 }
167174
168175 // Load the proto from content
169- const proto = loadProtoFromContent ( protoContent ) ;
176+ const proto = loadProtoFromContent ( protoContent , this . logger ) ;
170177
171178 if ( ! proto ?. FlightService ) {
172179 throw new Error ( 'Invalid proto file structure' ) ;
@@ -176,7 +183,7 @@ export class GrpcFlightClient {
176183 grpcAvailable = true ;
177184 this . useGrpc = true ;
178185 } catch ( error : any ) {
179- console . warn (
186+ this . logger . warn (
180187 `[spice.js] gRPC initialization failed: ${ error . message } . Using HTTP endpoint.` ,
181188 ) ;
182189 this . useGrpc = false ;
0 commit comments