woocommerce-paypal-payments/modules/ppcp-axo/resources/js/Helper/Debug.js
Emili Castells Guasch 11105d913b Run eslint autofix
2024-07-12 12:58:34 +02:00

29 lines
606 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;
if ( ! endpoint ) {
return;
}
fetch( endpoint, {
method: 'POST',
credentials: 'same-origin',
body: JSON.stringify( {
nonce: window.wc_ppcp_axo.ajax.frontend_logger.nonce,
log: {
message,
level,
},
} ),
} ).then( () => {
if ( wpDebug ) {
switch ( level ) {
case 'error':
console.error( `[AXO] ${ message }` );
break;
default:
console.log( `[AXO] ${ message }` );
}
}
} );
}