🚚 Move ConsoleLogger to wc-gateway module

This commit is contained in:
Philipp Stracker 2024-08-05 12:54:24 +02:00
parent f69209b91c
commit 3c200e408a
No known key found for this signature in database
3 changed files with 9 additions and 6 deletions

View file

@ -0,0 +1,43 @@
/**
* Helper component to log debug details to the browser console.
*
* A utility class that is used by payment buttons on the front-end, like the GooglePayButton.
*/
export default class ConsoleLogger {
/**
* The prefix to display before every log output.
*
* @type {string}
*/
#prefix = '';
/**
* Whether logging is enabled, disabled by default.
*
* @type {boolean}
*/
#enabled = false;
constructor( ...prefixes ) {
if ( prefixes.length ) {
this.#prefix = `[${ prefixes.join( ' | ' ) }]`;
}
}
set enabled( state ) {
this.#enabled = state;
}
log( ...args ) {
if ( this.#enabled ) {
// eslint-disable-next-line
console.log( this.#prefix, ...args );
}
}
error( ...args ) {
if ( this.#enabled ) {
console.error( this.#prefix, ...args );
}
}
}