mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-11 18:02:28 +01:00
137 lines
3.7 KiB
JavaScript
137 lines
3.7 KiB
JavaScript
'use strict';
|
|
|
|
var path = require('path'),
|
|
chalk = require('chalk'),
|
|
logger = require('./logger'),
|
|
mongoose = require('mongoose'),
|
|
loggerAnnounce = require('./loggerAnnounce'),
|
|
moment = require('moment'),
|
|
objectId = require('mongodb').ObjectId,
|
|
config = require(path.resolve('./config/config'));
|
|
|
|
var appConfig = config.meanTorrentConfig.app;
|
|
var announceConfig = config.meanTorrentConfig.announce;
|
|
|
|
module.exports.colorFunctionList = {
|
|
red: chalk.red,
|
|
error: chalk.red,
|
|
blue: chalk.blue,
|
|
yellow: chalk.yellow,
|
|
green: chalk.green
|
|
};
|
|
|
|
/**
|
|
* debug
|
|
* @param obj
|
|
* @param section
|
|
*/
|
|
module.exports.info = function (obj, section = undefined, colorFunction = undefined, isAnnounce = false, user = undefined) {
|
|
if (appConfig.writeServerDebugLog) {
|
|
var tools = isAnnounce ? loggerAnnounce : logger;
|
|
|
|
var userPrefix = '';
|
|
if (isAnnounce && !announceConfig.debugAnnounceUser.debugAll) {
|
|
if (user) {
|
|
var id = (('_id' in user) ? user._id.toString() : user.toString());
|
|
|
|
if (!announceConfig.debugAnnounceUser.ids.includes(id)) {
|
|
return;
|
|
} else {
|
|
userPrefix = ' - ' + (user.displayName || '-') + ' - ' + id;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!colorFunction) {
|
|
if (Array.isArray(obj)) {
|
|
tools.info((section ? section : '') + userPrefix);
|
|
obj.forEach(function (a) {
|
|
if (typeof a !== 'object') {
|
|
tools.info(a + '');
|
|
} else {
|
|
tools.info(JSON.stringify(a));
|
|
}
|
|
});
|
|
} else if (typeof obj !== 'object') {
|
|
tools.info((section ? section : '') + userPrefix + ' - ' + obj);
|
|
} else {
|
|
tools.info((section ? section : '') + userPrefix);
|
|
tools.info(JSON.stringify(obj));
|
|
}
|
|
} else {
|
|
if (Array.isArray(obj)) {
|
|
tools.info(colorFunction((section ? section : '') + userPrefix));
|
|
obj.forEach(function (a) {
|
|
if (typeof a !== 'object') {
|
|
tools.info(a + '');
|
|
} else {
|
|
tools.info(JSON.stringify(a));
|
|
}
|
|
});
|
|
} else if (typeof obj !== 'object') {
|
|
tools.info(colorFunction((section ? section : '') + userPrefix + ' - ' + obj));
|
|
} else {
|
|
tools.info(colorFunction((section ? section : '') + userPrefix));
|
|
tools.info(JSON.stringify(obj));
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
/**
|
|
* debug
|
|
* @param obj
|
|
* @param section
|
|
*/
|
|
module.exports.debug = function (obj, section = undefined, isAnnounce = false, user = undefined) {
|
|
this.info(obj, section, undefined, isAnnounce, user);
|
|
};
|
|
|
|
/**
|
|
* debugGreen
|
|
* @param obj
|
|
* @param section
|
|
*/
|
|
module.exports.debugGreen = function (obj, section = undefined, isAnnounce = false, user = undefined) {
|
|
this.info(obj, section, this.colorFunctionList.green, isAnnounce, user);
|
|
|
|
};
|
|
|
|
/**
|
|
* debugRed
|
|
* @param obj
|
|
* @param section
|
|
*/
|
|
module.exports.debugRed = function (obj, section = undefined, isAnnounce = false, user = undefined) {
|
|
this.info(obj, section, this.colorFunctionList.red, isAnnounce, user);
|
|
};
|
|
|
|
/**
|
|
* debugError
|
|
* @param obj
|
|
* @param section
|
|
*/
|
|
module.exports.debugError = function (obj, section = undefined, isAnnounce = false, user = undefined) {
|
|
this.info(obj, section, this.colorFunctionList.error, isAnnounce, user);
|
|
};
|
|
|
|
/**
|
|
* debugBlue
|
|
* @param obj
|
|
* @param section
|
|
*/
|
|
module.exports.debugBlue = function (obj, section = undefined, isAnnounce = false, user = undefined) {
|
|
this.info(obj, section, this.colorFunctionList.blue, isAnnounce, user);
|
|
|
|
};
|
|
|
|
/**
|
|
* debugYellow
|
|
* @param obj
|
|
* @param section
|
|
*/
|
|
module.exports.debugYellow = function (obj, section = undefined, isAnnounce = false, user = undefined) {
|
|
this.info(obj, section, this.colorFunctionList.yellow, isAnnounce, user);
|
|
};
|
|
|