-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't Control Log Level Easily Across Multiple Requests (Singleton problem) #186
Comments
Just a follow up, this looks to be fixed as of tag 1.9. |
Fixed on 1.9 or not, I'm not even seeing how to manipulate the log level. There are no accessors exposed. |
Can we get a response on this report and/or PR? It would do a lot for confidence from our developers that this SDK is taken seriously. |
@brianmc Can we please have some response or understanding if this will get merged in at some point? Maintaining our own fork is less than ideal. |
Apologies for no updates to this thread in a long time.
|
Thank you for the reply, happy to see progress on this issue. Firstly, the goal of logger injection is testability and flexibility, . Right now you have a $log = \net\authorize\util\LogFactory::getLog('this parameter is never used');
$log->setLogLevel(4); This would modify the singleton in a global scope and could have unintended consequences as we have now potentially changed state that could be unexpected elsewhere. The logger is now global, so if I wanted granularity difference across different method calls, I would have to do state modification to that singleton just before those methods each time, rather than having a logger or two that I inject depending on the needs at the time. This is a contrived example just to show the limitations of the singleton pattern with loggers. Secondly, it is interesting to hear that these controllers are auto-generated. I think with some simple refactoring, we can eliminate the need for those auto-generated classes all together. At this point, we are talking about a major bump for the SDK as these would result in breaking changes for consumers of the SDK. The first step would be to eliminate all of the auto-generated classes as it is an anti-pattern. We would then convert the public function __construct(\net\authorize\api\contract\v1\AnetApiRequestType $request, \net\authorize\api\contract\v1\ANetApiResponseTypeInterface $responseType, Log $logger = null) This would involve switching to the paradigm of coding to an interface as Now inside of the
Honestly, this refactor could go much deeper and across all of this library, so I don't want to tangent too much from the original problem. I am not sure you understand my intention with regards to the method of using $log = new \net\authorize\util\Log();
$log->setLogLevel(Log::ANET_LOG_ERROR); or $log = new \net\authorize\util\Log(Log::ANET_LOG_ERROR);
$log->setDebugLevel(); or even $log->setLevelToError(); and the Log class could do the following: public function setLevelToError()
{
$this->logLevel = self::ANET_LOG_ERROR;
} Conclusion: |
LogFactory is singleton. You can use it for set log level and log file.
Exemple:
|
Yup, I am aware of that. It is not ideal as a singleton though, in case for different requests I would want different log levels. I will rename this issue as I don't think that it is helpful as it stands. |
@gnongsie is there plans for this to become a feature and merged into a release? |
After stepping through the code for
Log.php
I am seeing some code smell.First off, these are global constants in the application. As such if I attempt to set
ANET_LOG_LEVEL
during bootstrapping of the applications I will end up throwing a PHP noitce for the constant already being defined when the class is included later in the application.As such all of these global variables should be member properties and a method of assigning a non-default value would need to be implemented.
Am I missing something, or is there not currently a way to define log level granularity?
The text was updated successfully, but these errors were encountered: