AiursoftWeb / Kahla.App

Kahla is a cross-platform business messaging app.
https://www.kahla.app
MIT License
415 stars 85 forks source link

Console.log debug on staging env #922

Open Anduin2017 opened 3 years ago

Anduin2017 commented 3 years ago

What do you suggest us to do?

Since @hv0905 mentioned that console.log is really a nice way for developers to diagnostic issues. I suggest that we can write it more to allow debugging in our staging env.

While when we are doing this approach, I don't suggest to write the following code everywhere:

if (isStaging) {
    console.log('some debug details');
}

But instead, we gonna create a log service.

interface LoggerService {
    log(Logging: any): void; 
}

And implement it with different ways. Like:

class ConsoleLogger : LoggerService {
}

class DummyLogger : LoggerService {
}

And use ConsoleLogger in staging env and DummyLogger in prod env.

if (isStaging) {
    services.Add<ConsoleLogger, LoggerService>();
} else {
    services.Add<DummyLogger, LoggerService>(); // I don't know if Angular dependency injection framework supports that...
}