Closed mohammadsiabbouforwork closed 9 months ago
Hello,
I'm not sure how Log::getLogger()
is configured, but if you create a logger similar to this line, it should just work.
The spec of the logger should be something similar to what is created in this method.
Hey , thanks for your reply,
Log::getLogger()
just returns an instance of a class implementing the LoggerInterface
as defined here.
I even tried to create a simple class to avoid any issues related to Laravel :
use Psr\Log\LoggerInterface;
use Stringable;
class CustomLogger implements LoggerInterface
{
public function emergency(Stringable|string $message, array $context = []): void
{
$this->log('emergency', $message, $context);
}
public function alert(Stringable|string $message, array $context = []): void
{
$this->log('alert', $message, $context);
}
public function critical(Stringable|string $message, array $context = []): void
{
$this->log('critical', $message, $context);
}
public function error(Stringable|string $message, array $context = []): void
{
$this->log('error', $message, $context);
}
public function warning(Stringable|string $message, array $context = []): void
{
$this->log('warning', $message, $context);
}
public function notice(Stringable|string $message, array $context = []): void
{
$this->log('info', $message, $context);
}
public function info(Stringable|string $message, array $context = []): void
{
$this->log('info', $message, $context);
}
public function debug(Stringable|string $message, array $context = []): void
{
$this->log('debug', $message, $context);
}
public function log($level, Stringable|string $message, array $context = []): void
{
file_put_contents("storage/logs", $message . PHP_EOL, FILE_APPEND);
}
}
and used it instead :
$logger = new CustomLogger();
$logger->info("TEST " . time());
$clientBuilder = (new GoogleAdsClientBuilder())
->from($config)
->withOAuth2Credential($oAuth2Credential)
->usingGapicV2Source(true)
->withLogger($logger)
->withLogLevel(LogLevel::DEBUG)
->build();
The "TEST" line shows up in the logs, but the library's logs don't!
Are you sure this has nothing to do with the usingGapicV2Source
?
Sorry for bothering you with this, thanks for your help.
usingGapicV2Source
is completely unrelated. You can just remove it if you wish.
Instead, if you don't set a logger at all, does it return anything?
And you're sure that your query returns a result (not empty result), correct?
if I don't set the logger it still returns results normally, however it won't show the logs , even while specifying a custom logFilePath
.
And yes, I have a fully working API integration class that returns non-empty results.
Could you check if your path has the write permission set properly?
if I don't set the logger it still returns results normally, however it won't show the logs , even while specifying a custom logFilePath.
Is it possible for you to test your code in command prompt?
It should output something if you don't set withLogger
.
Yes, the path has the write permission, I double-checked it. I tried running a script directly, and it doesn't show anything nor log anything when using a custom logger. I have to mention I'm running it in a docker container in case that effects anything.
BTW, do you use REST or gRPC? I ask because logging is supported by gRPC at this moment.
Hi, I double-checked, and it turned it I was using REST API, the documentations said it will use gRPC by default but since I didn't have the extension setup in the container it falls back to REST. I configured gRPC and used it, now the logs are working ok, sorry for bothering you with this, thanks for your help.
No worries. I'm really glad that you could find the cause. :)
Someone should add this to the logging docs! https://developers.google.com/google-ads/api/docs/client-libs/php/logging
The PHP client library conforms to PSR-3 for logging and provides a logger for gRPC calls.
The above sentence is already in the guide, but I'll make it more clear. Thanks for suggestion.
yeah, something like it defaults to rest if the extension is not installed would have been super helpful.
Your question: I'm trying to log requests I send, but it's not logging anything, I'm using Laravel logger :
Here is an example of a call :
i would really appreciate the help, thank you.