WC_Logger::__construct( array $handlers = null, string $threshold = null )
Constructor for the logger.
Description Description
Parameters Parameters
- $handlers
-
(Optional) Array of log handlers. If $handlers is not provided, the filter 'woocommerce_register_log_handlers' will be used to define the handlers. If $handlers is provided, the filter will not be applied and the handlers will be used directly.
Default value: null
- $threshold
-
(Optional) Define an explicit threshold. May be configured via WC_LOG_THRESHOLD. By default, all logs will be processed.
Default value: null
Source Source
File: includes/class-wc-logger.php
public function __construct( $handlers = null, $threshold = null ) {
if ( null === $handlers ) {
$handlers = apply_filters( 'woocommerce_register_log_handlers', array() );
}
$register_handlers = array();
if ( ! empty( $handlers ) && is_array( $handlers ) ) {
foreach ( $handlers as $handler ) {
$implements = class_implements( $handler );
if ( is_object( $handler ) && is_array( $implements ) && in_array( 'WC_Log_Handler_Interface', $implements, true ) ) {
$register_handlers[] = $handler;
} else {
wc_doing_it_wrong(
__METHOD__,
sprintf(
/* translators: 1: class name 2: WC_Log_Handler_Interface */
__( 'The provided handler %1$s does not implement %2$s.', 'woocommerce' ),
'<code>' . esc_html( is_object( $handler ) ? get_class( $handler ) : $handler ) . '</code>',
'<code>WC_Log_Handler_Interface</code>'
),
'3.0'
);
}
}
}
// Support the constant as long as a valid log level has been set for it.
if ( null === $threshold ) {
$threshold = Constants::get_constant( 'WC_LOG_THRESHOLD' );
if ( null !== $threshold && ! WC_Log_Levels::is_valid_level( $threshold ) ) {
$threshold = null;
}
}
if ( null !== $threshold ) {
$threshold = WC_Log_Levels::get_level_severity( $threshold );
}
$this->handlers = $register_handlers;
$this->threshold = $threshold;
}