mirror of
https://github.com/Wessel/pikmin.git
synced 2026-06-06 02:55:47 +02:00
types
This commit is contained in:
@@ -9,7 +9,7 @@ const pikmin = new Pikmin.instance({
|
||||
]
|
||||
});
|
||||
|
||||
pikmin.addTransport(new Pikmin.ConsoleTransport({ process: process, name: 'error', format: `${Pikmin.colors.red('%l')}`, defaults: {} }));
|
||||
pikmin.addTransport(new Pikmin.ConsoleTransport({ process: process, name: 'error', format: `${Pikmin.colors.red('%l')} `, defaults: {} }));
|
||||
Pikmin.bind(pikmin, console);
|
||||
|
||||
pikmin.info(Symbol.iterator);
|
||||
|
||||
@@ -6,11 +6,11 @@ exports.bind = (logger, log = console, specific = false) => {
|
||||
if (log && !specific) log.pikmin = {};
|
||||
|
||||
if (type(logger) === 2) {
|
||||
if (!logger.name && !logger.transports && !logger.log) throw new PikminError('The logger you\'ve provided isn\'t valid');
|
||||
if (!logger.name && !logger.transports && !logger.__log__) throw new PikminError('The logger you\'ve provided isn\'t valid');
|
||||
|
||||
Pikmin.loggers.get(logger.name).__bound__ = log;
|
||||
if (log && !specific) log.pikmin = Object.assign(log.pikmin, logger.log);
|
||||
else if (specific) log = Object.assign(log, logger.log);
|
||||
if (log && !specific) log.pikmin = Object.assign(log.pikmin, logger.__log__);
|
||||
else if (specific) log = Object.assign(log, logger.__log__);
|
||||
} else {
|
||||
if (!Pikmin.loggers.has(logger)) throw new PikminError('The logger you\'ve provided isn\'t valid');
|
||||
|
||||
@@ -24,7 +24,7 @@ exports.bind = (logger, log = console, specific = false) => {
|
||||
|
||||
exports.unbind = (logger, global = true) => {
|
||||
if (type(logger) === 2) {
|
||||
if (!logger.name && !logger.transports && !logger.log) throw new PikminError('The logger you\'ve provided isn\'t valid');
|
||||
if (!logger.name && !logger.transports && !logger.__log__) throw new PikminError('The logger you\'ve provided isn\'t valid');
|
||||
|
||||
const log = Pikmin.loggers.get(logger.name);
|
||||
if (global && log.__bound__) {
|
||||
|
||||
@@ -14,9 +14,9 @@ module.exports = class PikminInstance {
|
||||
* @returns {ThisType} The pikmin instance created
|
||||
*/
|
||||
constructor(options = { autogen: false }) {
|
||||
this.log = {};
|
||||
this.__log__ = {};
|
||||
this.name = this._stringify(options.name || 'main');
|
||||
this.baseFormat = this._stringify(options.format || '[%h:%m:%s] %l ->');
|
||||
this.baseFormat = options.format !== null ? this._stringify(options.format || '[%h:%m:%s] %l -> ') : '';
|
||||
this.transports = [];
|
||||
|
||||
if (type(this.name) !== 0) throw new PikminError(`"options.name" must be type of string but received type ${typeof this.name}`);
|
||||
@@ -41,7 +41,7 @@ module.exports = class PikminInstance {
|
||||
this.transports.push(transport);
|
||||
if (transport.name) {
|
||||
this[transport.name] = (msg, options) => this._print(msg, Object.assign(transport.defaults, options), transport.name, transport.format || this.baseFormat);
|
||||
this.log[transport.name] = (msg, options) => this._print(msg, Object.assign(transport.defaults, options), transport.name, transport.format || this.baseFormat);
|
||||
this.__log__[transport.name] = (msg, options) => this._print(msg, Object.assign(transport.defaults, options), transport.name, transport.format || this.baseFormat);
|
||||
} else transport.permanent = true;
|
||||
} catch(ex) {
|
||||
throw new PikminError(`Failed to write to transporter:\r\n${ex}`);
|
||||
@@ -51,7 +51,7 @@ module.exports = class PikminInstance {
|
||||
throw new PikminError(ex);
|
||||
}
|
||||
|
||||
Pikmin.loggers.set(this.name, this.log);
|
||||
Pikmin.loggers.set(this.name, this.__log__);
|
||||
}
|
||||
|
||||
addTransport(transport, options = { autogen: false }) {
|
||||
@@ -66,13 +66,13 @@ module.exports = class PikminInstance {
|
||||
this.transports.push(transport);
|
||||
if (transport.name) {
|
||||
this[transport.name] = (msg, opt) => this._print(msg, Object.assign(transport.defaults, opt), transport.name, transport.format || this.baseFormat,);
|
||||
this.log[transport.name] = (msg, opt) => this._print(msg, Object.assign(transport.defaults, opt), transport.name, transport.format || this.baseFormat);
|
||||
this.__log__[transport.name] = (msg, opt) => this._print(msg, Object.assign(transport.defaults, opt), transport.name, transport.format || this.baseFormat);
|
||||
} else transport.permanent = true;
|
||||
} catch(ex) {
|
||||
throw new PikminError(`Failed to write to transporter:\r\n${ex}`);
|
||||
}
|
||||
|
||||
Pikmin.loggers.set(this.name, this.log);
|
||||
Pikmin.loggers.set(this.name, this.__log__);
|
||||
}
|
||||
|
||||
_print(msg, options = {}, lvl, starter = this.baseFormat) {
|
||||
@@ -91,7 +91,7 @@ module.exports = class PikminInstance {
|
||||
if ([ 2, 5 ].some((v) => type(msg) === v)) m = inspect(msg, false, null, !c);
|
||||
}
|
||||
|
||||
v.append(options, `${this._format(starter, lvl, c)} ${m}`);
|
||||
v.append(options, `${this._format(starter, lvl, c)}${m}`);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
},
|
||||
"files": [
|
||||
"lib/",
|
||||
"LICENSE"
|
||||
"LICENSE",
|
||||
"index.d.ts"
|
||||
],
|
||||
"scripts": {
|
||||
"fix": "eslint --fix --quiet --color lib/*",
|
||||
|
||||
Reference in New Issue
Block a user