90 lines
2.4 KiB
TypeScript
90 lines
2.4 KiB
TypeScript
import { env } from '$env/dynamic/private';
|
|
import { isTruthy } from '$lib/truthyString';
|
|
const { DEV } = import.meta.env;
|
|
|
|
export const enableVerboseLog = isTruthy(env.VERBOSE);
|
|
|
|
/**
|
|
* @deprecated Use the new {@link Logger} class instead.
|
|
*/
|
|
export const log = {
|
|
verbose: (...params: any[]) => {
|
|
if (!enableVerboseLog) {
|
|
return;
|
|
}
|
|
console.debug(new Date().toISOString(), ...params);
|
|
},
|
|
debug: (...params: any[]) => {
|
|
if (!log.isDebugEnabled()) {
|
|
return;
|
|
}
|
|
console.debug(new Date().toISOString(), ...params);
|
|
},
|
|
log: (...params: any[]) => {
|
|
console.log(new Date().toISOString(), ...params);
|
|
},
|
|
info: (...params: any[]) => {
|
|
console.info(new Date().toISOString(), ...params);
|
|
},
|
|
warn: (...params: any[]) => {
|
|
console.warn(new Date().toISOString(), ...params);
|
|
},
|
|
error: (...params: any[]) => {
|
|
console.error(new Date().toISOString(), ...params);
|
|
},
|
|
isDebugEnabled: (): boolean => {
|
|
return DEV;
|
|
}
|
|
};
|
|
|
|
export class Logger {
|
|
public constructor(private name: string) {}
|
|
|
|
public static isDebugEnabled(): boolean {
|
|
return DEV || enableVerboseLog;
|
|
}
|
|
public verbose(...params: any[]) {
|
|
if (!enableVerboseLog) {
|
|
return;
|
|
}
|
|
console.debug(new Date().toISOString(), `- ${this.name} -`, ...params);
|
|
}
|
|
public debug(...params: any[]) {
|
|
if (false && !Logger.isDebugEnabled()) {
|
|
return;
|
|
}
|
|
console.debug(new Date().toISOString(), `- ${this.name} -`, ...params);
|
|
}
|
|
public log(...params: any[]) {
|
|
console.log(new Date().toISOString(), `- ${this.name} -`, ...params);
|
|
}
|
|
public info(...params: any[]) {
|
|
console.info(new Date().toISOString(), `- ${this.name} -`, ...params);
|
|
}
|
|
public warn(...params: any[]) {
|
|
console.warn(new Date().toISOString(), `- ${this.name} -`, ...params);
|
|
}
|
|
public error(...params: any[]) {
|
|
console.error(new Date().toISOString(), `- ${this.name} -`, ...params);
|
|
}
|
|
|
|
public static error(...params: any[]) {
|
|
console.error(new Date().toISOString(), ...params);
|
|
}
|
|
public static debug(...params: any[]) {
|
|
if (!Logger.isDebugEnabled()) {
|
|
return;
|
|
}
|
|
console.debug(new Date().toISOString(), ...params);
|
|
}
|
|
public static log(...params: any[]) {
|
|
console.log(new Date().toISOString(), ...params);
|
|
}
|
|
public static info(...params: any[]) {
|
|
console.info(new Date().toISOString(), ...params);
|
|
}
|
|
public static warn(...params: any[]) {
|
|
console.warn(new Date().toISOString(), ...params);
|
|
}
|
|
}
|