0

I have the following code that pushes to cloudwatch:

$this->logger->info('Offer did not have desired reservation status', [
    'message' => 'Offer did not have desired reservation status',
    'context' => 'offer_sync',
    'action' => 'process_result',
    'provider' => 'MyProvider',
    'payload' => [
        'id' => $result->companyid ?? 'unknown',
        'offer' => $rawXmlResult->asXML(),
        'isSpecial' => $special ? 'true' : 'false',
        'reservationStatus' => $result->reservationstatus,
    ],
    'log_level' => 'INFO',
    'timestamp' => time(),
    'extra' => [
        'process' => 'charter-' . ($result->companyid ?? 'unknown'),
    ]
]);

This is the signature of the method (with comments):

 * Interesting events.
 *
 * Example: User logs in, SQL logs.
 *
 * @param string  $message
 * @param mixed[] $context
 *
 * @return void
 */
public function info($message, array $context = array());

This interface is implemented by Monolog.

It creates the following log in AWS:

INFO: Offer did not have desired reservation status 
{
    "message": "Offer did not have desired reservation status",
    "context": "offer_sync",
    "action": "process_result",
    "provider": "MyProvider",
    "payload": {
        "id": "2903",
        "offer": "<resource resourceid=\"2442773770000102903\"/>",
        "isSpecial": "false",
        "reservationStatus": "1"
    },
    "log_level": "INFO",
    "timestamp": 1677164857,
    "extra": {
        "process": "charter-2903"
    }
}
 
{
    "token": "-133d2f52",
    "file": "/srv/src/App/Bundle/SyncBundle/Offer/OfferSync.php",
    "line": 433,
    "class": "App\\Bundle\\SyncBundle\\Offer\\OfferSync",
    "function": "processResult"
}

The issue I have is when I search for something using Cloudwatch Log Group logs, I can find it by doing { $.function = "processResult" }. However, I can't search for something like { $.extra.process = "charter-2903" } - this returns no results.

I have a few questions:

  1. Is that last json block generated by aws itself?
  2. Is there a way to overwrite that last json block?
  3. How would I be able to change my log call to allow me to search on $.extra.process for example?
  4. Is there some different way that I can find records with extra.process = charter-id?
Bird87 ZA
  • 2,313
  • 8
  • 36
  • 69

0 Answers0