AnonSec Shell
Server IP : 185.86.78.101  /  Your IP : 216.73.216.124
Web Server : Apache
System : Linux 675867-vds-valikoshka1996.gmhost.pp.ua 5.4.0-150-generic #167-Ubuntu SMP Mon May 15 17:35:05 UTC 2023 x86_64
User : www ( 1000)
PHP Version : 7.4.33
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /www/wwwroot/mifepriston.org/node_modules/eazy-logger/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /www/wwwroot/mifepriston.org/node_modules/eazy-logger/index.js
/**
 * tFunk for colours/compiler
 */
var tfunk = require("tfunk");

/**
 * Lodash clonedeep & merge
 */
var _ = require("./lodash.custom");

/**
 * Default configuration.
 * Can be overridden in first constructor arg
 */
var defaults = {

    /**
     * Initial log level
     */
    level: "info",

    /**
     * Prefix for logger
     */
    prefix: "",

    /**
     * Available levels and their score
     */
    levels: {
        "trace": 100,
        "debug": 200,
        "warn":  300,
        "info":  400,
        "error": 500
    },

    /**
     * Default prefixes
     */
    prefixes: {
        "trace": "[trace] ",
        "debug": "{yellow:[debug]} ",
        "info":  "{cyan:[info]} ",
        "warn":  "{magenta:[warn]} ",
        "error": "{red:[error]} "
    },

    /**
     * Should easy log statement be prefixed with the level?
     */
    useLevelPrefixes: false
};


/**
 * @param {Object} config
 * @constructor
 */
var Logger = function(config) {

    if (!(this instanceof Logger)) {
        return new Logger(config);
    }

    config = config || {};

    this._mute = false;
    this.config = _.merge({}, defaults, config);
    this.addLevelMethods(this.config.levels);
    this.compiler = new tfunk.Compiler(this.config.custom || {}, this.config);
    this._memo = {};

    return this;
};

/**
 * Set an option once
 * @param path
 * @param value
 */
Logger.prototype.setOnce = function (path, value) {

    if (typeof this.config[path] !== "undefined") {

        if (typeof this._memo[path] === "undefined") {
            this._memo[path] = this.config[path];
        }

        this.config[path] = value;
    }

    return this;
};
/**
 * Add convenience method such as
 * logger.warn("msg")
 * logger.error("msg")
 * logger.info("msg")
 *
 * instead of
 * logger.log("warn", "msg");
 * @param items
 */
Logger.prototype.addLevelMethods = function (items) {
    Object.keys(items).forEach(function (item) {
        if (!this[item]) {
            this[item] = function () {
                var args = Array.prototype.slice.call(arguments);
                this.log.apply(this, args);
                return this;
            }.bind(this, item);
        }
    }, this);
};
/**
 * Reset the state of the logger.
 * @returns {Logger}
 */
Logger.prototype.reset = function () {

    this.setLevel(defaults.level)
        .setLevelPrefixes(defaults.useLevelPrefixes)
        .mute(false);

    return this;
};

/**
 * @param {String} level
 * @returns {boolean}
 */
Logger.prototype.canLog = function (level) {
    return this.config.levels[level] >= this.config.levels[this.config.level] && !this._mute;
};

/**
 * Log to the console with prefix
 * @param {String} level
 * @param {String} msg
 * @returns {Logger}
 */
Logger.prototype.log = function (level, msg) {

    var args = Array.prototype.slice.call(arguments);

    this.logOne(args, msg, level);

    return this;
};

/**
 * Set the log level
 * @param {String} level
 * @returns {Logger}
 */
Logger.prototype.setLevel = function (level) {

    this.config.level = level;

    return this;
};

/**
 * @param {boolean} state
 * @returns {Logger}
 */
Logger.prototype.setLevelPrefixes = function (state) {

    this.config.useLevelPrefixes = state;

    return this;
};

/**
 * @param prefix
 */
Logger.prototype.setPrefix = function (prefix) {
    if (typeof prefix === "string") {
        this.compiler.prefix = this.compiler.compile(prefix, true);
    }
    if (typeof prefix === "function") {
        this.compiler.prefix = prefix;
    }
};

/**
 * @param {String} level
 * @param {String} msg
 * @returns {Logger}
 */
Logger.prototype.unprefixed = function (level, msg) {

    var args = Array.prototype.slice.call(arguments);

    this.logOne(args, msg, level, true);

    return this;
};

/**
 * @param {Array} args
 * @param {String} msg
 * @param {String} level
 * @param {boolean} [unprefixed]
 * @returns {Logger}
 */
Logger.prototype.logOne = function (args, msg, level, unprefixed) {

    if (!this.canLog(level)) {
        return;
    }

    args = args.slice(2);

    if (this.config.useLevelPrefixes && !unprefixed) {
        msg = this.config.prefixes[level] + msg;
    }

    msg = this.compiler.compile(msg, unprefixed);

    args.unshift(msg);

    console.log.apply(console, args);

    this.resetTemps();

    return this;
};

/**
 * Reset any temporary value
 */
Logger.prototype.resetTemps = function () {

    Object.keys(this._memo).forEach(function (key) {
        this.config[key] = this._memo[key];
    }, this);
};

/**
 * Mute the logger
 */
Logger.prototype.mute = function (bool) {

    this._mute = bool;
    return this;
};

/**
 * Clone the instance to share setup
 * @param opts
 * @returns {Logger}
 */
Logger.prototype.clone = function (opts) {

    var config = _.cloneDeep(this.config);

    if (typeof opts === "function") {
        config = opts(config) || {};
    } else {
        config = _.merge({}, config, opts || {});
    }

    return new Logger(config);
};

module.exports.Logger  = Logger;
module.exports.compile = tfunk;

Anon7 - 2022
AnonSec Team