Tone.js/Tone/core/util/Debug.ts

43 lines
733 B
TypeScript
Raw Normal View History

/**
2019-09-14 20:39:18 +00:00
* Assert that the statement is true, otherwise invoke an error with the given message.
*/
export function assert(statement: boolean, error: string): void {
if (!statement) {
throw new Error(error);
}
}
/**
* A basic logging interface
*/
interface Logger {
log: (args?: any[]) => void;
warn: (args?: any[]) => void;
}
/**
* The default logger is the console
*/
let defaultLogger: Logger = console;
/**
* Set the logging interface
*/
2019-09-20 21:49:54 +00:00
export function setLogger(logger: Logger): void {
defaultLogger = logger;
}
/**
* Log anything
*/
export function log(...args: any[]): void {
defaultLogger.log(...args);
}
/**
* Warn anything
*/
export function warn(...args: any[]): void {
defaultLogger.warn(...args);
}