This commit is contained in:
Eartharoid 2019-05-06 15:29:37 +01:00
parent 78ddc9c3a3
commit f560d2913b
2 changed files with 37 additions and 20 deletions

View File

@ -11,20 +11,26 @@ function time() {
return `${h}:${('0' + m).slice(-2)}:${('0' + s).slice(-2)}`; return `${h}:${('0' + m).slice(-2)}:${('0' + s).slice(-2)}`;
} }
let d = ('0' + date).slice(-2); let d = ('0' + date).slice(-2);
if (!fs.existsSync('./logs')) {
fs.mkdirSync(`./logs`);
console.log(`[INFO | ${time()}] No logs directory found, creating one for you.`);
}
const files = fs.readdirSync('./logs/').filter(file => file.endsWith('.log')); const files = fs.readdirSync('./logs/').filter(file => file.endsWith('.log'));
let path = `./logs/${d}-${time().replace(':', '-').replace(':', '-')}.log`; // let path = `./logs/${d}-${time().replace(':', '-').replace(':', '-')}.log`;
let path = `./logs/${d}-${('0' + now.getMonth()).slice(-2)}-${now.getFullYear()}.${time().replace(':', '-').replace(':', '-')}.log`;
// const log = require(path); // const log = require(path);
function init(x) { function init(x) {
console.log(leeks.colours.cyan(`[INFO | ${time()}] Setting up...`)); // console.log(leeks.colours.cyan(`[INFO | ${time()}] Setting up...`));
console.log(`[INFO | ${time()}] Initialising logger`); console.log(`[INFO | ${time()}] Initialising logger`);
console.log(`[INFO | ${time()}] Cleaning up...`); console.log(`[INFO | ${time()}] Cleaning up...`);
for (const file of files) { for (const file of files) {
if(!file.startsWith(`${d}-`)) { // if(!file.startsWith(`${d}-`)) {
if(parseInt(file.substr(0,2)) < parseInt(d-7) || parseInt(file.substr(0,2)) > parseInt(d)) {
fs.unlinkSync(`./logs/${file}`) fs.unlinkSync(`./logs/${file}`)
console.log(`[INFO | ${time()}] Deleting ./logs/${file}`); console.log(`[INFO | ${time()}] Deleting './logs/${file}'`);
}; };
}; };
try { try {
@ -48,53 +54,65 @@ exports.init = x => {
init(x) init(x)
}; };
exports.basic = (m) => { exports.basic = (m, c) => {
console.log(`[${time()}] ${m}`) if(c){console.log(leeks.colours[c](`[${time()}] ${m}`))} else {console.log(`[${time()}] ${m}`)};
fs.writeFileSync(path, `[${time()}] ${m}\n`, function (error) { fs.writeFileSync(path, `[${time()}] ${m}\n`, function (error) {
if (error) throw error; if (error) throw error;
}); });
}; };
exports.console = (m) => { exports.console = (m, c) => {
console.log(`[INFO | ${time()}] ${m}`); if(c){console.log(leeks.colours[c](`[${time()}] ${m}`))} else {console.log(`[INFO | ${time()}] ${m}`)};
let data = fs.readFileSync(path); let data = fs.readFileSync(path);
fs.writeFileSync(path, data + `[INFO | ${time()}] ${m}\n`, function (error) { fs.writeFileSync(path, data + `[INFO | ${time()}] ${m}\n`, function (error) {
if (error) throw error; if (error) throw error;
}); });
}; };
exports.info = (m) => { exports.info = (m, c) => {
console.info(leeks.colours.cyan(`[INFO | ${time()}] ${m}`)); if(c){console.info(leeks.colours[c](`[INFO | ${time()}] ${m}`))} else {console.info(leeks.colours.cyan(`[INFO | ${time()}] ${m}`))};
let data = fs.readFileSync(path); let data = fs.readFileSync(path);
fs.writeFileSync(path, data + `[INFO | ${time()}] ${m}\n`, function (error) { fs.writeFileSync(path, data + `[INFO | ${time()}] ${m}\n`, function (error) {
if (error) throw error; if (error) throw error;
}); });
}; };
exports.success = (m) => { exports.success = (m, c) => {
console.info(leeks.colours.green(`[INFO | ${time()}] ${m}`)); if(c){console.info(leeks.colours[c](`[INFO | ${time()}] ${m}`))} else {console.info(leeks.colours.green(`[INFO | ${time()}] ${m}`))};
let data = fs.readFileSync(path); let data = fs.readFileSync(path);
fs.writeFileSync(path, data + `[INFO | ${time()}] ${m}\n`, function (error) { fs.writeFileSync(path, data + `[INFO | ${time()}] ${m}\n`, function (error) {
if (error) throw error; if (error) throw error;
}); });
}; };
exports.debug = (m) => { exports.debug = (m, c) => {
console.info(leeks.colours.blueBright(`[DEBUG | ${time()}] ${m}`)); if(c){console.info(leeks.colours[c](`[DEBUG | ${time()}] ${m}`))} else {console.info(leeks.colours.blueBright(`[DEBUG | ${time()}] ${m}`))};
let data = fs.readFileSync(path); let data = fs.readFileSync(path);
fs.writeFileSync(path, data + `[DEBUG | ${time()}] ${m}\n`, function (error) { fs.writeFileSync(path, data + `[DEBUG | ${time()}] ${m}\n`, function (error) {
if (error) throw error; if (error) throw error;
}); });
}; };
exports.warn = (m) => { exports.warn = (m, c) => {
console.warn(leeks.colours.yellowBright(`[WARN | ${time()}] ${m}`)); if(c){console.warn(leeks.colours[c](`[WARN | ${time()}] ${m}`))} else {console.warn(leeks.colours.yellowBright(`[WARN | ${time()}] ${m}`))};
let data = fs.readFileSync(path); let data = fs.readFileSync(path);
fs.writeFileSync(path, data + `[WARN | ${time()}] ${m}\n`, function (error) { fs.writeFileSync(path, data + `[WARN | ${time()}] ${m}\n`, function (error) {
if (error) throw error; if (error) throw error;
}); });
}; };
exports.error = (m) => { exports.error = (m, c) => {
console.error(leeks.colours.red(`[ERROR | ${time()}] ${m}`)); if(c){console.error(leeks.colours[c](`[ERROR | ${time()}] ${m}`))} else {console.error(leeks.colours.red(`[ERROR | ${time()}] ${m}`))};
let data = fs.readFileSync(path); let data = fs.readFileSync(path);
fs.writeFileSync(path, data + `[ERROR | ${time()}] ${m}\n`, function (error) { fs.writeFileSync(path, data + `[ERROR | ${time()}] ${m}\n`, function (error) {
if (error) throw error; if (error) throw error;
}); });
}; };
exports.custom = (t, m, c) => {
if(c){console.log(leeks.colours[c](`[${t} | ${time()}] ${m}`))} else {console.log(`[${t} | ${time()}] ${m}`)};
let data = fs.readFileSync(path);
fs.writeFileSync(path, data + `[${t} | ${time()}] ${m}\n`, function (error) {
if (error) throw error;
});
};
module.exports.colors = leeks.colors;
module.exports.colours = leeks.colours;
module.exports.color = leeks.colors;
module.exports.colour = leeks.colours;

View File

@ -84,7 +84,6 @@ log.init('DiscordTickets (bot created by Eartharoid)')
// all log.* functions are logged to ./log/file.log from here onwards // all log.* functions are logged to ./log/file.log from here onwards
log.info(`Starting up...`) log.info(`Starting up...`)
client.once('ready', () => { // after bot has logged in client.once('ready', () => { // after bot has logged in
log.info(`Initialising bot...`) log.info(`Initialising bot...`)