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)",
"useEmbeds": true,
"logDMs": true,
"cooldown": 5,
"cooldown": 3,
"ticketImage": true,
"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.*",

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 d = now.getDate();
let date = now.getDate();
const h = now.getHours();
const m = now.getMinutes();
const s = now.getSeconds();
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 => {
console.log(`INIT FUNCTION TRIGGERED`)
init(x)
};
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) => {
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) => {
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) => {
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) => {
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) => {
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) => {
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 commands = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
log.init()
log.basic(leeks.colours.magentaBright(`
console.log(leeks.colours.magentaBright(`
######## #### ###### ###### ####### ######## ########
## ## ## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ##
@ -69,11 +68,12 @@ log.basic(leeks.colours.magentaBright(`
## #### ###### ## ## ######## ## ######
`)); // banner appears in console
log.basic(leeks.colours.yellow(leeks.styles.bold(`DiscordTickets v${version} - Made By Eartharoid`)));
log.basic(leeks.colours.yellow(leeks.styles.bold(homepage)));
log.basic('\n\n');
log.basic(leeks.colours.bgGrey(leeks.colours.grey(`\n\n==========================================================================\n\n`)))
log.basic('\n\n');
console.log(leeks.colours.yellow(leeks.styles.bold(`DiscordTickets v${version} - Made By Eartharoid`)));
console.log(leeks.colours.yellow(leeks.styles.bold(homepage)));
console.log('\n\n');
console.log(leeks.colours.bgGrey(leeks.colours.grey(`\n\n==========================================================================\n\n`)))
console.log('\n\n');
log.init()
log.info(`Starting up...`)