From 47f113efc6edd2bfc74ba9786109a58b97b7f9b9 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Sat, 22 Oct 2022 04:23:16 -0600 Subject: [PATCH] logger setup; log levels --- bot.js | 0 src/db/connect.js | 10 ++++++++++ src/util/log/getlevel.js | 17 +++++++++++++++++ src/util/log/levels.json | 5 +++++ src/util/log/log.js | 5 +++++ src/util/log/types.js | 0 6 files changed, 37 insertions(+) create mode 100644 bot.js create mode 100644 src/db/connect.js create mode 100644 src/util/log/getlevel.js create mode 100644 src/util/log/levels.json create mode 100644 src/util/log/log.js create mode 100644 src/util/log/types.js diff --git a/bot.js b/bot.js new file mode 100644 index 0000000..e69de29 diff --git a/src/db/connect.js b/src/db/connect.js new file mode 100644 index 0000000..6637e73 --- /dev/null +++ b/src/db/connect.js @@ -0,0 +1,10 @@ +module.exports = async client => { + const config = client.config; + try { + await mongoose.connect(`mongodb+srv://${config.database.user}:${config.database.password}@${config.database.cluster}.3jpp4.mongodb.net/test`, { + useFindAndModify: false, useNewUrlParser: true, dbName: 'Natsuki-Main', useUnifiedTopology: true, useCreateIndex: true + }).catch(() => {}); + } catch (e) { + + } +}; \ No newline at end of file diff --git a/src/util/log/getlevel.js b/src/util/log/getlevel.js new file mode 100644 index 0000000..ea338ca --- /dev/null +++ b/src/util/log/getlevel.js @@ -0,0 +1,17 @@ +const config = require('../../json/config.json'); +const levels = require('./levels.json'); +const validStrings = Object.keys(levels); + +const getLevel = (level) => { + console.log(level) + if (typeof level === 'number') { + if (level <= 0) {return 0;} + if (level > 3) {return 3;} + return Math.floor(level); + } else { + const levelM = `${level}`.trim().toUpperCase(); + return validStrings.includes(levelM) ? levels[levelM] : typeof config.log.defaultLevel === 'number' ? getLevel(config.log.defaultLevel) : 1; + } +}; + +module.exports = getLevel; \ No newline at end of file diff --git a/src/util/log/levels.json b/src/util/log/levels.json new file mode 100644 index 0000000..4482d9a --- /dev/null +++ b/src/util/log/levels.json @@ -0,0 +1,5 @@ +{ + "TOP": 0, + "STANDARD": 1, + "VERBOSE": 2 +} \ No newline at end of file diff --git a/src/util/log/log.js b/src/util/log/log.js new file mode 100644 index 0000000..7ab5613 --- /dev/null +++ b/src/util/log/log.js @@ -0,0 +1,5 @@ + + +module.exports = (message, level, source, color) => { + +}; \ No newline at end of file diff --git a/src/util/log/types.js b/src/util/log/types.js new file mode 100644 index 0000000..e69de29