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 \ LoggingMethods
__construct
logger
messageKey
string
The key in the jsonPayload
used to contain
the logged message. Defaults to message
.
options
array
Configuration options.
↳ metadataProvider
MetadataProviderInterface
Defaults toAn 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 experimentaland 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 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 toa 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');
message
string
The message to log.
context
void
alert
Log an alert entry.
Example:
$psrLogger->alert('alert message');
message
string
The message to log.
context
void
critical
Log a critical entry.
Example:
$psrLogger->critical('critical message');
message
string
The message to log.
context
void
error
Log an error entry.
Example:
$psrLogger->error('error message');
message
string
The message to log.
context
void
warning
Log a warning entry.
Example:
$psrLogger->warning('warning message');
message
string
The message to log.
context
void
notice
Log a notice entry.
Example:
$psrLogger->notice('notice message');
message
string
The message to log.
context
void
info
Log an info entry.
Example:
$psrLogger->info('info message');
message
string
The message to log.
context
void
debug
Log a debug entry.
Example:
$psrLogger->debug('debug message');
message
string
The message to log.
context
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'
]
]
]);
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
↳ 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 tothe current time, generated by the client with microsecond precision.
void
getMetadataProvider
Return the MetadataProvider.
Google\Cloud\Core\Report\MetadataProviderInterface
serialize
Serializes data.
string
unserialize
Unserializes data.
data
mixed
__serialize
__unserialize
data
array
Constants
ID_TEMPLATE
Value: 'stackdriver-logging-%s'