# Stackdriver Logging Client - Class PsrLogger (2.1.0)

2.1.0 (latest) 2.0.0 1.34.5 1.33.0 1.32.3 1.31.3 1.30.3 1.29.0 1.28.5 1.27.1 1.26.0 1.25.5 1.24.10 Reference documentation and code samples for the Stackdriver Logging Client class PsrLogger.

A PSR-3 compliant logger used to write entries to Google Stackdriver Logging.

Example:

    use Google\Cloud\Logging\LoggingClient;

    $logging = new LoggingClient();

    $psrLogger = $logging->psrLogger('my-log');

    // Write entries with background batching.
    use Google\Cloud\Logging\LoggingClient;

    $logging = new LoggingClient();

    $psrLogger = $logging->psrLogger('my-log', [
        'batchEnabled' => true
    ]);

## Namespace

Google \\ Cloud \\ Logging

## Methods

### __construct

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `logger` | `https://docs.cloud.google.com/php/docs/reference/cloud-logging/latest/Logger` The logger used to write entries. |
| `messageKey` | `string` The key in the `jsonPayload` used to contain the logged message. **Defaults to** `message`. |
| `options` | `array` Configuration options. |
| `↳ metadataProvider` | `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Report.MetadataProviderInterface.html` **Defaults to** An automatically chosen provider, based on detected environment settings. |
| `↳ batchEnabled` | `bool` Determines whether or not to use background batching. **Defaults to** `false`. Note that this option is currently considered **experimental** and is subject to change. |
| `↳ debugOutputResource` | `resource` A resource to output debug output to. |
| `↳ debugOutput` | `bool` Whether or not to output debug information. Please note debug output currently only applies in CLI based applications. **Defaults to** `false`. Applies only when `batchEnabled` is set to `true`. |
| `↳ batchOptions` | `array` A set of options for a BatchJob. [Google\\Cloud\\Core\\Batch\\BatchJob::__construct()](https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Batch.BatchJob.html#_Google_Cloud_Core_Batch_BatchJob____construct__) for more details. **Defaults to** \['batchSize' =\> 1000, 'callPeriod' =\> 2.0, 'numWorkers' =\> 2\]. Applies only when `batchEnabled` is set to `true`. |
| `↳ clientConfig` | `array` Configuration options for the Logging client used to handle processing of batch items. For valid options please see [LoggingClient::__construct()](https://docs.cloud.google.com/php/docs/reference/cloud-logging/latest/LoggingClient#_Google_Cloud_Logging_LoggingClient____construct__). Applies only when `batchEnabled` is set to `true`. |
| `↳ batchRunner` | `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Batch.BatchRunner.html` A BatchRunner object. Mainly used for the tests to inject a mock. **Defaults to** a newly created BatchRunner. Applies only when `batchEnabled` is set to `true`. |
| `↳ closureSerializer` | `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Batch.ClosureSerializerInterface.html` An implementation responsible for serializing closures used in the `$clientConfig`. This is especially important when using the batch daemon. **Defaults to** Google\\Cloud\\Core\\Batch\\OpisClosureSerializer if the `opis/closure` library is installed. |

### emergency

Log an emergency entry.

Example:

    $psrLogger->emergency('emergency message');

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `message` | `string` The message to log. |
| `context` | `array` \[optional\] Please see [PsrLogger::log()](https://docs.cloud.google.com/php/docs/reference/cloud-logging/latest/PsrLogger#_Google_Cloud_Logging_PsrLogger__log__) for the available options. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `void` |   |

### alert

Log an alert entry.

Example:

    $psrLogger->alert('alert message');

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `message` | `string` The message to log. |
| `context` | `array` \[optional\] Please see [PsrLogger::log()](https://docs.cloud.google.com/php/docs/reference/cloud-logging/latest/PsrLogger#_Google_Cloud_Logging_PsrLogger__log__) for the available options. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `void` |   |

### critical

Log a critical entry.

Example:

    $psrLogger->critical('critical message');

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `message` | `string` The message to log. |
| `context` | `array` \[optional\] Please see [PsrLogger::log()](https://docs.cloud.google.com/php/docs/reference/cloud-logging/latest/PsrLogger#_Google_Cloud_Logging_PsrLogger__log__) for the available options. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `void` |   |

### error

Log an error entry.

Example:

    $psrLogger->error('error message');

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `message` | `string` The message to log. |
| `context` | `array` \[optional\] Please see [PsrLogger::log()](https://docs.cloud.google.com/php/docs/reference/cloud-logging/latest/PsrLogger#_Google_Cloud_Logging_PsrLogger__log__) for the available options. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `void` |   |

### warning

Log a warning entry.

Example:

    $psrLogger->warning('warning message');

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `message` | `string` The message to log. |
| `context` | `array` \[optional\] Please see [PsrLogger::log()](https://docs.cloud.google.com/php/docs/reference/cloud-logging/latest/PsrLogger#_Google_Cloud_Logging_PsrLogger__log__) for the available options. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `void` |   |

### notice

Log a notice entry.

Example:

    $psrLogger->notice('notice message');

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `message` | `string` The message to log. |
| `context` | `array` \[optional\] Please see [PsrLogger::log()](https://docs.cloud.google.com/php/docs/reference/cloud-logging/latest/PsrLogger#_Google_Cloud_Logging_PsrLogger__log__) for the available options. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `void` |   |

### info

Log an info entry.

Example:

    $psrLogger->info('info message');

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `message` | `string` The message to log. |
| `context` | `array` \[optional\] Please see [PsrLogger::log()](https://docs.cloud.google.com/php/docs/reference/cloud-logging/latest/PsrLogger#_Google_Cloud_Logging_PsrLogger__log__) for the available options. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `void` |   |

### debug

Log a debug entry.

Example:

    $psrLogger->debug('debug message');

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `message` | `string` The message to log. |
| `context` | `array` \[optional\] Please see [PsrLogger::log()](https://docs.cloud.google.com/php/docs/reference/cloud-logging/latest/PsrLogger#_Google_Cloud_Logging_PsrLogger__log__) for the available options. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `void` |   |

### log

Write a log entry.

Example:

    use Google\Cloud\Logging\Logger;

    $psrLogger->log(Logger::ALERT, 'alert message');

    // Write a log entry using the context array with placeholders.
    use Google\Cloud\Logging\Logger;

    $psrLogger->log(Logger::ALERT, 'alert: {message}', [
        'message' => 'my alert message'
    ]);

    // Log information regarding an HTTP request
    use Google\Cloud\Logging\Logger;

    $psrLogger->log(Logger::ALERT, 'alert message', [
        'stackdriverOptions' => [
            'httpRequest' => [
                'requestMethod' => 'GET'
            ]
        ]
    ]);

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `level` | `string|int` The severity of the log entry. |
| `message` | `string` The message to log. |
| `context` | `array` Context is an associative array which can include placeholders to be used in the `$message`. Placeholders must be delimited with a single opening brace `{` and a single closing brace `}`. The context will be added as additional information on the `jsonPayload`. Please note that the key `stackdriverOptions` is reserved for logging Google Stackdriver specific data. |
| `↳ stackdriverOptions` | `array` \['resource'\] The [monitored resource](https://cloud.google.com/logging/docs/api/reference/rest/v2/MonitoredResource) to associate this log entry with. **Defaults to** type global. |
| `↳ stackdriverOptions` | `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/v2/LogEntry#httprequest) for more information. |
| `↳ stackdriverOptions` | `array` \['labels'\] A set of user-defined (key, value) data that provides additional information about the log entry. |
| `↳ stackdriverOptions` | `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/v2/LogEntry#logentryoperation) for more information. |
| `↳ stackdriverOptions` | `string` \['insertId'\] A unique identifier for the log entry. |
| `↳ stackdriverOptions` | `DateTimeInterface|https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Timestamp.html|string|null` \['timestamp'\] The timestamp associated with this entry. If providing a string it must be in RFC3339 UTC "Zulu" format. Example: "2014-10-02T15:01:23.045123456Z". If explicitly set to `null` the timestamp will be generated by the server at the moment the entry is received (with nanosecond precision). **Defaults to** the current time, generated by the client with microsecond precision. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `void` |   |

### getMetadataProvider

Return the MetadataProvider.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Report.MetadataProviderInterface.html` |   |

### serialize

Serializes data.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### unserialize

Unserializes data.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `data` | `mixed` |

### __serialize

### __unserialize

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `data` | `array` |

## Constants

### ID_TEMPLATE

    Value: 'stackdriver-logging-%s'