mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
31 lines
661 B
JavaScript
31 lines
661 B
JavaScript
export function log( message, level = 'info' ) {
|
|
const wpDebug = window.wc_ppcp_axo?.wp_debug;
|
|
const endpoint = window.wc_ppcp_axo?.ajax?.frontend_logger?.endpoint;
|
|
const loggingEnabled = window.wc_ppcp_axo?.logging_enabled;
|
|
|
|
if ( wpDebug ) {
|
|
switch ( level ) {
|
|
case 'error':
|
|
console.error( `[AXO] ${ message }` );
|
|
break;
|
|
default:
|
|
console.log( `[AXO] ${ message }` );
|
|
}
|
|
}
|
|
|
|
if ( ! endpoint || ! loggingEnabled ) {
|
|
return;
|
|
}
|
|
|
|
fetch( endpoint, {
|
|
method: 'POST',
|
|
credentials: 'same-origin',
|
|
body: JSON.stringify( {
|
|
nonce: window.wc_ppcp_axo.ajax.frontend_logger.nonce,
|
|
log: {
|
|
message,
|
|
level,
|
|
},
|
|
} ),
|
|
} );
|
|
}
|