diff --git a/docs/platforms/php/common/configuration/options.mdx b/docs/platforms/php/common/configuration/options.mdx index 1fb8585c28bba..f000c3fa44c8a 100644 --- a/docs/platforms/php/common/configuration/options.mdx +++ b/docs/platforms/php/common/configuration/options.mdx @@ -211,6 +211,20 @@ This function is called with an SDK-specific check-in event object, and can retu +## Logs Options + + + +This option enables the logging integration, which allows the SDK to capture logs and send them to Sentry. This is disabled by default. + + + + + +This function is called with an SDK-specific log object, and can return a modified log event object, or `null` to skip reporting the event. + + + ## Transport Options Transports are used to send events to Sentry. Transports can be customized to some degree to better support highly specific deployments. diff --git a/docs/platforms/php/common/logs/index.mdx b/docs/platforms/php/common/logs/index.mdx new file mode 100644 index 0000000000000..2f1ffb4d99b40 --- /dev/null +++ b/docs/platforms/php/common/logs/index.mdx @@ -0,0 +1,32 @@ +--- +title: Set Up Logs +sidebar_title: Logs +description: "Structured logs allow you to send, view and query logs sent from your applications within Sentry." +sidebar_order: 5600 +--- + + + +With Sentry Structured Logs, you can send text based log information from your applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes. + + + +Let us know what you would like to see on GitHub: [Laravel Logs](https://github.com/getsentry/sentry-php/issues/999) or [Symfony Logs](https://github.com/getsentry/sentry-symfony/issues/925). + + + +## Requirements + + + +## Setup + + + +## Usage + + + +## Options + + diff --git a/docs/product/explore/logs/getting-started/index.mdx b/docs/product/explore/logs/getting-started/index.mdx index e153c22f2ab2f..a94e2585ebb2d 100644 --- a/docs/product/explore/logs/getting-started/index.mdx +++ b/docs/product/explore/logs/getting-started/index.mdx @@ -194,6 +194,14 @@ To set up Sentry Logs, use the links below for supported SDKs. After it's been s url="/platforms/dart/guides/flutter/logs/" /> +### PHP + +- + ### Python - - '___PUBLIC_DSN___', + // Enable logs to be sent to Sentry + 'enable_logs' => true, + 'before_send_log' => function (\Sentry\Logs\Log $log): ?\Sentry\Logs\Log { + if ($log->getLevel() === \Sentry\Logs\LogLevel::info()) { + // Filter out all info logs + return null; + } + + return $log; + }, +]); +``` + +The `before_send_log` function receives a log object, and should return the log object if you want it to be sent to Sentry, or `null` if you want to discard it. diff --git a/platform-includes/logs/requirements/php.mdx b/platform-includes/logs/requirements/php.mdx new file mode 100644 index 0000000000000..204c1536d79be --- /dev/null +++ b/platform-includes/logs/requirements/php.mdx @@ -0,0 +1 @@ +Logs for PHP are supported in Sentry PHP SDK version `4.12.0` and above. diff --git a/platform-includes/logs/setup/php.mdx b/platform-includes/logs/setup/php.mdx new file mode 100644 index 0000000000000..ed415e288aab0 --- /dev/null +++ b/platform-includes/logs/setup/php.mdx @@ -0,0 +1,12 @@ +To enable logging, you need to initialize the SDK with the `enable_logs` option set to `true`. + +```php +\Sentry\init([ + 'dsn' => '___PUBLIC_DSN___', + // Enable logs to be sent to Sentry + 'enable_logs' => true, +]); + +// Somewhere at the end of you execution, you should flush the logger to send pending logs to Sentry. +\Sentry\logger()->flush(); +``` diff --git a/platform-includes/logs/usage/php.mdx b/platform-includes/logs/usage/php.mdx new file mode 100644 index 0000000000000..927f6c1868825 --- /dev/null +++ b/platform-includes/logs/usage/php.mdx @@ -0,0 +1,19 @@ +Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the `logger()` function. + +The `logger()` function exposes six methods that you can use to log messages at different log levels: `trace`, `debug`, `info`, `warn`, `error`, and `fatal`. + +You can pass additional attributes directly to the logging functions. These properties will be sent to Sentry, and can be searched from within the Logs UI, and even added to the Logs views as a dedicated column. + +```php +\Sentry\logger()->info('A simple log message'); +\Sentry\logger()->info('A message with a parameter that says %s', values: ['hello']); +\Sentry\logger()->warn('This is a warning log with attributes.', attributes: [ + 'attribute1' => 'string', + 'attribute2' => 1, + 'attribute3' => 1.0, + 'attribute4' => true, +]); + +// Somewhere at the end of you execution, you should flush the logger to send pending logs to Sentry. +\Sentry\logger()->flush(); +```