logger ™️
This commit is contained in:
Eartharoid 2019-05-05 16:34:39 +01:00
parent 671950cb9c
commit 64eeb50b05
3 changed files with 65 additions and 12 deletions

View File

@ -10,7 +10,7 @@
"playing": "with tickets (!help)", "playing": "with tickets (!help)",
"useEmbeds": true, "useEmbeds": true,
"logDMs": true, "logDMs": true,
"cooldown": 5, "cooldown": 3,
"ticketImage": true, "ticketImage": true,
"tagHereOnly": false, "tagHereOnly": false,
"ticketText": "Thanks you for reaching out to our support team.\nA member of staff will come to assist you shortly. Please describe the issue in detail and explain what you have done to resolve the issue so far.\n\n*If you feel that the support you recieve is inadequate, please feel free to submit a formal complaint to a senior member of staff.*", "ticketText": "Thanks you for reaching out to our support team.\nA member of staff will come to assist you shortly. Please describe the issue in detail and explain what you have done to resolve the issue so far.\n\n*If you feel that the support you recieve is inadequate, please feel free to submit a formal complaint to a senior member of staff.*",

View File

@ -1,35 +1,88 @@
const leeks = require('leeks.js'); const fs = require('fs');
const leeks = require('leeks.js'); // ultra light weight alternative to chalk
const now = new Date(); const now = new Date();
const d = now.getDate(); let date = now.getDate();
const h = now.getHours(); const h = now.getHours();
const m = now.getMinutes(); const m = now.getMinutes();
const s = now.getSeconds(); const s = now.getSeconds();
let timestamp = `${h}:${('0' + m).slice(-2)}:${('0' + s).slice(-2)}`; let timestamp = `${h}:${('0' + m).slice(-2)}:${('0' + s).slice(-2)}`;
let d = ('0' + date).slice(-2);
const files = fs.readdirSync('./logs/').filter(file => file.endsWith('.log'));
let path = `./logs/${d}-${timestamp.replace(':', '-').replace(':', '-')}.log`;
// const log = require(path);
function init(x) {
console.log(leeks.colours.cyan(`[INFO | ${timestamp}] Setting up...`));
console.log(`[INFO | ${timestamp}] Initialising logger`);
console.log(`[INFO | ${timestamp}] Cleaning up...`);
for (const file of files) {
if(!file.startsWith(`${d}-`) && !file.startsWith(`${d-1}-`)) {
fs.unlinkSync(`./logs/${file}`)
console.log(`[INFO | ${timestamp}] Deleting ./logs/${file}`);
};
};
try {
fs.appendFileSync(path, `Discord Tickets | Log File (${timestamp})\n`, function (error) {
if (error) throw error;
});
console.log(`[INFO | ${timestamp}] Creating new log file (${path})`);
} catch(error) {
console.error(leeks.colours.red(error));
}
};
exports.init = x => { exports.init = x => {
console.log(`INIT FUNCTION TRIGGERED`) init(x)
}; };
exports.basic = (m) => { exports.basic = (m) => {
console.log(m) console.log(`[${timestamp}] ${m}`)
fs.writeFileSync(path, `[${timestamp}] ${m}\n`, function (error) {
if (error) throw error;
});
}; };
exports.console = (m) => { exports.console = (m) => {
console.log(`[INFO | ${timestamp}] ${m}`); console.log(`[INFO | ${timestamp}] ${m}`);
let data = fs.readFileSync(path);
fs.writeFileSync(path, data + `[INFO | ${timestamp}] ${m}\n`, function (error) {
if (error) throw error;
});
}; };
exports.info = (m) => { exports.info = (m) => {
console.info(leeks.colours.cyan(`[INFO | ${timestamp}] ${m}`)); console.info(leeks.colours.cyan(`[INFO | ${timestamp}] ${m}`));
let data = fs.readFileSync(path);
fs.writeFileSync(path, data + `[INFO | ${timestamp}] ${m}\n`, function (error) {
if (error) throw error;
});
}; };
exports.success = (m) => { exports.success = (m) => {
console.info(leeks.colours.green(`[INFO | ${timestamp}] ${m}`)); console.info(leeks.colours.green(`[INFO | ${timestamp}] ${m}`));
let data = fs.readFileSync(path);
fs.writeFileSync(path, data + `[INFO | ${timestamp}] ${m}\n`, function (error) {
if (error) throw error;
});
}; };
exports.debug = (m) => { exports.debug = (m) => {
console.info(leeks.colours.blueBright(`[DEBUG | ${timestamp}] ${m}`)); console.info(leeks.colours.blueBright(`[DEBUG | ${timestamp}] ${m}`));
let data = fs.readFileSync(path);
fs.writeFileSync(path, data + `[DEBUG | ${timestamp}] ${m}\n`, function (error) {
if (error) throw error;
});
}; };
exports.warn = (m) => { exports.warn = (m) => {
console.warn(leeks.colours.yellowBright(`[WARN | ${timestamp}] ${m}`)); console.warn(leeks.colours.yellowBright(`[WARN | ${timestamp}] ${m}`));
let data = fs.readFileSync(path);
fs.writeFileSync(path, data + `[WARN | ${timestamp}] ${m}\n`, function (error) {
if (error) throw error;
});
}; };
exports.error = (m) => { exports.error = (m) => {
console.error(leeks.colours.red(`[ERROR | ${timestamp}] ${m}`)); console.error(leeks.colours.red(`[ERROR | ${timestamp}] ${m}`));
let data = fs.readFileSync(path);
fs.writeFileSync(path, data + `[ERROR | ${timestamp}] ${m}\n`, function (error) {
if (error) throw error;
});
}; };

View File

@ -50,8 +50,7 @@ const cooldowns = new Discord.Collection();
const now = Date.now(); const now = Date.now();
const commands = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); const commands = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
log.init() console.log(leeks.colours.magentaBright(`
log.basic(leeks.colours.magentaBright(`
######## #### ###### ###### ####### ######## ######## ######## #### ###### ###### ####### ######## ########
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
@ -69,11 +68,12 @@ log.basic(leeks.colours.magentaBright(`
## #### ###### ## ## ######## ## ###### ## #### ###### ## ## ######## ## ######
`)); // banner appears in console `)); // banner appears in console
log.basic(leeks.colours.yellow(leeks.styles.bold(`DiscordTickets v${version} - Made By Eartharoid`))); console.log(leeks.colours.yellow(leeks.styles.bold(`DiscordTickets v${version} - Made By Eartharoid`)));
log.basic(leeks.colours.yellow(leeks.styles.bold(homepage))); console.log(leeks.colours.yellow(leeks.styles.bold(homepage)));
log.basic('\n\n'); console.log('\n\n');
log.basic(leeks.colours.bgGrey(leeks.colours.grey(`\n\n==========================================================================\n\n`))) console.log(leeks.colours.bgGrey(leeks.colours.grey(`\n\n==========================================================================\n\n`)))
log.basic('\n\n'); console.log('\n\n');
log.init()
log.info(`Starting up...`) log.info(`Starting up...`)