PHP Class Google\Cloud\Logging\Logger

Example: use Google\Cloud\ServiceBuilder; $cloud = new ServiceBuilder(); $logging = $cloud->logging(); $logger = $logging->logger('my-log');
Datei anzeigen Open project: GoogleCloudPlatform/gcloud-php Class Usage Examples

Protected Properties

Property Type Description
$connection Represents a connection to Stackdriver Logging.

Public Methods

Method Description
__construct ( Google\Cloud\Logging\Connection\ConnectionInterface $connection, string $name, string $projectId, array $resource = null, array $labels = null )
delete ( array $options = [] ) Deletes this log and all its log entries. The log will reappear if it receives new entries.
entries ( array $options = [] ) : Generator Fetches entries scoped to the selected log.
entry ( array | string $data, array $options = [] ) : Entry Creates an entry which which can be written to a log. In order to write the entry to the log please use {@see Google\Cloud\Logging\Logger::write()} or {@see Google\Cloud\Logging\Logger::writeBatch()}.
getLogLevelMap ( ) Returns the log level map.
write ( array | string | Entry $entry, array $options = [] ) Write a single entry to the log.
writeBatch ( array $entries, array $options = [] ) Write a set of entries to the log.

Method Details

__construct() public method

public __construct ( Google\Cloud\Logging\Connection\ConnectionInterface $connection, string $name, string $projectId, array $resource = null, array $labels = null )
$connection Google\Cloud\Logging\Connection\ConnectionInterface Represents a connection to Stackdriver Logging.
$name string The name of the log to write entries to.
$projectId string The project's ID.
$resource array [optional] The [monitored resource](https://cloud.google.com/logging/docs/api/reference/rest/Shared.Types/MonitoredResource) to associate log entries with. **Defaults to** type global.
$labels array [optional] A set of user-defined (key, value) data that provides additional information about the log entries.

delete() public method

Example: $logger->delete();
See also: https://cloud.google.com/logging/docs/api/reference/rest/v2/projects.logs/delete projects.logs delete API documentation.
public delete ( array $options = [] )
$options array [optional] Configuration Options.

entries() public method

Please note that a default filter specifying the logName will be applied for you. Example: $entries = $logger->entries(); foreach ($entries as $entry) { echo $entry->info()['textPayload'] . PHP_EOL; } Use an advanced logs filter to fetch only entries with a specific payload. $entries = $logger->entries([ 'filter' => 'textPayload = "hello world"' ]); foreach ($entries as $entry) { echo $entry->info()['textPayload'] . PHP_EOL; }
See also: https://cloud.google.com/logging/docs/api/reference/rest/v2/entries/list Entries list API documentation.
public entries ( array $options = [] ) : Generator
$options array [optional] { Configuration options. @type string $filter An [advanced logs filter](https://cloud.google.com/logging/docs/view/advanced_filters). @type string $orderBy How the results should be sorted. Presently, the only permitted values are `timestamp asc` and `timestamp desc`. **Defaults to** `"timestamp asc"`. @type int $pageSize The maximum number of results to return per request. }
return Generator

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

getLogLevelMap() public static method

Returns the log level map.
public static getLogLevelMap ( )

write() public method

Example: Writing a simple log entry. $logger->write('a log entry'); Writing a simple entry with a key/value set of data and a severity of EMERGENCY. $logger->write(['user' => 'calvin'], [ 'severity' => Logger::EMERGENCY ]); Using the entry factory method to write a log entry. $entry = $logger->entry('a log entry'); $logger->write($entry);
See also: https://cloud.google.com/logging/docs/api/reference/rest/v2/entries/write Entries write API documentation.
public write ( array | string | Entry $entry, array $options = [] )
$entry array | string | Entry The entry to write to the log.
$options array [optional] Please see {@see \Google\Cloud\Logging\Logger::entry()} to see the options that can be applied to a log entry. Please note that if the provided entry is of type `Entry` these options will overwrite those that may already be set on the instance.

writeBatch() public method

Example: $entries = []; $entries[] = $logger->entry('my message'); $entries[] = $logger->entry('my second message'); $logger->writeBatch($entries);
See also: https://cloud.google.com/logging/docs/api/reference/rest/v2/entries/write Entries write API documentation.
public writeBatch ( array $entries, array $options = [] )
$entries array Entries to write to the log.
$options array [optional] Configuration Options.

Property Details

$connection protected_oe property

Represents a connection to Stackdriver Logging.
protected $connection