A remote logging package for Automattic based projects. This package provides error tracking and logging capabilities, with support for rate limiting, stack trace formatting, and customizable error filtering.
The WooCommerce Remote Logging package offers the following features:
- Remote error logging with stack trace analysis
- Customizable log severity levels
- Rate limiting to prevent API flooding
- Automatic capture of unhandled errors and promise rejections
- Filtering of errors based on WooCommerce asset paths
- Extensibility through WordPress filters
## Usage
1. Initialize the remote logger at the start of your application. If your plugin depends on WooCommerce plugin, the logger will be initialized in WooCommerce, so you don't need to call this function.
```js
import { init } from '@woocommerce/remote-logging';
init({
errorRateLimitMs: 60000 // Set rate limit to 1 minute
Remote logging is subject to the following conditions:
1.**Remote Logging Enabled**: The package checks `window.wcSettings.isRemoteLoggingEnabled` to determine if the feature should be enabled. The value is set via PHP and passed to JS as a boolean. It requires tracks to be enabled and a few other conditions internally. Please see the [RemoteLogger.php](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/src/Internal/Logging/RemoteLogger.php) for more details.
2.**Non-Development Environment**: It also checks `process.env.NODE_ENV` to ensure logging only occurs in non-development environments.
If either of these conditions are not met (Tracks is not enabled or the environment is development), no logs will be transmitted to the remote server.
## API Reference
-`init(config: RemoteLoggerConfig): void`: Initializes the remote logger with the given configuration.
-`log(severity: LogSeverity, message: string, extraData?: object): Promise<boolean>`: Logs a message with the specified severity and optional extra data.
-`captureException(error: Error, extraData?: object): void`: Captures an error and sends it to the remote API.
For more detailed information about types and interfaces, refer to the source code and inline documentation.