UNPKG

@xbibzlibrary/tiktokscrap

Version:

Powerful TikTok Scraper and Downloader Library

60 lines (48 loc) 1.37 kB
import chalk from 'chalk'; export enum LogLevel { DEBUG = 0, INFO = 1, WARN = 2, ERROR = 3, NONE = 4 } export class Logger { private static instance: Logger; private logLevel: LogLevel = LogLevel.INFO; private constructor() {} public static getInstance(): Logger { if (!Logger.instance) { Logger.instance = new Logger(); } return Logger.instance; } public setLogLevel(level: LogLevel): void { this.logLevel = level; } public debug(message: string, ...args: any[]): void { if (this.logLevel <= LogLevel.DEBUG) { console.log(chalk.gray(`[DEBUG] ${message}`), ...args); } } public info(message: string, ...args: any[]): void { if (this.logLevel <= LogLevel.INFO) { console.log(chalk.blue(`[INFO] ${message}`), ...args); } } public warn(message: string, ...args: any[]): void { if (this.logLevel <= LogLevel.WARN) { console.log(chalk.yellow(`[WARN] ${message}`), ...args); } } public error(message: string, ...args: any[]): void { if (this.logLevel <= LogLevel.ERROR) { console.log(chalk.red(`[ERROR] ${message}`), ...args); } } public success(message: string, ...args: any[]): void { if (this.logLevel <= LogLevel.INFO) { console.log(chalk.green(`[SUCCESS] ${message}`), ...args); } } } export default Logger.getInstance();