Jump to content

Replace \Logger instance


Recommended Posts

Hello,

An object, used by my module had this code :

    private function fetchData($exporter)
    {
        $fetched_data = file_get_contents($exporter->getFetchFullUrl());
        \Logger::addLog("fetching from " . $exporter->getFetchFullUrl(), 1, null, null, null, true);
        return $fetched_data;
    }

But it now throw an exception : UndefinedMethodException on the \Logger line.

 

So I replace it with this code :

public function __construct($definition_class_name)
    {
        $this->logger = new LegacyLogger();
        ...
     }

and

    private function fetchData($exporter)
    {
        $fetched_data = file_get_contents($exporter->getFetchFullUrl());
        $this->logger->info("fetching from " . $exporter->getFetchFullUrl());

        return $fetched_data;
    }

That works fine.

 

However, I'd like to know if this is the correct way to do it. Is it ?

Can I rely on some dependency injection ?

Or rely on (global) Container ?

Link to comment
Share on other sites

I guess using the serviceLocator is a better Option.

 

ServiceLocator::get(LegacyLogger::class);

but finaly, no because it should be removed ( :confused: )

/**
 * @internal
 *
 * To be removed in 1.7.1.
 */
class ServiceLocator
{ ... }

Any idea / guidelines ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...