Skip to content

Commit e930b4f

Browse files
committed
Change remaining references for console logs
Signed-off-by: Shubham Sharma <[email protected]>
1 parent 2337424 commit e930b4f

File tree

8 files changed

+24
-12
lines changed

8 files changed

+24
-12
lines changed

src/actors/client/ActorClient/ActorClient.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import CommunicationProtocolEnum from '../../../enum/CommunicationProtocol.enum'
1515
import GRPCClient from '../../../implementation/Client/GRPCClient/GRPCClient';
1616
import HTTPClient from '../../../implementation/Client/HTTPClient/HTTPClient';
1717
import IClientActor from '../../../interfaces/Client/IClientActor';
18+
import { Logger } from '../../../logger/Logger';
1819
import { DaprClientOptions } from '../../../types/DaprClientOptions';
1920
import ActorClientGRPC from './ActorClientGRPC';
2021
import ActorClientHTTP from './ActorClientHTTP';
@@ -34,16 +35,18 @@ export default class ActorClient {
3435
this.communicationProtocol = communicationProtocol;
3536
this.options = options;
3637

38+
let logger = new Logger(this.options.loggerOptions);
39+
3740
// Builder
3841
switch (communicationProtocol) {
3942
case CommunicationProtocolEnum.GRPC: {
40-
const client = new GRPCClient(this.daprHost, this.daprPort, this.options);
43+
const client = new GRPCClient(this.daprHost, this.daprPort, this.options, logger);
4144
this.actor = new ActorClientGRPC(client);
4245
break;
4346
}
4447
case CommunicationProtocolEnum.HTTP:
4548
default: {
46-
const client = new HTTPClient(this.daprHost, this.daprPort, this.options);
49+
const client = new HTTPClient(this.daprHost, this.daprPort, this.options, logger);
4750
this.actor = new ActorClientHTTP(client);
4851
break;
4952
}

src/actors/runtime/AbstractActor.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ limitations under the License.
1313

1414
import { Temporal } from "@js-temporal/polyfill";
1515
import DaprClient from "../../implementation/Client/DaprClient";
16+
import { Logger } from "../../logger/Logger";
1617
import ActorId from "../ActorId";
1718
import ActorClient from "../client/ActorClient/ActorClient";
1819
import ActorStateManager from "./ActorStateManager";
@@ -42,6 +43,10 @@ export default abstract class AbstractActor {
4243
private readonly actorClient: ActorClient;
4344
private readonly daprStateProvider: StateProvider;
4445
private readonly actorType: any; // set at constructor level
46+
private readonly logger: Logger;
47+
48+
private readonly LOG_COMPONENT: string = "Actors";
49+
private readonly LOG_AREA: string = "AbstractActor";
4550

4651
/**
4752
* Instantiates a new Actor
@@ -52,7 +57,7 @@ export default abstract class AbstractActor {
5257
constructor(daprClient: DaprClient, id: ActorId) {
5358
this.daprClient = daprClient;
5459
this.actorClient = new ActorClient(daprClient.getDaprHost(), daprClient.getDaprPort(), daprClient.getCommunicationProtocol(), daprClient.getOptions());
55-
60+
this.logger = new Logger(daprClient.getOptions().loggerOptions)
5661
this.id = id;
5762

5863
this.stateManager = new ActorStateManager(this);
@@ -201,7 +206,7 @@ export default abstract class AbstractActor {
201206
}
202207

203208
async receiveReminder(_data: string): Promise<void> {
204-
console.warn(JSON.stringify({
209+
this.logger.warn(this.LOG_COMPONENT, this.LOG_AREA, JSON.stringify({
205210
error: "ACTOR_METHOD_NOT_IMPLEMENTED",
206211
errorMsg: `A reminder was created for the actor with id: ${this.id} but the method 'receiveReminder' was not implemented`,
207212
}));

src/actors/runtime/ActorManager.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ export default class ActorManager<T extends AbstractActor> {
8787

8888
async getActiveActor(actorId: ActorId): Promise<T> {
8989
if (!this.actors.has(actorId.getId())) {
90-
// console.log(`Doesn't have active actor (${actorId.getId()}), activating it`);
9190
await this.activateActor(actorId);
9291
}
9392

src/implementation/Client/DaprClient.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ export default class DaprClient {
7373
readonly configuration: IClientConfiguration;
7474
readonly actor: IClientActorBuilder;
7575

76+
private readonly LOG_COMPONENT: string = "DaprClient";
77+
private readonly LOG_AREA: string = "DaprClient";
78+
7679
constructor(
7780
daprHost?: string
7881
, daprPort?: string
@@ -145,9 +148,9 @@ export default class DaprClient {
145148
let isHealthyRetryCount = 0;
146149
const isHealthyMaxRetryCount = 60; // 1s startup delay and we try max for 60s
147150

148-
console.log(`[Dapr-JS][Client] Awaiting Sidecar to be Started`);
151+
this.logger.info(this.LOG_COMPONENT, this.LOG_AREA, `Awaiting Sidecar to be Started`);
149152
while (!isHealthy) {
150-
console.log(`[Dapr-JS][Client] Waiting till Dapr Sidecar Started (#${isHealthyRetryCount})`);
153+
this.logger.verbose(this.LOG_COMPONENT, this.LOG_AREA,`Waiting for the Dapr Sidecar to start, retry count: (#${isHealthyRetryCount})`);
151154
await NodeJSUtils.sleep(Settings.getDaprSidecarPollingDelayMs());
152155

153156
// Implement API call manually as we need to enable calling without initialization
@@ -174,7 +177,7 @@ export default class DaprClient {
174177
await this.awaitSidecarStarted();
175178
await this.daprClient.start();
176179
await this.daprClient.setIsInitialized(true);
177-
console.log(`[Dapr-JS][Client] Sidecar Started`);
180+
this.logger.info(this.LOG_COMPONENT, this.LOG_AREA, "Sidecar Started");
178181
}
179182

180183
getDaprClient(): IClient {

src/implementation/Client/GRPCClient/GRPCClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export default class GRPCClient implements IClient {
8585
return new Promise((resolve, reject) => {
8686
this.client.waitForReady(deadline, (err?) => {
8787
if (err) {
88-
console.error(err);
88+
this.logger.error(this.LOG_COMPONENT, this.LOG_AREA, `Error waiting for client to be ready: ${err}`);
8989
return reject();
9090
}
9191

src/implementation/Client/HTTPClient/HTTPClient.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ export default class HTTPClient implements IClient {
162162

163163
this.logger.debug(this.LOG_COMPONENT, this.LOG_AREA, `Fetching ${params.method} ${urlFull} with body: (${params.body})`);
164164

165-
// console.log(`${params.method} - ${urlFull} (${params.body})`);
166165
const res = await fetch(urlFull, params);
167166

168167
// Parse body

src/implementation/Server/DaprServer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ export default class DaprServer {
5151
readonly actor: IServerActor;
5252
readonly client: DaprClient;
5353

54+
private readonly LOG_COMPONENT: string = "DaprServer";
55+
private readonly LOG_AREA: string = "DaprServer";
56+
5457
constructor(
5558
serverHost?: string
5659
, serverPort?: string
@@ -117,7 +120,7 @@ export default class DaprServer {
117120
await this.client.start();
118121

119122
// We are initialized
120-
console.log(`[Dapr-JS][Server] Sidecar Started`);
123+
this.logger.info(this.LOG_COMPONENT, this.LOG_AREA, "Sidecar Started");
121124
}
122125

123126
async stop(): Promise<void> {

src/implementation/Server/HTTPServer/pubsub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default class HTTPServerPubSub implements IServerPubSub {
5353
}
5454

5555
// Let Dapr know that the message was processed correctly
56-
// console.log(`[Dapr API][PubSub][route-${topic}] Ack'ing the message`);
56+
this.logger.debug(this.LOG_COMPONENT, this.LOG_AREA, `[route-${topic}] Ack'ing the message`);
5757
return res.send({ success: true });
5858
});
5959
}

0 commit comments

Comments
 (0)