Google\Cloud\Logging\V2\LoggingServiceV2Client::writeLogEntries PHP Method

writeLogEntries() public method

Sample code: try { $loggingServiceV2Client = new LoggingServiceV2Client(); $entries = []; $response = $loggingServiceV2Client->writeLogEntries($entries); } finally { if (isset($loggingServiceV2Client)) { $loggingServiceV2Client->close(); } }
public writeLogEntries ( google\logging\v2\LogEntry[] $entries, array $optionalArgs = [] ) : google\logging\v2\WriteLogEntriesResponse
$entries google\logging\v2\LogEntry[] Required. The log entries to write. Values supplied for the fields `log_name`, `resource`, and `labels` in this `entries.write` request are added to those log entries that do not provide their own values for the fields. To improve throughput and to avoid exceeding the [quota limit](/logging/quota-policy) for calls to `entries.write`, you should write multiple log entries at once rather than calling this method for each individual log entry.
$optionalArgs array { Optional. @type string $logName Optional. A default log resource name that is assigned to all log entries in `entries` that do not specify a value for `log_name`: "projects/[PROJECT_ID]/logs/[LOG_ID]" "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]" `[LOG_ID]` must be URL-encoded. For example, `"projects/my-project-id/logs/syslog"` or `"organizations/1234567890/logs/cloudresourcemanager.googleapis.com%2Factivity"`. For more information about log names, see [LogEntry][google.logging.v2.LogEntry]. @type MonitoredResource $resource Optional. A default monitored resource object that is assigned to all log entries in `entries` that do not specify a value for `resource`. Example: { "type": "gce_instance", "labels": { "zone": "us-central1-a", "instance_id": "00000000000000000000" }} See [LogEntry][google.logging.v2.LogEntry]. @type array $labels Optional. Default labels that are added to the `labels` field of all log entries in `entries`. If a log entry already has a label with the same key as a label in this parameter, then the log entry's label is not changed. See [LogEntry][google.logging.v2.LogEntry]. @type bool $partialSuccess Optional. Whether valid entries should be written even if some other entries fail due to INVALID_ARGUMENT or PERMISSION_DENIED errors. If any entry is not written, the response status will be the error associated with one of the failed entries and include error details in the form of WriteLogEntriesPartialErrors. @type \Google\GAX\RetrySettings $retrySettings Retry settings to use for this call. If present, then $timeoutMillis is ignored. @type int $timeoutMillis Timeout to use for this call. Only used if $retrySettings is not set. }
return google\logging\v2\WriteLogEntriesResponse
    public function writeLogEntries($entries, $optionalArgs = [])
    {
        $request = new WriteLogEntriesRequest();
        foreach ($entries as $elem) {
            $request->addEntries($elem);
        }
        if (isset($optionalArgs['logName'])) {
            $request->setLogName($optionalArgs['logName']);
        }
        if (isset($optionalArgs['resource'])) {
            $request->setResource($optionalArgs['resource']);
        }
        if (isset($optionalArgs['labels'])) {
            foreach ($optionalArgs['labels'] as $key => $value) {
                $request->addLabels((new LabelsEntry())->setKey($key)->setValue($value));
            }
        }
        if (isset($optionalArgs['partialSuccess'])) {
            $request->setPartialSuccess($optionalArgs['partialSuccess']);
        }
        $mergedSettings = $this->defaultCallSettings['writeLogEntries']->merge(new CallSettings($optionalArgs));
        $callable = ApiCallable::createApiCall($this->loggingServiceV2Stub, 'WriteLogEntries', $mergedSettings, $this->descriptors['writeLogEntries']);
        return $callable($request, [], ['call_credentials_callback' => $this->createCredentialsCallback()]);
    }