# Stackdriver Logging Client - Class Logger (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 Logger.

A logger used to write entries to Google Stackdriver Logging.

Example:

    use Google\Cloud\Logging\LoggingClient;

    $logging = new LoggingClient();

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

## Namespace

Google \\ Cloud \\ Logging

## Methods

### __construct

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `connection` | `Connection\Gapic` Represents a connection to Stackdriver Logging. This object is created by LoggingClient, and should not be instantiated outside of this client. |
| `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/reference/v2/rest/v2/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

See also:

- [projects.logs delete API documentation.](https://cloud.google.com/logging/docs/api/reference/rest/v2/projects.logs/delete)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` \[optional\] Configuration Options. |

### entries

See also:

- [Entries list API documentation.](https://cloud.google.com/logging/docs/api/reference/rest/v2/entries/list)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` Configuration options. |
| `↳ filter` | `string` An [advanced logs filter](https://cloud.google.com/logging/docs/view/advanced_filters). |
| `↳ orderBy` | `string` How the results should be sorted. Presently, the only permitted values are `timestamp asc` and `timestamp desc`. **Defaults to** `"timestamp asc"`. |
| `↳ pageSize` | `int` The maximum number of results to return per request. |
| `↳ resultLimit` | `int` Limit the number of results returned in total. **Defaults to** `0` (return all results). |
| `↳ pageToken` | `string` A previously-returned page token used to resume the loading of results from a specific point. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Iterator.ItemIterator.html<https://docs.cloud.google.com/php/docs/reference/cloud-logging/latest/Entry>` |   |

### entry

See also:

- [LogEntry resource documentation.](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `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` Configuration options. |
| `↳ resource` | `array` The [monitored resource](https://cloud.google.com/logging/docs/api/reference/rest/v2/MonitoredResource) to associate this log entry with. **Defaults to** type global. |
| `↳ timestamp` | `DateTimeInterface|https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Timestamp.html|string|null` 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. |
| `↳ severity` | `string|int` The severity of the log entry. **Defaults to** `"DEFAULT"`. |
| `↳ insertId` | `string` A unique identifier for the log entry. |
| `↳ httpRequest` | `array` 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. |
| `↳ labels` | `array` A set of user-defined (key, value) data that provides additional information about the log entry. |
| `↳ operation` | `array` 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. |
| `↳ spanId` | `string` Optional. The span ID within the trace associated with the log entry. For Trace spans, this is the same format that the Trace API v2 uses: a 16-character hexadecimal encoding of an 8-byte array, such as 000000000000004a. |
| `↳ trace` | `string` Optional. Resource name of the trace associated with the log entry, if any. If it contains a relative resource name, the name is assumed to be relative to //tracing.googleapis.com. Example: projects/my-projectid/traces/06796866738c859f2f19b7cfb3214824. |
| `↳ traceSampled` | `bool` True means that the trace resource name in the trace field was sampled for storage in a trace backend. False means that the trace was not sampled for storage when this log entry was written, or the sampling decision was unknown at the time. A non-sampled trace value is still useful as a request correlation identifier. The default is False. |
| `↳ sourceLocation` | `array` Source code location information associated with the log entry, if any. Please see the [API docs](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogEntrySourceLocation) for more information. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-logging/latest/Entry` |   |

### write

See also:

- [Entries write API documentation.](https://cloud.google.com/logging/docs/api/reference/rest/v2/entries/write)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `entry` | `array|string|https://docs.cloud.google.com/php/docs/reference/cloud-logging/latest/Entry` The entry to write to the log. |
| `options` | `array` \[optional\] Please see [Logger::entry()](https://docs.cloud.google.com/php/docs/reference/cloud-logging/latest/Logger#_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

See also:

- [Entries write API documentation.](https://cloud.google.com/logging/docs/api/reference/rest/v2/entries/write)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `entries` | `array<https://docs.cloud.google.com/php/docs/reference/cloud-logging/latest/Entry>` Entries to write to the log. |
| `options` | `array` \[optional\] Configuration Options. |

### name

Returns the logger's name.

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

### static::getLogLevelMap

Returns the log level map.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `array` |   |

## Constants

### EMERGENCY

    Value: 800

### ALERT

    Value: 700

### CRITICAL

    Value: 600

### ERROR

    Value: 500

### WARNING

    Value: 400

### NOTICE

    Value: 300

### INFO

    Value: 200

### DEBUG

    Value: 100

### DEFAULT_LEVEL

    Value: 0