HEX
Server: nginx/1.24.0
System: Linux nowruzgan 6.8.0-57-generic #59-Ubuntu SMP PREEMPT_DYNAMIC Sat Mar 15 17:40:59 UTC 2025 x86_64
User: babak (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: //var/dev/farhangmoaser/web/node_modules/file-stream-rotator/src/helper.ts
import * as fs from "fs"
import path = require("path");

export function makeDirectory(pathWithFile: string) {
    if (pathWithFile.trim() === "") {
        return
    }
    var _path = path.dirname(pathWithFile);
    try {
        fs.mkdirSync(_path, {recursive: true})
    } catch (error: any) {
        if(error.code !== 'EEXIST'){
            throw error;
        }    
    }
}

export class Logger {
    private static instance: Logger
    private constructor(){}
    
    isVerbose: boolean = false
    allowDebug: boolean = false

    static getInstance(verbose?: boolean, debug?: boolean): Logger {
        if (!Logger.instance) {
            Logger.instance = new Logger()
            Logger.instance.isVerbose = verbose ?? false
            Logger.instance.allowDebug = debug ?? false
        }
        return Logger.instance
    }

    static verbose(...args: any) {        
        if (Logger.getInstance().isVerbose) {
            console.log.apply(null, [new Date(), "[FileStreamRotator:VERBOSE]", ...args])
        }
    }

    static log(...args: any) {
        console.log.apply(null, [new Date(), "[FileStreamRotator]", ...args])
    }

    static debug(...args: any) {
        if (Logger.getInstance().allowDebug) {
            console.debug.apply(null, [new Date(), "[FileStreamRotator:DEBUG]", ...args])
        }
    }    
}