How to use the log4js/lib/date_format.asString function in log4js

To help you get started, we’ve selected a few log4js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github diplomatiegouvfr / hornet-js / hornet-js-utils / src / dateFileSyncAppender.ts View on Github external
public shouldRoll(): boolean {
        let lastTime = this.lastTimeWeWroteSomething,
            thisTime = format.asString(this.pattern, new Date(this.now()));

        debug("DateRollingFileStream.shouldRoll with now = " +
            this.now() + ", thisTime = " + thisTime + ", lastTime = " + lastTime);

        this.lastTimeWeWroteSomething = thisTime;
        this.previousTime = lastTime;

        return thisTime !== lastTime;
    }
github diplomatiegouvfr / hornet-js / hornet-js-utils / src / dateFileSyncAppender.ts View on Github external
this.filename = filename;
        this.options = options || { encoding: "utf8", mode: parseInt("0644", 8), flags: "a" };

        debug("Now is " + now);
        if (pattern && typeof (pattern) === "object") {
            now = options;
            options = pattern;
            pattern = null;
        }
        this.pattern = pattern || ".yyyy-MM-dd";
        this.now = now || Date.now;

        if (fs.existsSync(filename)) {
            let stat = fs.statSync(filename);
            this.lastTimeWeWroteSomething = format.asString(this.pattern, stat.mtime);
        } else {
            this.lastTimeWeWroteSomething = format.asString(this.pattern, new Date(this.now()));
        }

        this.baseFilename = filename;
        this.alwaysIncludePattern = false;

        if (options) {
            if (options.alwaysIncludePattern) {
                this.alwaysIncludePattern = true;
                filename = this.baseFilename + this.lastTimeWeWroteSomething;
            }
            delete options.alwaysIncludePattern;
            if (Object.keys(options).length === 0) {
                options = null;
            }
github diplomatiegouvfr / hornet-js / hornet-js-utils / src / dateFileSyncAppender.ts View on Github external
this.options = options || { encoding: "utf8", mode: parseInt("0644", 8), flags: "a" };

        debug("Now is " + now);
        if (pattern && typeof (pattern) === "object") {
            now = options;
            options = pattern;
            pattern = null;
        }
        this.pattern = pattern || ".yyyy-MM-dd";
        this.now = now || Date.now;

        if (fs.existsSync(filename)) {
            let stat = fs.statSync(filename);
            this.lastTimeWeWroteSomething = format.asString(this.pattern, stat.mtime);
        } else {
            this.lastTimeWeWroteSomething = format.asString(this.pattern, new Date(this.now()));
        }

        this.baseFilename = filename;
        this.alwaysIncludePattern = false;

        if (options) {
            if (options.alwaysIncludePattern) {
                this.alwaysIncludePattern = true;
                filename = this.baseFilename + this.lastTimeWeWroteSomething;
            }
            delete options.alwaysIncludePattern;
            if (Object.keys(options).length === 0) {
                options = null;
            }
        }
        debug("this.now is " + this.now + ", now is " + now);