Compare commits
5 Commits
d469ed3969
...
762bdc17bd
Author | SHA1 | Date |
---|---|---|
Kit Kasune | 762bdc17bd | 2 years ago |
Kit Kasune | a5e1c4c1f9 | 2 years ago |
Kit Kasune | 2dadce7391 | 2 years ago |
Kit Kasune | 3b3d64cf62 | 2 years ago |
Kit Kasune | 31d5741707 | 2 years ago |
@ -1,14 +1,5 @@ |
|||||||
const logger = require('./src/util/log/log'); |
const dbConnect = require('./src/db/connect'); |
||||||
const client = {test: 'e', config: {logLevel: 1}}; |
const r = async () => { |
||||||
const log = logger(client); |
await dbConnect({auth: require('./src/json/auth.json'), config: {logLevel: 1}}); |
||||||
log(); |
}; |
||||||
log("Hello World!") |
r(); |
||||||
log("Hello in blue", {color: 'blue'}); |
|
||||||
log('A strange warning appears!', {color: 'yellowBright', source: 'warn', sourceColor: 'yellow'}); |
|
||||||
log('Extra line spacing before', {}, false, true); |
|
||||||
log('regular line'); |
|
||||||
log('extra line spacing after', {}, true); |
|
||||||
log('regular line'); |
|
||||||
log('both line spaces', {}, true, true); |
|
||||||
log('regular line'); |
|
||||||
log('a custom fancy pink color', {color: '#ff00ff', sourceColor: '#660066'}); |
|
@ -1,10 +1,23 @@ |
|||||||
module.exports = async client => { |
const chalk = require('chalk'); |
||||||
const config = client.config; |
const mongoose = require('mongoose'); |
||||||
try { |
|
||||||
await mongoose.connect(`mongodb+srv://${config.database.user}:${config.database.password}@${config.database.cluster}.3jpp4.mongodb.net/test`, { |
const log = require('../util/log/log'); |
||||||
useFindAndModify: false, useNewUrlParser: true, dbName: 'Natsuki-Main', useUnifiedTopology: true, useCreateIndex: true |
const ora = require('../util/log/ora'); |
||||||
}).catch(() => {}); |
|
||||||
} catch (e) { |
|
||||||
|
|
||||||
|
module.exports = async client => { |
||||||
|
const auth = client.auth; |
||||||
|
const t = Date.now(); |
||||||
|
client.misc = {}; |
||||||
|
client.misc.dbconnected = false; |
||||||
|
await ora(chalk.blueBright.bold.underline("Connecting to MongoDB..."), |
||||||
|
mongoose.connect(`mongodb+srv://${auth.database.user}:${auth.database.password}@${auth.database.cluster}.3jpp4.mongodb.net/test`, { |
||||||
|
useFindAndModify: false, useNewUrlParser: true, dbName: auth.database.name, useUnifiedTopology: true, useCreateIndex: true |
||||||
|
}) |
||||||
|
).catch((e) => log(client).error("Failed to connect to mongoose!! Error below.", 0, true, true, e)) |
||||||
|
.then(() => {client.misc.dbconnected = true;}); |
||||||
|
if (!client.misc.dbconnected) { |
||||||
|
log(client).warn("Database not connected, considering runtime to be unusable and exiting.", 0, true, true); |
||||||
|
throw new Error(); |
||||||
} |
} |
||||||
|
return log(client).success(`Connected to Mongo Database in ${chalk.white(`${Date.now() - t}ms`)}.`); |
||||||
}; |
}; |
@ -0,0 +1,18 @@ |
|||||||
|
const ora = require('ora'); |
||||||
|
|
||||||
|
module.exports = async (text, promise, callback) => { |
||||||
|
return new Promise(async (resolve, reject) => { |
||||||
|
let spin = ora(text).start(); |
||||||
|
return await promise |
||||||
|
.catch(e => { |
||||||
|
spin.stop(); |
||||||
|
spin.clear(); |
||||||
|
return reject(e) |
||||||
|
}) |
||||||
|
.then((...args) => { |
||||||
|
spin.stop(); |
||||||
|
spin.clear(); |
||||||
|
return callback ? resolve(callback(spin, args)) : resolve(true); |
||||||
|
}); |
||||||
|
}); |
||||||
|
}; |
@ -0,0 +1,20 @@ |
|||||||
|
module.exports = (log) => { return { |
||||||
|
error: (message, options, prenl, postnl, ...multcons) => log(message, { |
||||||
|
color: 'redBright', |
||||||
|
source: 'err!', |
||||||
|
sourceColor: 'red', |
||||||
|
level: 0 |
||||||
|
}, prenl, postnl, ...multcons), |
||||||
|
warn: (message, options, prenl, postnl, ...multcons) => log(message, { |
||||||
|
color: 'yellowBright', |
||||||
|
source: 'warn', |
||||||
|
sourceColor: 'yellow', |
||||||
|
level: 1 |
||||||
|
}, prenl, postnl, ...multcons), |
||||||
|
success: (message, options, prenl, postnl, ...multcons) => log(message, { |
||||||
|
color: 'greenBright', |
||||||
|
source: 'proc' || options && options.source, |
||||||
|
sourceColor: 'green', |
||||||
|
level: options && typeof options.level !== 'undefined' ? options.level : 0 |
||||||
|
}, prenl, postnl, ...multcons) |
||||||
|
}}; |
@ -0,0 +1,7 @@ |
|||||||
|
module.exports = (time) => { |
||||||
|
return new Promise(function (resolve) { |
||||||
|
setTimeout(function () { |
||||||
|
resolve(null); |
||||||
|
}, time); |
||||||
|
}); |
||||||
|
}; |
Loading…
Reference in new issue