gnikyt / Basic-Shopify-API

A simple API wrapper for Shopify using Guzzle for REST and GraphQL
MIT License
220 stars 66 forks source link

Unsure how to use setLogger #36

Closed fbunadi closed 4 years ago

fbunadi commented 5 years ago

Hi,

I'm not sure how to use $api->setLogger function so it will write into Laravel log files. I'm trying to get the errors->exception from the rest response and I see that the api class already logs it so I tried to use setLogger however I don't see it created the file.

Most likely, I set it up incorrectly.

This is my code:

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('shopify');
        $logger->pushHandler(new StreamHandler(storage_path('logs/flagged-order.log'), Logger::WARNING));
        $this->shop->api()->setLogger($logger);

Here's the api response:

{#6643 ▼
  +"response": Response {#6640 ▼
    -reasonPhrase: "Bad Request"
    -statusCode: 400
    -headers: array:29 [▶]
    -headerNames: array:29 [▶]
    -protocol: "1.1"
    -stream: Stream {#6638 ▶}
  }
  +"errors": {#6634 ▼
    +"status": 400
    +"body": {#261 ▼
      +"errors": {#6637 ▼
        +"page_info": "Invalid value."
      }
    }
    +"exception": ClientException {#6641 ▶}
  }
  +"body": ""
  +"timestamps": array:2 [▶]

Please help. Thanks :)

gnikyt commented 5 years ago

Sorry, will look into this.

The logger only logs some debug items, it does not capture full responses.

I'll see whats up.. but should accept any PSR compatible logger and "work" in my previous testing.

gnikyt commented 5 years ago

Yes... so the logger is only for debug purposes, it does not catch "errors" param and shoot it to the logs... I will adjust it so it does!

fbunadi commented 5 years ago

Thanks!