Google\Cloud\Logging\Logger::entry PHP Method

entry() public method

Example: Create an entry with a key/value set of data $entry = $logger->entry(['user' => 'calvin']); Create an entry with a string $entry = $logger->entry('my message'); Create an entry with a severity of EMERGENCY and specifying a resource. $entry = $logger->entry('my message', [ 'severity' => Logger::EMERGENCY, 'resource' => [ 'type' => 'gcs_bucket', 'labels' => [ 'bucket_name' => 'my-bucket' ] ] ]);
See also: https://cloud.google.com/logging/docs/api/reference/rest/Shared.Types/LogEntry LogEntry resource documentation.
public entry ( array | string $data, array $options = [] ) : Entry
$data array | string The data to log. When providing a string the data will be stored as a `textPayload` type. When providing an array the data will be stored as a `jsonPayload` type.
$options array [optional] { Configuration options. @type array $resource The [monitored resource](https://cloud.google.com/logging/docs/api/reference/rest/Shared.Types/MonitoredResource) to associate this log entry with. **Defaults to** type global. @type array $httpRequest Information about the HTTP request associated with this log entry, if applicable. Please see [the API docs](https://cloud.google.com/logging/docs/api/reference/rest/Shared.Types/LogEntry#httprequest) for more information. @type array $labels A set of user-defined (key, value) data that provides additional information about the log entry. @type array $operation Additional information about a potentially long-running operation with which a log entry is associated. Please see [the API docs](https://cloud.google.com/logging/docs/api/reference/rest/Shared.Types/LogEntry#logentryoperation) for more information. @type string|int $severity The severity of the log entry. **Defaults to** `"DEFAULT"`. }
return Entry
    public function entry($data, array $options = [])
    {
        if (!is_array($data) && !is_string($data)) {
            throw new \InvalidArgumentException('$data must be either a string or an array.');
        }
        if (is_array($data)) {
            $options['jsonPayload'] = $data;
        } else {
            $options['textPayload'] = $data;
        }
        if (!array_key_exists('labels', $options) && $this->labels) {
            $options['labels'] = $this->labels;
        }
        return new Entry($options + ['logName' => $this->formattedName, 'resource' => $this->resource]);
    }