diff --git a/src/client/API.ts b/src/client/API.ts index 39f77be..a258b5c 100644 --- a/src/client/API.ts +++ b/src/client/API.ts @@ -16,7 +16,7 @@ import { debuglog } from 'node:util'; import { AsyncLocalStorage } from 'node:async_hooks'; import { Metadata } from '@grpc/grpc-js'; -import { KV, RequestWithMeta, Map } from '../types/common'; +import { KV, RequestWithMeta, Map, Logger } from '../types/common'; import { mergeMetadataToMap } from '../utils'; const debug = debuglog('layotto:client:api'); @@ -24,7 +24,7 @@ const debug = debuglog('layotto:client:api'); export type CreateMetadataHook = (localStorage?: AsyncLocalStorage) => Record; export interface APIOptions { - logger?: Console; + logger?: Logger; localStorage?: AsyncLocalStorage; /** * Setting more request metadata here, e.g.: tracing headers @@ -34,7 +34,7 @@ export interface APIOptions { export class API { protected readonly localStorage?: AsyncLocalStorage; - protected readonly logger: Console; + protected readonly logger: Logger; #createMetadataHook?: CreateMetadataHook; constructor(options?: APIOptions) { diff --git a/src/client/Client.ts b/src/client/Client.ts index e7ba5c1..e55ae32 100644 --- a/src/client/Client.ts +++ b/src/client/Client.ts @@ -31,6 +31,7 @@ import { Binding } from './Binding'; import { Oss, OssOptions } from './Oss'; import { Cryption, CryptionOptions } from './Cryption'; import type { CreateMetadataHook } from './API'; +import { Logger } from '../types/common'; const debug = debuglog('layotto:client:main'); @@ -38,7 +39,7 @@ export interface ClientOptions { ossEnable?: boolean; oss?: OssOptions; cryption?: CryptionOptions; - logger?: Console; + logger?: Logger; localStorage?: AsyncLocalStorage; createMetadataHook?: CreateMetadataHook; } @@ -47,7 +48,7 @@ export class Client { readonly host: string; readonly port: string; protected readonly localStorage?: AsyncLocalStorage; - protected readonly logger: Console; + protected readonly logger: Logger; protected readonly createMetadataHook?: CreateMetadataHook; protected readonly _runtime: RuntimeClient; private readonly _address: string; diff --git a/src/server/GRPCServerImpl.ts b/src/server/GRPCServerImpl.ts index 852ba6d..b88956b 100644 --- a/src/server/GRPCServerImpl.ts +++ b/src/server/GRPCServerImpl.ts @@ -26,11 +26,12 @@ import { } from '../../proto/runtime/v1/appcallback_pb'; import { PubSubCallback, TopicEventRequest } from '../types/PubSub'; import { convertMapToKVString, mergeMetadataToMap } from '../utils'; +import { Logger } from '../types/common'; const debug = debuglog('layotto:server:grpc'); export interface GRPCServerOptions { - logger?: Console; + logger?: Logger; localStorage?: AsyncLocalStorage; } @@ -40,7 +41,7 @@ export class GRPCServerImpl implements IAppCallbackServer { protected readonly handlersTopics: Record = {}; protected readonly subscriptionsList: TopicSubscription[] = []; protected readonly localStorage?: AsyncLocalStorage; - protected readonly logger: Console; + protected readonly logger: Logger; constructor(options?: GRPCServerOptions) { this.logger = options?.logger ?? global.console; diff --git a/src/server/Server.ts b/src/server/Server.ts index 5046287..978864d 100644 --- a/src/server/Server.ts +++ b/src/server/Server.ts @@ -19,11 +19,12 @@ import { ServerCredentials, Server as GRPCServer } from '@grpc/grpc-js'; import { AppCallbackService } from '../../proto/runtime/v1/appcallback_grpc_pb'; import { GRPCServerImpl } from './GRPCServerImpl'; import { PubSub } from './PubSub'; +import { Logger } from '../types/common'; const debug = debuglog('layotto:server:main'); export interface ServerOptions { - logger?: Console; + logger?: Logger; localStorage?: AsyncLocalStorage; } @@ -31,7 +32,7 @@ export class Server { readonly port: string; readonly pubsub: PubSub; protected readonly localStorage?: AsyncLocalStorage; - protected readonly logger: Console; + protected readonly logger: Logger; private readonly _serverImpl: GRPCServerImpl; private readonly _server: GRPCServer; #start = false; diff --git a/src/types/common.ts b/src/types/common.ts index 2bba43e..c7828fc 100644 --- a/src/types/common.ts +++ b/src/types/common.ts @@ -34,3 +34,9 @@ export function convertArrayToKVString(items: [string, string][]) { } return kv; } + +export interface Logger { + info(message?: any, ...optionalParams: any[]): void; + warn(message?: any, ...optionalParams: any[]): void; + error(message?: any, ...optionalParams: any[]): void; +}