Stackdriver Logging Client - Class PsrLogger (1.30.3)

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 Google\Cloud\Logging\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 MetadataProviderInterface

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() 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 Google\Cloud\Logging\LoggingClient::__construct(). Applies only when batchEnabled is set to true.

↳ batchRunner BatchRunner

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 ClosureSerializerInterface

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 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 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 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 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 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 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 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 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 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 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 for more information.

↳ stackdriverOptions string

['insertId'] A unique identifier for the log entry.

↳ stackdriverOptions DateTimeInterface|Timestamp|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
Google\Cloud\Core\Report\MetadataProviderInterface

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'